The simple example of CLASS in C++, To find the area of the Circle:

Program Code:
#include <iostream>
using namespace std;
class circle
{
int rad;
public:
void getdata()
{
cout<<"Enter the radius of the circle: ";
 cin>>rad;
}
void area()
{
 float area= 3.14*rad*rad;
cout<<"The area of the circle is = "<<area<<endl;
}
};
int main() 
{
circle cir1,cir2;
cir1.getdata();
cir1.area();
}

The output of the program is tested on www.jdoodle.com

Output:
Enter the radius of the circle: 5
The area of the circle is = 78.5


Thanks


Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: