Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// P34_1.cpp This program illustrates the local and global variables and call-by-value. // This program computes the side area and the cross section area of

// P34_1.cpp This program illustrates the local and global variables and call-by-value. // This program computes the side area and the cross section area of a cylinder #include #include using namespace std; const double PI = 3.14159; // This variable is defined globally, known to all functions in this program as PI const double conversion = 0.3937; // This is the Cm to inch conversion factor double area(double r); // Function declaration for function that computes cross section area double area(double r, double h); // Function declaration for function that computes side area int main(void) { double h, r; //variables local to the main function cout << "Enter the radius and the height of the cylinder in Cm "; cin >> r >> h; cout << endl; cout << "Before I do any computation or call any function, I want to let you know that "; cout << "you have entered r = " << r << " and h = " << h << "." << endl; cout << "I am planning to use inch, thus in the first function, I will convert r, and " << endl; cout << "in the second one I will convert h "; cout << "The cross section area of the cylinder is " << area(r) << " inch-sqr endl; cout << "The side area of the cylinder is " << area(r,h) << " inch-sqr "; return 0; } double area(double r) { //Cross secion area includes the disks at the bottom and the top r = r * conversion; // converting r to inch return 2*PI*pow(r,2); } double area(double r, double h) { double area; //variable local to Side_area function h = h * conversion; // converting h to inch r = r * conversion; // converting r to inch area = 2*PI*r*h; return area; }

Modify program P34_1.cpp to compute the side area, total area, and volume of a cylinder and the area and volume of a sphere, depending on the choice that the user makes. Your program should ask users to enter 1 to choose cylinder or 2 for sphere, and display an "invalid choice error" for other values. For a cylinder, we want to compute Side area: (2*PI*r) * h Total Area: 2*(PI*r2) + Side area Volume: (PI*r2)*h For a sphere, we want to compute Surface area: 4*PI*r2 Volume: (4.0/3.0)*PI*r3. Use overloading whenever possible.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions