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....
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...
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...
Description: The purpose of this assignment is to practice writing code that calls functions, and contains...
Description: The purpose of this assignment is to practice writing code that calls functions, and contains loops and branches. You will create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. General Comments: Your code must contain at least one of all of the following control types: nested for() loops a while() or a do-while() loop a switch() statement 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...
C++:Write a complete program that repeatedly asks the user to enter pairs of double-type numbers until...
C++:Write a complete program that repeatedly asks the user to enter pairs of double-type numbers until at least one of the pair is 0. For each pair, the program should use a function to calculate the harmonic mean of the numbers. This function should use both calling-by-value and calling-by reference methods when passing parameters (i.e. some parameters called by value and others called by reference), and the type of this function should be void. All the input and output processes...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT