A simple class example

using namespace std;
class rectangle
{
private:
int len,br;
public:
void getdata()
{
cout<<endl<<“enter length and breadth”<<endl;
cin>>len>>br;
}
void setdata(int i,int b){
len=i;
br=b;
}
void displaydata(){
cout<<endl<<“length= “<<len;
cout<<endl<<“Breadth= “<<br;
}
void per()
{
int a;
a=len*br;
cout<<endl<<“area= “<<a;
}
};
int main()
{
rectangle r1,r2,r3;
r1.setdata(10,20);
r1.displaydata();
r1.per();
r2.setdata(2,3);
r2.displaydata();
r2.per();

r3.getdata();
r3.displaydata();
r3.per();
return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s