#include<iostream.h>
#include<conio.h>
class shape
{
public:
int w,h;
shape()
{
w=h=0;
}
shape(int a, int b)
{
w=a;
h=b;
}
void asgn(int a,int b)
{
w=a;
h=b;
}
};
class rect:public shape
{
int ans;
public:
rect(int c,int d):shape(c,d)
{
}
void area()
{
ans=w*h;
}
void display()
{
cout<<"\nArea of an rectangle is:"<<ans;
}
};
class square
{
int ans;
shape s1;
public:
square(int c)
{
s1.asgn(c,c);
}
void area()
{
ans=s1.w*s1.h;
}
void display()
{
cout<<"\nArea of an Square is:"<<ans;
}
};
void main()
{
rect r(5,2);
clrscr();
r.area();
r.display();
square s(5);
s.area();
s.display();
getch();
}
No comments:
Post a Comment