Question: #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 =3.14159;
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 2 digits
// following the decimal point.
cout << fixed << setprecision(2)<< endl;
CSE100 Homework 320 Points
1.(10 pts) Study the program in the source code file named h3.cpp. Create a text file named h1a.txt
specifying within it the program output when it is run and the program input is 14.
2.(10 pts) Modify h3.cpp (storing the code for the new program in h3-1.cpp) to insert a new user
choice in between 3 Calculate the area of a triangle and 4 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 h1a.txt and h3-1.cpp to Gradescope for grading.// Display selections and request user input
cout << "Geometry Calculator
";
cout <<"1. Calculate the area of a Circle
";
cout <<"2. Calculate the area of a Rectangle
";
cout <<"3. Calculate the area of a Triangle
";
cout <<"4. Quit
";
cout << "Enter your choice (1-4):
";
cin >> choice;
// Calculate and display the area of the selected shape
switch (choice)
{
case 1: // Area of a circle
cout <<"
Enter the circle's radius:
";
cin >> radius;
if (radius <0)
cout <<"
The radius can not be less than zero.
";
else
{ area = PI * radius * radius;
cout <<"
The area is "<< area << endl;
break;
}
case 2: // Area of a rectangle
cout <<"
Enter the rectangle's length:
";
cin >> length;
cout << "Enter the rectangle's width:
";
cin >> width;
if (length <0|| width <0)
cout <<"
Only enter positive values for length and width.
";
else
{ area = length * width;
cout <<"
The area is "<< area << endl;
}
break;
case 3: // Area of a triangle
cout << "Enter the length of the base:
";
cin >> base;
cout << "Enter the triangle's height:
";
cin >> height;
if (base <0|| height <0)
cout <<"
Only enter positive values for base and height.
";
else
{ area = base * height *0.5;
cout <<"
The area is "<< area << endl;
}
break;
case 4: cout <<"
Bye!
";
break;
default: cout <<"
You may only enter 1,2,3, or 4.
";
}
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!