Exercise 5.5 (EASY) for beginning CS CLASS
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 ex55b.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;
}
//Part A
//Before making change

//Change Made

//After Change

//PART B
//Function added

//Full program
// 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<iostream>
#include<cmath>
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
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 area of the cylinder is " <<
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 <-----Change made
area = 2*PI*r*h;
return area;
}
double total_area(double r, double h)
{
return cross_area(r)+side_area(r,h);//call the
respective functions and return their sum
}
//output

Exercise 5.5 (EASY) for beginning CS CLASS PART A Copy or cut and paste program P5_2.cpp...
Write a C program named assignment04.cpp that will ask for and read in a float for a radius ask for and read in a float for the height each of the following functions will calculate some property of a shape (area, volume, circumference, etc) The functions will accept one or two parameters (radius and/or height) and return the proper calculation. There is no input/output (cin or cout) in the function – just the calculation write the following functions float areaCircle(float...
In this exercise, you will modify the hypotenuse program shown earlier in Figure 9-6. Follow the instructions for starting C++ and viewing the ModifyThis13.cpp file, which is contained in either the Cpp8/Chap09/ModifyThis13 Project folder or the Cpp8/Chap09 folder. Remove both calculation tasks from the main function, and assign both to a program-defined value-returning function named getHypotenuse. Test the program appropriately. //Hypotenuse.cpp - displays the length of a right //triangle's hypotenuse #include <iostream> #include <iomanip> #include <cmath> using namespace std; int...
Please help me to write a program in C++ with comments and to
keep it simple as possible.
Thank you!
Here is my program I have done before and that need
to be change:
#include <iostream>
#include <iomanip>
using namespace std;
// function prototype – returning one value
double cylvol(double, double); // Note: two data types inside
brackets
double surfarea(double, double); // Note: two data types inside
brackets
int main()
{
double r, l, V, S;
cout << setprecision(2) <<...
C++ programming question will upvote
A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following int main //the radius of the...
Exercise 2: There can be several constructors as long as they differ in number of parameters or data type. Alter the program so that the user can enter just the radius, the radius and the center, or nothing at the time the object is defined. Whatever the user does NOT include (radius or center) must be initialized somewhere. There is no setRadius function and there will no longer be a setCenter function. You can continue to assume that the default...
In c++ Please. Now take your Project 4 and modify it. You’re going to add another class for getting the users name. Inherit it. Be sure to have a print function in the base class that you can use and redefine in the derived class. You’re going to also split the project into three files. One (.h) file for the class definitions, both of them. The class implementation file which has the member function definitions. And the main project file where your main...
Need some help on this C++ program. Circle - color:String - radius:double +Circle() +Circle(newColor:String, newRadius:double) +setColor(color:String):void +setRadius(radius:double):void +getColor():String +getRadius():double +printCircleInfo():void Create the class using three files - a .h, a .cpp and a main.cpp Create a class called Circle as describe below Constructor with no arguments Sets radius to 1 and color to “black” Constructor with arguments Sets the color and radius to the values passed in Get methods (accessors) return the field that the get refers to Set methods...
C++ Exercice
Topic Cover: Class and main implementation 1. Created the class circle.h file 2. Create the Circle. cpp 3. Create the main function and use the class Circle in your program (CircleClass) Create a class called circle in other to performing the calculation of the area, sectional area and circumference of any circle. Write a program to test your class. Circle Use double variables to represent the private data of the class. Provide a constructor that enables an object...
C++ Class and Operator Overloading part 1 The source file contains a C++ program that declares and initializes an array of Circles. The program is using a for loop statement to find the largest circle in the array and display it on the output screen. However, the program is currently not working. The problem is the program uses logical operator ' > ' for comparison of circles and it is not working unless we overload such operator for the class...
in C++ use Inheritance for the following Shape Circle Sphere Cylinder Rectangle Square Cube You must define one class for each shape. And, use public inheritance when deriving from base classes. Circle int r; void area(); void perimeter(); void volume(); //No volume for circle Sphere int r; void area();//Sphere surface area= 4 × pi × radius2 void perimeter(); //No perimeter for Sphere void volume();//Sphere volume= 4/3 × pi × radius2 Cylinder int r, height; void area();// Cylinder surface area=perimeter of...