Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// P33_2.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

// P33_2.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; double PI = 3.14159; // This variable is defined globally, known to all functions in this program as PI double cross_area(double r); // Function prototype for function cross_area double side_area(double r, double h); // Function prototype for function 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 " << cross_area(r) << " inch-sqr endl; cout << "The side area of the cylinder is " << side_area(r,h) << " inch-sqr "; return 0; } double cross_area(double r) { //Cross secion area includes the disks at the bottom and the top r = r * 0.3937; // converting r to inch return 2*PI*pow(r,2); } double side_area(double r, double h) { double area; //variable local to Side_area function h = h * 0.3937; // converting h to inch area = 2*PI*r*h; return area; }

Exercise 3.6 Copy or cut and paste program P33_2.cpp to a new program called ex36.cpp. Compile and run the program for the following values: r = 2 Cm, h = 10 Cm The answer should be: The cross section area of the cylinder is 3.8955634 c The side area of the cylinder is 19.474819 inch-sqr Did you get the same answer? Explain the reason for such an error and fix the problem. Exercise 3.7 Modify the ex36.cpp to include a new function called total_area, that computes the total suface area of a cylinder. The total surface area is the sum of side area and cross section area. Call your new program ex37.cpp. For the above test values the total area must be: 23.370382 inch-sqr

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

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions

Question

Influences on Nonverbal Communication?

Answered: 1 week ago