1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kolbaska11 [484]
4 years ago
12

14. Write an if/then/else primitive to do each of the following operations: a. Compute and display the value x ÷ y if the value

of y is not 0. If y does have the value 0, then display the message ‘Unable to perform the division’. b. Compute the area and circumference of a circle given the radius r if the radius is greater than or equal to 1.0; otherwise, you should compute only the circumference.
Computers and Technology
1 answer:
tatuchka [14]4 years ago
6 0

Answer:

// part (a).

//include header

#include <bits/stdc++.h>

using namespace std;

//main function

int main() {

// variables

int x_val,y_val;

cout<<"enter value of x:";

// read the value of x

cin>>x_val;

cout<<"enter value of y:";

// read the value of y

cin>>y_val;

// check if y=0 or not

if(y_val==0)

cout<<"Unable to perform the division"<<endl;

else

cout<<"value of x/y is: "<<x_val/y_val<<endl;

return 0;

}

Explanation:

Declare variable "x","y" and read the value of both from user.If value of "y" is equal to 0 then it will print "Unable to perform the division" else it will calculate x/y and print its value.

Output:

enter value of x:4

enter value of y:0

Unable to perform the division

enter value of x:5

enter value of y:2

value of x/y is: 2

//part(b)

//include header

#include <bits/stdc++.h>

using namespace std;

//main function

int main() {

// variable to store radius of circle

float cir_rad;

cout<<"enter the radius :";

// read the radius of circle

cin>>cir_rad;

// validate the radius, it must be positive

while(cir_rad<=0)

{

   cout<<"radius must be positive:";

   cin>>cir_rad;

}

// if radius is greater or equal to 1 Then

// it will calculate area and circumference and print

if(cir_rad>=1)

{

   float area=3.14*cir_rad*cir_rad;

   cout<<"area of circle is: "<<area<<endl;

   float circumference=2*3.14*cir_rad;

   cout<<"circumference of circle is: "<<circumference<<endl;

}

// else it will only circumference and print

else{

    float circumference=2*3.14*cir_rad;

   cout<<"circumference of circle is: "<<circumference<<endl;

}

return 0;

}

Explanation:

Read the value of radius from user and Assign it to variable "r".Check if "r" is negative or not.If "r" is negative then again ask user to enter a positive radius. After that if radius is greater or equal to 1 then it will Calculate area and circumference of circle and print.If radius is less than 1 then it will Calculate only circumference and print.

Output:

enter the radius:-2

radius must be positive:2

area of circle is: 12.56

circumference of circle is: 12.56

You might be interested in
W-11/6=4<br><img src="https://tex.z-dn.net/?f=%20%20%5Cfrac%7Bx%20-%2011%20%7D%7B%206%7D%20%20%3D%204" id="TexFormula1" title="
kozerog [31]

step 1, multiply by 6:

x-11 = 4*6 = 24

step 2, add 11:

x = 35

7 0
3 years ago
Hat are three machines or devices that depend on gravity to work?
jonny [76]
Some devices that depend on gravity to function include scales, showers, and satellites, to list a few.
6 0
3 years ago
To reduce chances of system failure, engineers may use _____ .
Nataliya [291]
<span>To reduce chances of system failure, engineers may use process control. This is a system which involves activities that ensures the whole process variables can be predicted and controlled to prevent failure. This involves the use of safety valves and sensors.</span>
5 0
3 years ago
Read 2 more answers
Which of the following is not one of the steps a company would take in an attempt to prevent a malfunction or failure of their p
bulgar [2K]

Answer:

A overdesign

Explanation:

7 0
3 years ago
Explain in detail why intel 8086 segments are 64 KB in size?
gtnhenbr [62]

Answer:

Explanation:

phân đoạn bộ nhớ x86 đề cập đến việc thực hiện phân đoạn bộ nhớ trong Intel x86 máy vi tính bản hướng dẫn kiến ​​trúc. Phân đoạn đã được giới thiệu trên Intel 8086 vào năm 1978 như một cách cho phép các chương trình có địa chỉ hơn 64 KB (65,536byte) của bộ nhớ. Các Intel 80286 đã giới thiệu phiên bản thứ hai của phân đoạn vào năm 1982 bổ sung hỗ trợ cho bộ nhớ ảo và bảo vệ bộ nhớ. Tại thời điểm này, mô hình ban đầu đã được đổi tên chế độ thựcvà phiên bản mới được đặt tên chế độ bảo vệ. Các x86-64 kiến trúc, được giới thiệu vào năm 2003, phần lớn đã bỏ hỗ trợ phân đoạn ở chế độ 64-bit.

Ở cả chế độ thực và chế độ được bảo vệ, hệ thống sử dụng 16-bit đăng ký phân đoạn để lấy địa chỉ bộ nhớ thực. Ở chế độ thực, các thanh ghi CS, DS, SS và ES trỏ đến chương trình đang được sử dụng đoạn mã (CS), hiện tại phân đoạn dữ liệu (DS), hiện tại phân đoạn ngăn xếp (SS) và một thêm phân đoạn do người lập trình xác định (ES). Các Intel 80386, được giới thiệu vào năm 1985, bổ sung thêm hai thanh ghi phân đoạn, FS và GS, không có mục đích sử dụng cụ thể nào được xác định bởi phần cứng. Cách thức sử dụng các thanh ghi phân đoạn khác nhau giữa hai chế độ.[1]

Việc lựa chọn phân đoạn thường được bộ xử lý mặc định theo chức năng đang được thực thi. Các hướng dẫn luôn được tìm nạp từ đoạn mã. Mọi lần đẩy hoặc bật ngăn xếp hoặc bất kỳ tham chiếu dữ liệu nào tham chiếu đến ngăn xếp đều sử dụng phân đoạn ngăn xếp. Tất cả các tham chiếu khác đến dữ liệu đều sử dụng phân đoạn dữ liệu. Phân đoạn bổ sung là đích mặc định cho các hoạt động chuỗi (ví dụ: MOVS hoặc CMPS). FS và GS không có mục đích sử dụng do phần cứng chỉ định. Định dạng hướng dẫn cho phép một tùy chọn tiền tố phân đoạn byte có thể được sử dụng để ghi đè phân đoạn mặc định cho các hướng dẫn đã chọn nếu muốn

8 0
3 years ago
Other questions:
  • Which of the following is an example of a query with an explicit location? Select all that apply. True False [walmart boston], E
    7·2 answers
  • True or false: Your digital footprint is all the information about you online that only you post. Group of answer choices
    12·2 answers
  • Sulfur content is measured in
    11·1 answer
  • Citing Wikipedia as a reference is not considered a good practice because 1.leverages a neutral point of view. 2.hosts unopinion
    8·1 answer
  • The text between and defines the _____.
    15·1 answer
  • Anyone know how to delete that I need ASAP
    13·1 answer
  • HELP ME PLEASEEEE
    8·1 answer
  • Functionality testing is primarily used with ____________. firewall protection software development hardening servers server tes
    8·1 answer
  • Which of the following class definition defines a legal abstract class Group of answer choices public class Rectangle abstract {
    15·1 answer
  • What is best defined as a phishing email that is targeted directly at you?.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!