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();
}
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
The area of the circle is = 78.5
Thanks
Mukesh Rajput
Post A Comment:
0 comments: