Hello, I\'m supposed to create a volume calculator and have the most of the code
ID: 3606822 • Letter: H
Question
Hello, I'm supposed to create a volume calculator and have the most of the code written, but don't know how to write the code for number 4. in the instruction. Can someone help? thanks.
#include <cstdio> //
#include <cstdlib> //
#include <iostream> //
#include <stdio.h> //
#include <stdlib.h>
#include <cmath>
#include <string>
using namespace std;
void cube();
void rectangularPrism();
void cylinder();
void pyramid();
void cone();
void sphere();
double side = 0.0;
double a = 0.0;
double b = 0.0;
double c = 0.0;
double r = 0.0;
double h = 0.0;
char answer;
char choice;
char unit;
double pi = (22.0/7.0);
void cube(){
double Vol;
Vol = pow(side, 3);
cout << "The volume of your cube is " << Vol << endl;
}
void rectangularPrism(){
double Vol;
Vol = a*b*c;
cout << "The volume of your rectangular prism is " << Vol << endl;
}
void cylinder(){
double Vol;
Vol = pi*pow(r,2)*h;
cout << "The volume of your cylinder is " << Vol << endl;
}
void pyramid(){
double Vol;
Vol = (.3333)*b*h;
cout << "The volume of your pyramid is " << Vol << endl;
}
void cone(){
double Vol;
Vol = (.3333)*pi*pow(r,2)*h;
cout << "The volume of your cone is " << Vol << endl;
}
void sphere(){
double Vol;
Vol = (1.3333)*pi*pow(r,3);
cout << "The volume of your sphere is " << Vol << endl;
}
int main (void)
{
char first(100);
char last (20);
char selection;
char ending;
system ("cls");
cout << "please enter you first name ";//pronts you to enter your first name
cin >> first;
cout << "please enter you last name ";// pronts you to enter your last name.
cin >> last;
system ("cls");
cout << "Hello " <<first<<" "<<last <<" "
<<"Welcome to the Volume calculator " ;
system ("pause");
do {
cout << "A: cube Calculator" << endl;
cout << "B: rectangular prism calculator"<< endl;
cout << "C: cylinder calculator" << endl;
cout << "D: pyramid calculator"<< endl;
cout << "E: cone calculator"<< endl;
cout << "F: sphere calculator" << endl;
{
cout << "Which selection do you want from the menu?" << endl;
cin >> choice;
if (choice == 'A' || choice == 'a')
{
cout << "A: cube calculator" << endl;
cout << "Please enter the side of your cube" << " ";
cin >> side;
cube();
system ("pause");
}
else if (choice == 'B' || choice == 'b') {
cout << "B: rectangular prism calculator" << endl;
cout << "Please enter the sides of the rectangular prism" << " ";
cout << "enter value a =";
cin >> a;
cout << "enter value b =";
cin >> b;
cout << "enter value c =";
cin >> c;
rectangularPrism();
system ("pause");
}
else if (choice == 'C' || choice == 'c') {
cout << "C: cylinder calculator" << endl;
cout << "Please enter the values for the cylinder" << " ";
cout << "enter the value for the radius =";
cin >> r;
cout << "please enter the value for the height";
cin >> h;
cylinder();
system ("pause");
}
else if (choice == 'D' || choice == 'd') {
cout << "D: pyramid calculator " << endl;
cout << "Please enter the values for the pyramid" << " ";
cout << "enter the value for the base =";
cin >> b;
cout << "please enter the value for the height";
cin >> h;
pyramid();
system ("pause");
}
else if (choice == 'E' || choice == 'e') {
cout << "E: cone calculator " << endl;
cout << "Please enter the values for the cone" << " ";
cout << "enter the value for the radius =";
cin >> r;
cout << "please enter the value for the height";
cin >> h;
cone();
system ("pause");
}
else if (choice == 'F' || choice == 'f') {
cout << "F: sphere calculator " << endl;
cout << "Please enter the values for the sphere" << " ";
cout << "enter the value for the radius =";
cin >> r;
sphere();
system ("pause");
}
cout << "Would you like to try another volume calculator? Y or N " << endl;
cin >> answer;
}
} while (answer != 'N' || answer != 'n');
exit(0);
}
Explanation / Answer
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <string>
using namespace std;
void cube();
void rectangularPrism();
void cylinder();
void pyramid();
void cone();
void sphere();
double side = 0.0;
double a = 0.0;
double b = 0.0;
double c = 0.0;
double r = 0.0;
double h = 0.0;
char answer;
char choice;
char unit;
double pi = (22.0/7.0);
void cube(){
double Vol;
Vol = pow(side, 3);
cout << " cube of value " << Vol << endl;
}
void rectangularPrism(){
double Vol;
Vol = a*b*c;
cout << "The volume of your rectangular prism is " << Vol << endl;
}
void cylinder(){
double Vol;
Vol = pi*pow(r,2)*h;
cout << "The volume of your cylinder is " << Vol << endl;
}
void pyramid(){
double Vol;
Vol = (.3333)*b*h;
cout << "The volume of your pyramid is " << Vol << endl;
}
void cone(){
double Vol;
Vol = (.3333)*pi*pow(r,2)*h;
cout << "The volume of your cone is " << Vol << endl;
}
void sphere(){
double Vol;
Vol = (1.3333)*pi*pow(r,3);
cout << "The volume of your sphere is " << Vol << endl;
}
int main (void)
{
char first(100);
char last (20);
char selection;
char ending;
system ("cls");
cout << "please first name ";
cin >> first;
cout << "please last name ";// pronts you to enter your last name.
cin >> last;
system ("cls");
cout << "Hello " <<first<<" "<<last <<" "
<<"Welcome to calculator " ;
system ("pause");
do {
cout << "A: cube to Calculator" << endl;
cout << "B: rectangular prism to calculator"<< endl;
cout << "C: cylinder to calculator" << endl;
cout << "D: pyramid to calculator"<< endl;
cout << "E: cone to calculator"<< endl;
cout << "F: sphere to calculator" << endl;
{
cout << "Which one you selection do you want from the menu?" << endl;
cin >> choice;
if (choice == 'A' || choice == 'a')
{
cout << "A: cube calculator" << endl;
cout << "Please enter the side of your cube" << " ";
cin >> side;
cube();
system ("pause");
}
else if (choice == 'B' || choice == 'b') {
cout << "B: rectangular prism calculator" << endl;
cout << "Please enter the sides of the rectangular prism" << " ";
cout << "enter value a =";
cin >> a;
cout << "enter value b =";
cin >> b;
cout << "enter value c =";
cin >> c;
rectangularPrism();
system ("pause");
}
else if (choice == 'C' || choice == 'c') {
cout << "C: cylinder calculator" << endl;
cout << "Please enter the values for the cylinder" << " ";
cout << "enter the value for the radius =";
cin >> r;
cout << "please enter the value for the height";
cin >> h;
cylinder();
system ("pause");
}
else if (choice == 'D' || choice == 'd') {
cout << "D: pyramid calculator " << endl;
cout << "Please enter the values for the pyramid" << " ";
cout << "enter the value for the base =";
cin >> b;
cout << "please enter the value for the height";
cin >> h;
pyramid();
system ("pause");
}
else if (choice == 'E' || choice == 'e') {
cout << "E: cone calculator " << endl;
cout << "Please enter the values for the cone" << " ";
cout << "enter the value for the radius =";
cin >> r;
cout << "please enter the value for the height";
cin >> h;
cone();
system ("pause");
}
else if (choice == 'F' || choice == 'f') {
cout << "F: sphere calculator " << endl;
cout << " enter the values for the sphere" << " ";
cout << "please enter the value for the radius =";
cin >> r;
sphere();
system ("pause");
}
cout << "will you be like to try another volume calculator? Y or N " << endl;
cin >> answer;
}
} while (answer != 'N' || answer != 'n');
exit(0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.