Question

complete a C++ program that asks the user to make a choice off a menu that...

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.

Homework Answers

Answer #1

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::

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Python program named lastNameVolumes that finds the volumes of different 3 D objects such...
Write a Python program named lastNameVolumes that finds the volumes of different 3 D objects such as a cube, sphere, cylinder and cone. In this file there should be four methods defined. Write a method named cubeVolFirstName, which accepts the side of a cube in inches as an argument into the function. The method should calculate the volume of a cube in cubic inches and return the volume. The formula for calculating the volume of a cube is given below....
IN PYTHON : Write a program that asks the user for a number. Write the number...
IN PYTHON : Write a program that asks the user for a number. Write the number to a file called total.txt. Then ask the user for a second number. Write the new number on line 2 with the total for both numbers next to it separated by a comma. Then ask the user for a third number and do the same. Keep asking for numbers until the person puts in a zero to terminate the program. Close the file. Be...
C++. Write a program that draws a rocket shape on the screen based on user input...
C++. Write a program that draws a rocket shape on the screen based on user input of three values, height, width and stages. The type of box generated (i.e.. a hollow or filled-in) is based on a check for odd or even values input by the user for the box height (or number of rows). Here is the general specification given user input for the height of the box..... Draw a hollow box for each stage if the value for...
In C programming language please. -Construct a program that will make use of user defined functions,...
In C programming language please. -Construct a program that will make use of user defined functions, the do/while loop, the for loop and selection. -Using a do/while loop, your program will ask/prompt the user to enter in a positive value representing the number of values they wish to have processed by the program or a value to quit/exit. -If the user enters in a 0 or negative number the program should exit with a message to the user indicating they...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
in C++ Write a program. The program should prompt the user for the number of shares...
in C++ Write a program. The program should prompt the user for the number of shares purchased, purchase price per share, the commission for the purchase, sale commission paid, and the price the shares were sold at. The program should validate each of these values to ensure they are acceptable (none can be less than zero) and should then pass them to a function called numberfunction.The function should use the following formula to determine the profit: Profit = ((number of...
Write a program in Java that: 1. will prompt user with a menu that contains options...
Write a program in Java that: 1. will prompt user with a menu that contains options to: a. Add a To-Do Item to a todo list. A To-Do Item contains: i. An arbitrary reference number (4; 44,004; etc.) ii. A text description of the item ("Pick up dry cleaning", etc.) iii. A priority level (1, 2, 3, 4, or 5) b. View an item in the list (based on its reference number) c. Delete an item from the list (based...
please create a C++ program that will ask the user how many times to roll a...
please create a C++ program that will ask the user how many times to roll a pair of dice. The choices are 10, 20 & 50. Allow the user to select 1 choice and error if none of the choices are valid. The program will then the desired amount. The program will keep track of the running total of the sum of the dice (i.e. 5, 2 = 7; 3,6 =7+9 = 16). The program will then produce the total...
Using C++ 1. Create a program that asks the user to create 5 triangles, asking for...
Using C++ 1. Create a program that asks the user to create 5 triangles, asking for 5 bases and 5 heights (you can use an array), have a function to print the triangle bases, heights, and areas 2. Create a structure for the Triangle that holds the base and height of the triangles. Ask the user for 5 triangles, and print them. 3. Create an array of 5 structures - ask the user for 5 triangles, and then print the...
Write a program which inputs an integer value, incr, from the user at the keyboard, and...
Write a program which inputs an integer value, incr, from the user at the keyboard, and then displays a graph of the sine of the degree values from 0 to 180, in increments of incr. You must use the sin function (in a similar manner to ceil and floor) to find the sine. Note that the sin function only operates on radians so the degree value must first be converted to radians. To do so, multiply the degree value by...