complete a C++ program that asks the user to make a choice off a menu that will be displayed to them. The user can make as many selections as they wish. The last choice from the menu will give them an option to stop.
The menu choices will be the following four calculations:
Find the volume of a cone
Find the volume of a sphere
Find the area of octagon
Find the distance between two points
Stop
For the different formulas, you will need to do some different function calculations these either finding the square root of a value, finding a number raised to a power or both. You must use the cmath library functions "pow" and/or "sqrt" to do the calculations. Along with this you will use acos(-1) for an estimation on . This value must be saved using a constant variable.
The main function allows the user to pick from the menu. Depending on what choice they make they will be prompted for all the values that will be needed to make the requested calculations. i.e. if the choose "1" then they will be asked for the radius and the height. The outputs must be similar to the following:
The volume of a cone with radius 5 and height 3.5 is 91.63.
The volume of a cone with radius 5.2 is 588.98.
The area of the octagon with side length 3.4 is 55.82.
The distance between the two give points is (3, 2) and (1.5, 6.5) is approximately 4.7434.
Required parts of the program:
You must use a "do while" loop to allow the user to choose from the menu.
You must use a "switch statement" to process the user’s choice.
You must use the above mentioned cmath functions in your calculations.
You must make a user define function for the fore mentioned formulas. Each function must have a prototype statement that is before the beginning of the "main" function with the function declaration after the end of the "main" function. Each function must receive all the values needed to make the calculation and return the result.
PROGRAM::
#include <iostream>
#include<bits/stdc++.h>
#include <cmath>
#define PI 3.14159265359
using namespace std;
int main()
{
double height, radius, side, x1,y1, x2, y2;
double volCone = 0.0;
double volSphere = 0.0;
double octArea = 0.0;
double dis = 0.0;
int ch;
do
{
cout<<"\nMENU\n1 - Find volume of cone.\n2 - Find volume of
sphere.\n3 - Find area of octagon\n4 - FInd the distance between 2
Points."<<
"\n5 - STOP"<<endl;
cout<<"\nChoose an option:";
cin>>ch;
switch(ch)
{
case 1 : cout<<"Enter radius of cone: ";
cin>>radius;
cout<<"Enter height of cone: ";
cin>>height;
volCone = (1.0/3.0)*PI*pow(radius,2)*height;
cout<<"\nVolume of the cone with radius
"<<radius<<" and height "<<height<<" is:
"<<fixed << setprecision(2) << volCone;
break;
case 2 : cout<<"Enter radius of sphere: ";
cin>>radius;
volSphere = (4.0/3.0)*PI*pow(radius,3);
cout<<"\nVolume of the sphere with radius
"<<radius<< " is: "<<fixed <<
setprecision(2) << volSphere; break;
case 3 : cout<<"Enter side length of Octagon: ";
cin>>side;
octArea = 2.0*pow(side,2)*(1.0+sqrt(2));
cout<<"\nArea of octagon with side "<<side<<" is:
"<<fixed << setprecision(2) << octArea;
break;
case 4 : cout<<"Enter x1 and y1: ";
cin>>x1>>y1;
cout<<"Enter x2 and y2: ";
cin>>x2>>y2;
dis = sqrt(pow((x2-x1),2)+pow((y2-y1),2));
cout<<"\nThe distance between
("<<x1<<","<<y1<<") and
("<<x2<<", "<<y2<<") is: "<<fixed
<< setprecision(4) <<dis; break;
case 5 : break;
}
}while(ch!=5);
return 0;
}
SCREENSHOT::
Get Answers For Free
Most questions answered within 1 hours.