C++ program – Classes with primitive data members

0
1349

C++ program – Classes with primitive data members

CONSTRUCTION:

  1. Start the program.
  2. Include header files.
  3. Create a class calculate and declare the necessary data members and member functions.
  4. Get the values for r, h and invoke the number function inside the class using object.
  5. Stop the program.

PROGRAM:

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>

class calculate
{
float v;
public:
void cylinder(float r,float h)
{
float pi=3.14;
v=pi*r*r*h;
cout<<"volume of the cylinder:"<<v;
}
};

void main()
{
clrscr();
calculate c;
float r,h;
cout<<setw(20)<<"cylinder.volume"<<endl;
cout<<setw(15)<<"____________________"<<endl;
cout<<"\nEnter the radius";
cin>>r;
cout<< "\nEnter the height";
cin>>h;
c.cylinder(r,h);
}

 

Leave a Reply