Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include using namespace std; int main ( ) { const double PI = 3 . 1 4 1 5 9 ; int choice; /
#include
#include
using namespace std;
int main
const double PI ;
int choice; User's shape choice
double radius, Circle radius
length, Rectangle length
width, Rectangle width
base, Triangle base
height, Triangle height
area; Area of the selected shape
Configure cout so real numbers are output in fixed notation with digits
following the decimal point.
cout fixed setprecision endl;
CSE Homework Points
pts Study the program in the source code file named hcpp Create a text file named hatxt
specifying within it the program output when it is run and the program input is
pts Modify hcpp storing the code for the new program in hcpp to insert a new user
choice in between Calculate the area of a triangle and Quit. The new choice shall output a prompt
asking the user to enter the base of a parallelogram and shall read the base from the keyboard. Next, it
will output a prompt asking the user to input the height of the parallelogram and shall read the height
from the keyboard. Next, the program shall calculate the area of the parallelogram and shall output the
area. All real numbers shall be output with two digits following the decimal point. Every output line shall
be terminated with a newline.
When you have completed the assignment, submit hatxt and hcpp to Gradescope for grading. Display selections and request user input
cout "Geometry Calculator
;
cout Calculate the area of a Circle
;
cout Calculate the area of a Rectangle
;
cout Calculate the area of a Triangle
;
cout Quit
;
cout "Enter your choice :
;
cin choice;
Calculate and display the area of the selected shape
switch choice
case : Area of a circle
cout
Enter the circle's radius:
;
cin radius;
if radius
cout
The radius can not be less than zero.
;
else
area PI radius radius;
cout
The area is area endl;
break;
case : Area of a rectangle
cout
Enter the rectangle's length:
;
cin length;
cout "Enter the rectangle's width:
;
cin width;
if length width
cout
Only enter positive values for length and width.
;
else
area length width;
cout
The area is area endl;
break;
case : Area of a triangle
cout "Enter the length of the base:
;
cin base;
cout "Enter the triangle's height:
;
cin height;
if base height
cout
Only enter positive values for base and height.
;
else
area base height ;
cout
The area is area endl;
break;
case : cout
Bye!
;
break;
default: cout
You may only enter or
;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started