Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

THE PICTURE IS THE MAKE UP LAB 3 REFERRED TO IN THE DESCRIPTION , AND THE DESCRI

ID: 3591213 • Letter: T

Question

THE PICTURE IS THE MAKE UP LAB 3 REFERRED TO IN THE DESCRIPTION , AND THE DESCRIPTION IS WHAT WE HAVE TO CHANGE ABOUT MAKE UP LAB USE C++

In Labs 1 - 3 Makeup,, you were required to write 6 while loops to check input for dimensions of 3 - dimensional objects.. For this lab,, you should redo Labs 1 - 3 makeup with function calls replacing the while loops to check dimensions and write a fun ction to check the validity.. ( I have posted a possible sol ution for Labs 1 - 3 makeup that you can use if you did not do Labs 1 - 3 makeup . Review this possible solution,, fix any errors,, then make the changes for this lab..)

The new function that you add to check the validity should accept two parameters:: one a doub le and one a string.. You should send the dimension that is being checked to the double parameter and a description of what that dimension stands for (ee..gg.. “rradius of sphere””,, “hheight of box””,, etc..)) to the string parameter.. The function should employ a si ngle while loop to check the validity of dimension and prompt the user to re - enter the dimension when it is wrong.. There should not be any selection structures in this function.. Your error message should what dimension is wrong be similar to

“The length of the box cannot be less than zero.. Please enter the length of the box again..””

You should only have one function other than main.. Do not use and string objects to store the descriptions of the dimensions,, rather send a literal constant to the function

Explanation / Answer

#include <iostream>

using namespace std;

int main()

{

char s, S,c, C,b, B,q, shape;

  

int radius,height,width,length;

double volume;

cout<<"This program will calculate the volume of a box, cylinder, or sphere from entered dimensions."<<endl;

do

{

  

cout<<"Choose the shape of your object:"<<endl;

cout<<"box (b or B), cylinder (c or C), sphere (s or S), or quit (q) this program.";

cin>>shape;

}while(shape!=q);

switch(shape)

{

case 'b':

cout << " You want to enter a box." << endl;

cout<<"Enter the height of your box. ";

cin>>height;

cout<<"Enter the width of your box. ";

cin>>width;

cout<<"Enter the length of your box. ";

cin>>length;

volume=height*width*length;

cout<<"A box with height of "<<height<<", width of "<<width<<", and length of "<<length<<" has a volume of "

<<volume<<endl;

break;

case 'B':

cout<<"Enter the height of your box. ";

cin>>height;

cout<<"Enter the width of your box. ";

cin>>width;

cout<<"Enter the length of your box. ";

cin>>length;

volume=height*width*length;

cout<<"A box with height of "<<height<<", width of "<<width<<", and length of "<<length<<" has a volume of "

<<volume<<endl;

break;

case 'c':

cout<<"Enter the radius of your cone. ";

cin>>radius;

cout<<"Enter the height of your cone. ";

cin>>height;

volume=height*width*length;

cout<<"A cone with radius of "<<radius<<" and height of "<<height<<" has a volume of "

<<volume<<endl;

break;

case 'C':

cout<<"Enter the radius of your cone. ";

cin>>radius;

cout<<"Enter the height of your cone. ";

cin>>height;

volume=height*width*length;

cout<<"A cone with radius of "<<radius<<" and height of "<<height<<" has a volume of "

<<volume<<endl;

break;

case 's':

cout<<"Enter the radius of your sphere. ";

cin>>radius;

volume=4/3*3.14159*radius*radius;

cout<<"A sphere with radius of "<<radius<<" has a volume of "

<<volume<<endl;

break;

case 'S':

cout<<"Enter the radius of your sphere. ";

cin>>radius;

volume=4/3*3.14159*radius*radius;

cout<<"A sphere with radius of "<<radius<<" has a volume of "

<<volume<<endl;

break;

}return 0;

}