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