Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, Can someone help me with this Its for C++ not Java Geometry Calculator : Wri

ID: 3728131 • Letter: H

Question

Hi, Can someone help me with this

Its for C++ not Java

Geometry Calculator :

Write a program that displays the following menu: 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. Use the following formula: area = (the square of r) Use 3.14159 for and the radius of the circle for r. If the user enters 2, the program should ask for the length and width of the rectangle and then display the rectangle’s area. Use the following formula: area = length * width If the user enters 3, the program should ask for the length of the triangle’s base and its height, and then display its area. Use the following formula: area = base * height * .5 If the user enters 4, the program should end. Input Validation: Display an error message if the user enters a number outside the range of 1 through 4 when selecting an item from the menu. Do not accept negative values for the circle’s radius, the rectangle’s length or width, or the triangle’s base or height. NOTE: If the user enters an improper menu choice (1-4), the program prints "The valid choices are 1 through 4. Run the program again and select one of those." If the user enters a negative radius, the program prints "The radius can not be less than zero." If the user enters a negative value for height or base , the program prints "Only enter positive values for base and height." Input Validation: Do not accept a number less than 1 or greater than 10.

Explanation / Answer

#include<iostream>

using namespace std;

double getCircleArea(double radius){

return 2 * 3.14 * radius;

}

double getRectangleArea(double length, double width){

return length * width;

}

double getTriangleArea(double base, double height){

return base * height * 0.5;

}

int main()

{

cout<<"Geometry Calculator"<<endl;

cout<<"1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit"<<endl;

cout<<"Enter your choice (1-4): "<<endl;

int choice;

cin >> choice;

double area;

while(choice != 4){

switch(choice) {

case 1: cout<<"Please enter the radius of Circle"<<endl;

double radius;

cin >> radius;

if(radius<=0) {

cout<<"The radius can not be less than zero."<<endl;

} else {

area = getCircleArea(radius);

cout<<"The area of the Circle is: "<<area<<endl;

}

break;

case 2:

cout<<"Please enter the length of Rectangle"<<endl;

double length;

cin >> length;

cout<<"Please enter the width of Rectangle"<<endl;

double width;

cin >> width;

if(length<=0 || width<=0) {

cout<<"Only enter positive values for length and width"<<endl;

} else {

area = getRectangleArea(length, width);

cout<<"The area of the Rectangle is: "<<area<<endl;

}

break;

case 3:

cout<<"Please enter the base of Triangle"<<endl;

double base;

cin >> base;

cout<<"Please enter the height of Triangle"<<endl;

double height;

cin>>height;

if(base<=0||height<=0) {

cout<<"Only enter positive values for base and height"<<endl;

} else {

area = getTriangleArea(base, height);

cout<<"The area of the Rectangle is: "<<area<<endl;

}

case 4:

cout<<"Exit"<<endl;

break;

default:

cout<<"Error: The range should be between 1 and 4"<<endl;

}

cout<<"1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit"<<endl;

cout<<"Enter your choice (1-4): "<<endl;

cin >> choice;

}

}

Output:

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):
Please enter the radius of Circle
The area of the Circle is: 12.56
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):
Please enter the length of Rectangle
Please enter the width of Rectangle
The area of the Rectangle is: 18
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):

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote