Question

In: Computer Science

1) Write a single function CalcArea( ) that has no input/output arguments. Inside the function, you...

1) Write a single function CalcArea( ) that has no input/output arguments. Inside the function, you will first print a “menu” listing 2 items: “rectangle”, “circle”.  It prompts the user to choose an option, and then asks the user to enter the required parameters for calculating the area (i.e., the width and length of a rectangle, the radius of a circle) and then prints its area.  The script simply prints an error message for an incorrect option.  

Here are two examples of running it:

>> CalcArea

Menu

1. Rectangle

2. Circle

Please choose one:2

Enter the radius of the circle: 4.1

The area is 52.81.

>> CalcArea

Menu

1. Rectangle
2. Circle

Please choose one: 1

Enter the length: 4

Enter the width: 6

The area is 24.00.

Solutions

Expert Solution

#include <iostream>

using namespace std;

void CalcArea() {
int option;
cout<<"\nWelcome to CalcArea";
cout<<"\nMenu";
cout<<"\n1. Rectangle";
cout<<"\n2. Circle";
cout<<"\nPlease choose one: ";
cin>>option;
if(option==1) {
double length,width,area;
cout<<"\nEnter the length: ";
cin>>length;
cout<<"\nEnter the width: ";
cin>>width;
area=length*width;
cout<<"\nThe Area is :"<<area;
}
else if(option==2) {
double radius,area;
cout<<"\nEnter the radius of the circle: ";
cin>>radius;
area=3.14*radius*radius;
cout<<"\nThe Area is :"<<area;
}
else{
cout<<"\nIncorrect option, run again";
}
}

int main()
{
CalcArea();

return 0;
}

Thanks and regards
if you like the answer please give a thumbs up
if you have a problem, feel free to comment.


Related Solutions

Write a user-defined MATLAB function, with two input and two output arguments that determines the height...
Write a user-defined MATLAB function, with two input and two output arguments that determines the height in centimeters (cm) and mass in kilograms (kg)of a person from his height in inches (in.) and weight in pounds (lb). (a) Determine in SI units the height and mass of a 5 ft.15 in. person who weight 180 lb. (b) Determine your own height and weight in SI units.
1. Suppose that output q is a function of a single input, labor (L). Describe the...
1. Suppose that output q is a function of a single input, labor (L). Describe the returns to scale associated with each of the following production functions: a. q = 3L. Answer: b. q = L3. Answer:
1.) Write a function, base2tobase10 that has a single input, a vector containing 1,s and 0...
1.) Write a function, base2tobase10 that has a single input, a vector containing 1,s and 0 's representing a binary number. For example the binary number 01101011 would be represented by the vector [ 0, 1, 1, 0, 1, 0,1, 1]. Your function should return a single output,the base 10 equivalent of the base 2 number. First, your function must check the input vector and detremine if any of the vector elemnets are not a 0 or a1. If they...
Write a function that will receive two input arguments that is the height in inches (in.)...
Write a function that will receive two input arguments that is the height in inches (in.) and the weight in pounds (lb) of a person and return two output arguments that is the height in meters (m) and mass in kilograms (kg). Determine in SI units the height and mass of a 5 ft.15 in. person who weight 180 lb. Determine your own height and weight in SI units. Note: 1 meter = 39.3701 inch, 1 foot = 12 inches,...
There is a package, `beepr`, with a single function, `beep()`. Write a function with an input,...
There is a package, `beepr`, with a single function, `beep()`. Write a function with an input, `x`, that will call `beep()` when `x > 0`. You may assume that the `beepr` package has been loaded. Call your function `xgt0()`. using R studio
C Programming: Write a program that accepts 2 arguments, an input file and an output file....
C Programming: Write a program that accepts 2 arguments, an input file and an output file. The program is to store in the output file the contents of the input file in reverse. If the input file looks like this: Hello World.\n This is Line 2\n This is the end.\n then the output file should look like this: \n .dne eht si sihT\n 2 eniL si sihT\n .dlroW olleH The main program should look like this: int main(int argc, char...
Assume there is a function called frustumArea that has three input arguments and returns the area...
Assume there is a function called frustumArea that has three input arguments and returns the area of a frustum: area = frustumArea( height, majRadius, minRadius ). When the major and minor radii of a frustum are equal, the frustum is a cylinder. Write a new function named cylinderArea that uses the frustumArea function to compute and return the area of a cylinder. Do this for both Python and Matlab.
Write a MATLAB function named myaccel that accepts three inputs and has a single output. Inputs:...
Write a MATLAB function named myaccel that accepts three inputs and has a single output. Inputs: a list of time values a list of position values a single time value. Output: a single number which is obtained by numerically differentiating position with respect to time twice (forward difference method) and then interpolating the results based on the third input. Example: time=0:10; position=time.^3; myaccel(time,position,2.8) % should return 22.8
Write a function called alternate that takes two positive integers, n and m, as input arguments...
Write a function called alternate that takes two positive integers, n and m, as input arguments (the function does not have to check the format of the input) and returns one matrix as an output argument. Each element of the n-by-m output matrix for which the sum of its indices is even is 1. All other elements are zero. For example, here is an example run: >> alternate(4,5) ans = 1 0 1 0 1 0 1 0 1 0...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a weighted sum of that numbers digits. The last digit of the number (the ones digit) has a weight of 1, so should be added to the sum "as is". The second from last digit (the tens digit) has a weight of 2, and so should be multiplied by 2 then added to the sum. The third from last digit should be multiplied by 1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT