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

I\'m stuck on this part of my assignment and wanted to see how this code is set

ID: 3799727 • Letter: I

Question

I'm stuck on this part of my assignment and wanted to see how this code is set up because I am now lost. It might be different from what you have because I've gotten help here before and it helped a bit. Thank you.

Step 1: Remove switch.cpp from the project and add the areas.cpp program in your Lab4 folder to the project. This file contains just a program shell in which you will write all the programming statements needed to complete the program described below. Here is a copy of the current contents of areas.cpp. 1 Lab 4 areas. cpp 2 WRITE A COMMENT BRIEFLY DESCRIBING THE PROGRAM 3 PUT YOUR NAME HERE 4 INCLUDE ANY NEEDED FILES HERE 5 using namespace sta; 7 int main DEFINE THE NAMED CONSTANT PI HERE AND SET ITS VALUE TO 3.14159 10 DECLARE ALL NEEDED VARIABLES HERE. GIVE EACH ONE A DESCRIPTIVE 11 NAME AND AN APPROPRIATE DATA. TYPE 13 WRITE STATEMENTS HERE TO DISPLAY THE 4 MENU CHOICES 14 15 WRITE A STATEMENT HERE TO INPUT THE USER'S MENU CHOICE 16 17 18 USE AN IF/ELSE IF STATEMENT TO OBTAIN ANY NEEDED INPUT INFORMATION AND COMPUTE AND DISPLAY THE AREA FOR EACH VALID MENU CHOICE 19 IF AN INVALID MENU CHOICE WAS ENTERED AN ERROR MESSAGE SHOULD 20 21 BE DISPLAYED 22 23 return 0; 24 Step 2: Design and implement the areas. cpp program so that it correctly meets the program specifications given below. Specifications: Sample Run Create a menu-driven program that finds and Program to calculate areas of objects displays areas of 3 different objects. Square The menu should have the following 4 choices: circle 1 Square ight triangle 2 circle quit 3 right triangle quit Radius of the circle 3.0 If the user selects choice 1, the program Area 28.27 43 should find the area of a square If the user selects choice 2, the program should find the area of a circle. If the user selects choice 3, the program should find the area of a right triangle If the user selects choice 4, the program should quit without doing anything. If the user selects anything else (i.e., an invalid choice) an appropriate error message should be printed.

Explanation / Answer

Here is the solution, i have provided a while loop to continously run the program until quit is selected. If you want the program to run only one time,please remove the while loop or comment it.

#include <iostream>
using namespace std;

int main() {
  
// declare constant variable PI
const float PI = 3.14159;
  
//variables required for the area calculation
int selection=0;
float radius=0.0;
float side=0;
float area=0.0;
float height=0.0;
float base=0.0;
  
  
cout<<"Program to calculate areas of objects: " ;
  
// run until 4 is selected.
while(selection!=4)
{
cout<<" 1.Square 2.Circle 3.Rigth Triangle 4.Quit";
cout<<" Enter your choice:";
cin>>selection;
if(selection==1)
{
cout<<" Length of side:";
cin>>side;
area=side*side;
cout<<" Area of Square:"<<area;
}
else if(selection==2)
{
cout<<" Radius of circle:";
cin>>radius;
area=PI*radius*radius;
cout<<" Area of circle:"<<area;
}
else if(selection==3)
{
cout<<" Height of Triangle";
cin>>height;
cout<<" Base of Triangle";
cin>>base;
area=0.5*height*base;
cout<<" Area of Triangle:"<<area;

}
else if(selection==4)
{
cout<<" Terminating!!.";
}
else
{
cout<<" Invalid selection";
}
}
  
   return 0;
}

Output:

Program to calculate areas of objects:

1.Square
2.Circle
3.Rigth Triangle
4.Quit
Enter your choice:2
Radius of circle:3.4
Area of circle:36.3168
1.Square
2.Circle
3.Rigth Triangle
4.Quit
Enter your choice:1
Length of side:5
Area of Square:25
1.Square
2.Circle
3.Rigth Triangle
4.Quit
Enter your choice:3
Height of Triangle 12
Base of Triangle 10
Area of Triangle:60
1.Square
2.Circle
3.Rigth Triangle
4.Quit

Enter your choice:5
Invalid selection
Enter your choice:4
Terminating!!.