The simple example of CLASS in C++, To find the area of the rectangle:
Program Code:
#include <iostream>
using namespace std;
class rect
{
int a,b,c;
public:
void input()
{
cout<<"enter the value of a and b"<<"\n";
cin>>a;
cin>>b;
}
void area()
{
c=a*b;
cout<<"area of rectangle is"<<"\n";
cout<<c;
}
};
int main()
{
rect obj;
obj.input();
obj.area();
}
using namespace std;
class rect
{
int a,b,c;
public:
void input()
{
cout<<"enter the value of a and b"<<"\n";
cin>>a;
cin>>b;
}
void area()
{
c=a*b;
cout<<"area of rectangle is"<<"\n";
cout<<c;
}
};
int main()
{
rect obj;
obj.input();
obj.area();
}
The output of the program is tested on www.jdoodle.com
Output:
enter the value of a and b 5 7
area of rectangle is 35
area of rectangle is 35
Thanks
Mukesh Rajput
Post A Comment:
0 comments: