Question

I'm trying to write a program that can ask a user about what type of solid...

I'm trying to write a program that can ask a user about what type of solid they have and to be able to enter values like radius and length of the shape so the program can calculate the volume of a shape and print the result. I also want to give them a repeating option to input another shape if they want to.

I'm trying to use at least 7 functions that can display an output, the volumes of a rectangular solid, cylinder, sphere, regular tetrahedron, and a right circular cone in this format,

**************

volume=

**************

I also want to be able to print the volume of the largest shape calculated.

Here is my code so far. Please help!

//This program will calculate volumes of multiple types of solids.
//It will calculate certain formulas for solids and volumes.

#include <QCoreApplication>
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//SVol = single volume of solid. GVol = Greatest volume of solids.
//Need to repeat option to enter new solid over and over again.
double R, L, W, H, SVol, GVol;
int x, pi;
pi=3.14159265359;
//Type of solid
//Which type of solid
cout << "Which type of solid do you have?" << endl;
cin >> x;

//Information for different solids

//Radius of solid
cout << "Enter Radius" << endl;
cin >> R;

//Length of solid
cout << "Enter Length" << endl;
cin >> L;

//Width of solid
cout << "Enter Width" << endl;
cin >> W;

//Height of solid
cout << "Enter Height" << endl;
cin >> H;
//types of solids
//Rectangle
SVol = L*W*H;

//Cylinder
SVol = pi*pow(R,2)*H;

//Sphere
SVol = (4/3)*pi*pow(R,3);

//Regular Tetrahedron
SVol = (1/(6*sqrt(2)))*pow(L,3);

//Right Circular Cone
SVol = (pi/3) * pow(R, 2) * H;


for ( ; x>=1; x--)
{
int x;
switch(x)
{
if (x = 1) {
// print this message that the solid is...
cout << "Rectangular Solid " << endl;
break;}
}

for ( ; x>=2; x--)
{
if (x = 2) {
//print this message that the solid is...
cout << "Cylinder " << endl;
break;}
}

for ( ; x>=3; x--)
{
if (x = 3) {
//print this message if the solid is...
cout << "Sphere " << endl;
break;}
}

for ( ; x>=4; x--)
{
if (x = 4) {
//print this message if the solid is...
cout << "Regular Tetrahedron " << endl;
break;}
}

for ( ; x>=5; x--)
{
if (x = 5) {
//print this message if the solid is...
cout << "Right Circular Cone " << endl;
break;}
}
cout << "" << x << endl;
}
return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

#include <iostream>
#include <cmath>
using namespace std;
const double pi=3.14159265359;
int getOption()
{
int x;
cout << "Which type of solid do you have?" << endl;
cin >> x;
return x;
}
double rectangle()
{
double SVol,L,W,H;
//Length of solid
cout << "Enter Length" << endl;
cin >> L;
cout << "Enter Width" << endl;
cin >> W;
cout << "Enter Height" << endl;
cin >> H;

SVol = L*W*H;
return SVol;
}
double cone()
{
double SVol,R,H;
cout << "Enter Radius" << endl;
cin >> R;
cout << "Enter Height" << endl;
cin >> H;
SVol = (pi/3.0) * pow(R, 2.0) * H;
return SVol;

}
double cylinder()
{
double SVol,R,H;
cout << "Enter Radius" << endl;
cin >> R;
cout << "Enter Height" << endl;
cin >> H;
//Cylinder
SVol = pi*pow(R,2.0)*H;
return SVol;

}
double sphere()
{
double SVol,R;
cout << "Enter Radius" << endl;
cin >> R;
SVol = (4.0/3.0)*pi*pow(R,3.0);
return SVol;

}
double tetra()
{
double SVol,L;
//Length of solid
cout << "Enter Length" << endl;
cin >> L;
SVol = (1.0/(6.0*sqrt(2.0)))*pow(L,3.0);
return SVol;

}
void print(double SVol)
{
cout<<"Volume="<<SVol<<endl;
}
void menu()
{
cout<<"Press 1 for rectangle Press 2 for cylinder Press 3 for sphere Press 4 for Tetrahedron Press 5 for cone ";
}
int main()
{
//SVol = single volume of solid. GVol = Greatest volume of solids.
//Need to repeat option to enter new solid over and over again.
double R, L, W, H, SVol, GVol;
int x, pi;

//Type of solid
//Which type of solid

//Information for different solids
char choice='y';
while(choice!='N'&&choice!='n')
{menu();
x=getOption();
switch(x)
{
case 1:
SVol=rectangle();
print(SVol);
break;
case 2:
SVol=cylinder();
print(SVol);
break;

case 3:
SVol=sphere();
print(SVol);
break;

case 4:
SVol=tetra();
print(SVol);
break;

case 5:
SVol=cone();
print(SVol);
break;

default:
cout<<"Invalid input!!"<<endl;
break;

}
cout<<"Continue <y/n>: ";
cin>>choice;
}
return 0;
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
I'm trying to write a program that can ask a user about what type of solid...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE TYPE OUT IN TEXT (please no pdf or writing) C++ CODE Consider the following program...

    PLEASE TYPE OUT IN TEXT (please no pdf or writing) C++ CODE Consider the following program in which the statements are in the incorrect order. Rearrange the statements in the following order so that the program prompts the user to input: The height of the base of a cylinder The radius of the base of a cylinder The program then outputs (in order): The volume of the cylinder. The surface area of the cylinder Format the output to two decimal...

  • can someone assist me and tell me what I'm missing. I managed to get it this...

    can someone assist me and tell me what I'm missing. I managed to get it this far but still missing two parts to complete it. CENGAGE MINDTAP Programming Exercise 6-4 Tasks main.cpp + 1 #include <iostream r with successful Uses piand 2 #include <cnath> output 5,00 out of 10.00 3 using nanespace std; 4 5 const double PI = 3.1419; 2 out of 4 checks passed. Review 6 the results below for more details. 7 int main() 8 ( Checks...

  • Consider the following program in which the statements are in the incorrect order. Rearrange the statements...

    Consider the following program in which the statements are in the incorrect order. Rearrange the statements so that the program prompts the user to input the height and the radius of the base of a cylinder and outputs the volume and surface area of the cylinder. Formant the output to two decimal places. #include <iomanip> #include <cmath> int main () {} double height; cout << ”Volume of the cylinder = “ <<PI * pow(radius, 2.0) * height << endl; cout...

  • I am trying to write this code which asks "Write a program that ask the user,...

    I am trying to write this code which asks "Write a program that ask the user, the question: What is a^b? //The program generates two signed integers and gives the user four attempts to get the correct answer //a=- , b = + //a= + , b = - " So far this what I wrote. I am not sure how to do this correctly. #include<iostream> #include<cstdlib> #include<ctime> using namespace std; int main() {    srand(time(0));    int guess,a,ans,b, k;...

  • The statement in the following program is in the incorrect order. Rearrange the statements so that...

    The statement in the following program is in the incorrect order. Rearrange the statements so that they prompt the user to input the shape type (rectangle, circle, or cylinder) and the appropriate dimension of the shape. The program then outputs the following information about the shape: For a rectangle, it outputs the area and perimeter, for a circle, it outputs the area and circumference; and for a cylinder, it output the volume and surface area. After rearranging the statements, your...

  • Write a C program named assignment04.cpp that will ask for and read in a float for...

    Write a C program named assignment04.cpp that will ask for and read in a float for a radius ask for and read in a float for the height each of the following functions will calculate some property of a shape (area, volume, circumference, etc) The functions will accept one or two parameters (radius and/or height) and return the proper calculation. There is no input/output (cin or cout) in the function – just the calculation write the following functions float areaCircle(float...

  • I'm trying to get this program to give the user an option to enter a random...

    I'm trying to get this program to give the user an option to enter a random word and then have that word included at the end of each break in the story. I can get the option to ask for a word, but can't get the inputted word in the sentence to finish it. I believe my string story is wrong. Please help! //This program will ask a user to input three random words. //The words will be placed within...

  • In C++ I am trying to implement a log base 2 hash table utilizing the shift...

    In C++ I am trying to implement a log base 2 hash table utilizing the shift function. So, the code determines the position of where the value will be stored using log2. But am having issues using the shift part as everything just wants to pile on to zero. //ChainingHash - log2 #include<iostream> #include<vector> #include<iterator> #include<string> #include<cmath> using namespace std; #define BUCKET 10 //no. of buckets class Hash {    vector<int>*table; //ptr containing buckets       public:        Hash();...

  • in C++ use Inheritance for the following Shape Circle Sphere Cylinder Rectangle Square Cube You must define one class for each shape. And, use public inheritance when deriving from base cla...

    in C++ use Inheritance for the following Shape Circle Sphere Cylinder Rectangle Square Cube You must define one class for each shape. And, use public inheritance when deriving from base classes. Circle int r; void area(); void perimeter(); void volume(); //No volume for circle Sphere int r; void area();//Sphere surface area= 4 × pi × radius2 void perimeter(); //No perimeter for Sphere void volume();//Sphere volume= 4/3 × pi × radius2 Cylinder int r, height; void area();// Cylinder surface area=perimeter of...

  • -can you change the program that I attached to make 3 file songmain.cpp , song.cpp ,...

    -can you change the program that I attached to make 3 file songmain.cpp , song.cpp , and song.h -I attached my program and the example out put. -Must use Cstring not string -Use strcpy - use strcpy when you use Cstring: instead of this->name=name .... use strcpy ( this->name, name) - the readdata, printalltasks, printtasksindaterange, complitetasks, addtasks must be in the Taskmain.cpp - I also attached some requirements below as a picture #include <iostream> #include <iomanip> #include <cstring> #include <fstream>...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT