Please find the code below:
#include<iostream> // used for cout and cin
using namespace std;
void calcAreaCircle(float&,float&); // prototype of all the 3 functions
void calcAreaSquare(float&,float&); // variables are passed as reference
void calcAreaRectangle(float&,float&,float&);
int main() // main()
{
float areaCircle,areaSquare,areaRectangle; // variables to store the area of circle, square and rectangle
float cRadius; // variable to store the radius of circle
float sBase; // variable to store the base of square
float rHeight,rWidth; // variable to store height and width of rectangle
int choice; // variable to store the user's choice
do // using a do while loop for user's option
{
cout<<endl<<"Please select:"; // provide the menu to the user
cout<<endl<<"1. Area of Circle";
cout<<endl<<"2. Area of Square";
cout<<endl<<"3. Area of rectangle";
cout<<endl<<"0. Quit";
cout<<endl<<"Please enter your choice:";
cin>>choice; // Ask user for choice, take user's choice in variable choice
switch(choice) // using switch case statements to evaluate choice
{
case 1: // if choice is 1, ask user to enter radius
cout<<endl<<"Enter the radius of the circle:";
cin>>cRadius;
while(cRadius<=0) // using a while loop to evaluate if the radius is negative
{ // keep asking user for input till user provides valid data
cout<<endl<<"Please enter a positive value for radius";
cout<<endl<<"Enter the radius of circle:";
cin>>cRadius;
}
calcAreaCircle(cRadius,areaCircle); // call calAreaCircle() and pass radius and area of circle as parameters
cout<<endl<<"The area of circle is: "<<areaCircle; // print the area of circle
break;
case 2:
cout<<endl<<"Enter the base of the square:"; // if choice is 2, ask user to enter the base of square
cin>>sBase;
while(sBase<=0) // if base is negative, keep asking user for base till user provides valid input
{
cout<<endl<<"Please enter a positive value for base";
cout<<endl<<"Enter the base of the square:";
cin>>sBase;
}
calcAreaSquare(sBase,areaSquare); // call calcAreaSquare and pass base and area of square as parameter
cout<<endl<<"The area of square is: "<<areaSquare; // print the area of square
break;
case 3:
cout<<endl<<"Enter the height of the rectangle:"; // if choice is 3, ask user for height and base of rectangle
cin>>rHeight;
cout<<endl<<"Enter the base of the rectangle:";
cin>>rWidth;
while(rHeight<=0) // if height is negative, keep asking user for height till user provides valid input
{
cout<<endl<<"Please enter a positive value for height";
cout<<endl<<"Enter the height of the rectangle:";
cin>>rHeight;
}
while(rWidth<=0) // if base is negative, keep asking user for base till user provides valid input
{
cout<<endl<<"Please enter a positive value for base";
cout<<endl<<"Enter the base of the rectangle:";
cin>>rWidth;
}
calcAreaRectangle(rHeight,rWidth,areaRectangle); // call calcAreaRectangle() and pass height width and area of rectangle
cout<<endl<<"The area of rectangle is: "<<areaRectangle;
break;
case 0: // if case is 0, print good bye
cout<<endl<<"Good Bye!";
break;
default: // if any other value is used as choice, print invalid choice
cout<<endl<<"Invalid choice";
}
}while(choice!=0); // continue looping till user enters 0
return 0;
}
void calcAreaCircle(float& cRadius,float& areaCircle) // definition of calcAreaCircle()
{ // it takes the references of cRadius and areaCircle variables as parameters
float pi=3.14; // declare and initialize pi to 3.14
areaCircle=pi*cRadius*cRadius; // calculate area as pi*radius*radius
}
void calcAreaSquare(float& sBase,float& areaSquare) // definition of calcAreaSquare()
{ // it takes references of sBase and areaSquare as parameters
areaSquare=sBase*sBase; // calculate area as base * base
}
void calcAreaRectangle(float& rHeight,float& rWidth,float& areaRectangle) // definition of calcAreaRectangle()
{ // it takes references of rHeight,rWidth and areaRectangle as parameters
areaRectangle=rHeight*rWidth; // calculate area as height * width
}
===========================================================================================
Output:
C++ Pr ogramming (CSC-115) Functions (pass by Reference) Programming project Using FUNCTIONS, write a C++ program...
Using Python Write the following well-documented (commented) program. Create a class called Shape that has a method for printing the area and the perimeter. Create three classes (Square, Rectangle, and Circle) which inherit from it. Square will have one instance variable for the length. Rectangle will have two instance variables for the width and height. Circle will have one instance variable for the radius. The three classes will have methods for computing the area and perimeter of its corresponding shape....
Java only please Write a program that displays the following menu: Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Triangle 3. Calculate the Area of a Rectangle 4. Quit Enter your choice (1-4): If the user enters 1, the program should ask for the radius of the circle and then display its area. Use the formula: area = ∏r2 Use 3.14159 for ∏. If the user enters 2 the program should ask for...
C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...
Menu-driven programs will display the menu options to the user and then prompt them for a menu choice. This program will display the following menu in the following format: Calculator Options: Calculate the area of a circle Calculate the area of a rectangle Calculate the area of a triangle Calculate the area of a trapezoid Calculate the area of a sphere Exit Enter your choice (1-6) Once the user enters a choice for the menu, the program should use a...
Geometric calclator use python to do this program. Write a program that displays the following menu: 1. Calculate the area of circle 2. calculate the area of rectangle 3. calculate the area of triangle 4. Quit Enter your choice (1-4). if the user enters 1, your program should ask for the radius of the circle and then display its area. Use the formula to calculate the circle's area: Area = pi*r^2 Use 3.14149 for Pi and the radius of the...
Using C++, Write a program that will provide the user a menu from which the user may select to calculate the area of one of four geometric shapes: a circle, a rectangle, a triangle, and a trapezoid. You should use the most appropriate SWITCH block for this program. The user will input all data needed to calculate the area. The program should output all data input by the user, the calculated area, and the geometric shape selected. Run this program...
In Java Exercise #2: (Java) Design and implement a program (name it ComputeAreas) that defines four methods as follows: Method squareArea (double side) returns the area of a square. Method rectangleArea (double width, double length) returns the area of a rectangle. Method circleArea (double radius) returns the area of a circle. Method triangleArea (double base, double height) returns the area of a triangle. In the main method, test all methods with different input value read from the user. Document your...
(PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1 - 4): If the user enters 1, the program should ask for the radius of the circle and then display its area. If the user enters 2, the program should ask for the length and width of...
1. Write a program that determines the area and perimeter of a square. Your program should accept the appropriate measurement of the square as input from the user and display the result to the screen. Area of Square = L (squared) Perimeter of Square = 4 * L 2. Write a program that determines the area and circumference of a circle. Your program should accept the appropriate measurement of the circle as input from the user and display the result to...
Please use C++ and output have to look like that Create a menu driven C++ program with functions. There must be four functions, calculating the size of area of circle, rectangle, triangle, and parallelogram. You are required to create those four functions and invoke them from the main program in order to reccive any credit. Please Submit: . A flowchart of your program with equations and expected results. 4 points) 2. Printout of your C++program with a heading comment, also...