Write a C++ program to input the dimensions of a cylinder and calculate and prin
ID: 3676876 • Letter: W
Question
Write a C++ program to input the dimensions of a cylinder and calculate and print the surface area and volume. Not to sure how to tackle this one. I started the header fiel and it is below. Not sure if that is correct either. I need to put together the implementation file as well as client file. Still not fully sure how to go about the whole program. So any help would be most useful. Thnak you very much for your time.
HEADER FILE BELOW:
#ifndef cylinderType_H
#define cylinderType_H
class cylinderType
{
public:
void setDimension(double h, double r);
//Function to set the height and radius of the cylinder.
//Postcondition: length = l;
double area() const;
//Function to return the area of the cylinder.
//Postcondition: The area of the cylinder is
// calculated and returned.
void print() const;
//Function to output the length and width of
//the rectangle.
cylinderType();
//Default constructor
//Postcondition: height = 0, radius = 0;
cylinderType(double h, double r);
//Constructor with parameters
//Postcondition: height = h; radius = r;
private:
double height;
double radius
};
#endif
Explanation / Answer
This below C++ code is written and updated based on the given problem statement. see the below code.
1. Created class called Cylinder with height and radius
2. Created methods defualt and parameterised and getArea and getVolume .
3. Called these class object in main method..
#include<iostream>
using namespace std;
const double PI = 3.14159;
class Cylinder
{
double height;
double radius;
public:
Cylinder()
{
height = 0.0;
radius = 0.0;
}
Cylinder(double height1, double radius1)
{
height = height1;
radius = radius1;
}
double getArea()
{
double area = 2 * PI * radius *(radius + height);
return area ;
}
double getVolume()
{
double volume = (PI * radius * radius * height);
return volume;
}
void display()
{
cout<<"Cylinder Surface Area is :"<<getArea()<<endl;
cout<<"Cylinder Volume is :"<<getVolume()<<endl;
}
};
int main()
{
Cylinder c1(15.26, 25.26);
c1.display();
return 1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.