Question

In: Computer Science

Exercise 5.5 PART A Copy or cut and paste program P5_2.cpp (located below) to a new...

Exercise 5.5

PART A

Copy or cut and paste program P5_2.cpp (located below) to a new program called ex55.cpp. Make PI a constant value. Compile and run the program for the following values:

r = 2 cm, h = 10 cm

The correct answer should be:
      The cross-section area of the cylinder is 3.89556 inch-sq
      The side area of the cylinder is 19.4778 inch-sqr

Did you get the correct answer? You didn't! Explain the reason for this logic error in your report. Now add the instruction that fixes the problem (yes, you need just one instruction) and save your file in ex55.cpp file.   HINT: r=r*0.3937; //converting r to inch

PART B

Modify the ex55.cpp to include a new function called total_area that computes the total surface area of a cylinder. The total surface area is the sum of the side area and cross-section area. Call your new program ex56.cpp.

For r=2 and h=10, the total area must be:  23.373383 inch-sqr.

Program P5_2.cpp:

// P 5_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;

//Let’s declare first any global constant, if any required

// This variable is defined globally, i.e. it is known to all functions in this program as PI

// To declare a global constant you must write it outside the main() function

const double PI = 3.14159;  

//Now we declare any programmer defined function

double cross_area(double r);                          // Function prototype for function cross_area
double side_area(double r, double h);            // Function prototype for function Side_area

// Start defining the main function

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 \n";
      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 \n";

      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 \n\n";

      return 0;
}

// Definition of all programmer defined functions

double cross_area(double r)
{
     //Cross section 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;
}

Solutions

Expert Solution

Solution:

PART A

#include<bits/stdc++.h>
using namespace std;

const double PI = 3.14159;

//Now we declare any programmer defined function

double cross_area(double r); // Function prototype for function cross_area
double side_area(double r, double h); // Function prototype for function Side_area

// Start defining the main function

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 \n";
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 \n";

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 \n\n";

return 0;
}

// Definition of all programmer defined functions

double cross_area(double r)
{
//Cross section 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
//new line which is added is below
r=r*0.3937; //converting r to inch
area = 2*PI*r*h;
return area;
}

-----------------------------------------------------------------------------------------------------------------------------------------------------------

PART B

#include<bits/stdc++.h>
using namespace std;

const double PI = 3.14159;

//Now we declare any programmer defined function

double cross_area(double r); // Function prototype for function cross_area
double side_area(double r, double h); // Function prototype for function Side_area
double total_area(double r, double h); // Function prototype for function total_area
// Start defining the main function

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 \n";
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 \n";

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 \n";
cout << "The total surface area of the cylinder is "<<setprecision(8) << total_area(r,h) << " inch-sqr \n\n";

return 0;
}

// Definition of all programmer defined functions

double cross_area(double r)
{
//Cross section 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
  
r=r*0.3937; //converting r to inch
area = 2*PI*r*h;
return area;
}

double total_area(double r, double h)
{
  
double area= side_area(r,h)+cross_area(r); // calculating the total surface area
return area;
}


Related Solutions

Research question: cut and paste the appropriate part of the FASB Codification that contains the rule....
Research question: cut and paste the appropriate part of the FASB Codification that contains the rule. – the section reference, and the exact rule. Find the FASB rules that define when one company is deemed to have control over a second one. (5 points)
For each of the questions below, cut and paste the question onto an email or word...
For each of the questions below, cut and paste the question onto an email or word document. Provide a short answer and email it to me by the due date. Short answer is all that is required. Demonstrate you understand the subject and support your answer. For question #2 below, your answer can be more opinion based. That is, how you feel or your position regarding the topic is more important to me than citing a source that doesn’t agree...
Please no copy and paste from other website: EXERCISE #1 - PHYSICAL AND PROCEDURAL CONTROLS FOR...
Please no copy and paste from other website: EXERCISE #1 - PHYSICAL AND PROCEDURAL CONTROLS FOR PROTECTING ASSETS - GENERAL DISCUSSION "Security Management Standard: Physical Asset Protection" is a 2012 ASIS International publication that assists security directors in completing their security planning. "ASIS International Facilities Physical Security Measures Guideline," also assists organizations in determining risk levels and the appropriate controls to secure assets in the most effective, efficient, and cost-saving manner. After thoroughly reviewing these documents, summarize their contents and...
Block copy, and paste, the argument into the window below, and do a proof to prove...
Block copy, and paste, the argument into the window below, and do a proof to prove that the argument is valid. 1. (p   ⊃ z)   •   (q • ~z) 2. (~p • q)    ⊃   s 3. m   v ~s     : .    m
Block copy, and paste, the argument into the window below, and do a proof to prove...
Block copy, and paste, the argument into the window below, and do a proof to prove that the argument is valid. 1. (p   • q)   •   (q ⊃   x) 2. ~x v ~s 3. n   v   s     : .    t ⊃ n
Block copy, and paste, the argument into the window below, and do a proof to prove...
Block copy, and paste, the argument into the window below, and do a proof to prove that the argument is valid. 1. (p   ⊃   x) • (x ⊃ ~q) 2. p •   n 3.   t v q     : .     t
Block copy, and paste, the argument into the window below, and do a proof to prove...
Block copy, and paste, the argument into the window below, and do a proof to prove that the argument is valid. 1. (p   ⊃ z)   •   (q • ~z) 2. (~p • q)    ⊃   s 3. m   v ~s     : .    m
Block copy, and paste, the argument into the window below, and do a proof to prove...
Block copy, and paste, the argument into the window below, and do a proof to prove that the argument is valid. This question is worth 25 points.    1. (p   ⊃   x) • (x ⊃ ~q) 2. p •   n 3.   t v q     : .     t
Block copy, and paste, the argument into the window below, and do a proof to prove...
Block copy, and paste, the argument into the window below, and do a proof to prove that the argument is valid. This question is worth 25 points. 1. (p   • q)   •   (q ⊃   x) 2. ~x v ~s 3. n   v   s     : .    t ⊃ n
PLEASE DO NOT COPY AND PASTE PREVIOUS ANSWERED QUESTION. Working effectively and efficiently as part of...
PLEASE DO NOT COPY AND PASTE PREVIOUS ANSWERED QUESTION. Working effectively and efficiently as part of a team can be challenging. But when done properly, teamwork offers many benefits as different people bring their experience, education, knowledge, and skills to resolve a problem. The ability to work with others and collaborate in teams is an important skill in the world today. It is likely that, as a business professional, you will be called upon to work as a valuable member...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT