1. Write a C++ program to calculate the surface area, volume, or \"girth + depth
ID: 3632550 • Letter: 1
Question
1. Write a C++ program to calculate the surface area, volume, or "girth + depth" of a box. The formula are as follows: Volume = LWD (Length * Width * Depth) Surface Area = 2LW + 2WD + 2 LD Girth+Depth = 2(L+W) + D The formula above are given in algebra; you will have to translate to C++.2. The input of the program will be a letter. "v: will indicate volume, "A" the surface area, "G" the Girth plus Depth, and "Q" to stop the loop (Q is the sentinel). the second part of the input will be a three (float) numbers representing the Length, width, and depth respectively. For example: A 2.0 3.0 4.0 means find teh surface area of a box with length = 2.0 width = 3.0 and depth = 4.0.
3. For each input, just calculate what is called for, not all three answers. Use nested if-elses, or a switch structure to control your actions. The output should have appropriate labels. Use format to control the appearance of your answers.
4. Use sentinel loops to read the data. The Q for the operation will be the sentinel. The program should work for any data set, not just the data set below.
5. Libraries: iostream , iomanip
Input: A = 1.0 2.0 3.0
G = 5.0 4.0 3.0
V = 2.3 4.9 6.7
A = 3.7 4.3 9.6
Q = stop the loop
Explanation / Answer
please rate - thanks
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{double length,width,depth,result;
char choice;
do
{cout<<"What would you like to calculate? ";
cout<<"V - volume ";
cout<<"A - surface area ";
cout<<"G - girth plus depth ";
cout<<"Q = quit ";
cin>>choice;
if(choice!='q'&&choice!='Q')
{cout<<"enter length: ";
cin>>length;
cout<<"enter width: ";
cin>>width;
cout<<"Enter depth: ";
cin>>depth;
}
switch(choice)
{case 'v':
case 'V': result=length*width*depth;
cout<<"Volume = "<<result<<endl;
break;
case 'A':
case 'a': result=2*(length*width)+2*(width*depth)+2*(length*depth);
cout<<"Area = "<<result<<endl;
break;
case 'G':
case 'g': result=2*(length+width)+depth;
cout<<"Girth = "<<result<<endl;
}
}while(choice!='q'&&choice!='Q');
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.