#include <iostream.h>class juxing //矩形类
{
public:
float a;//矩形的长
float b;//宽
public:
juxing(float x,float y)//初始化
{
a=x;
b=y;
}
public:
float getS()//面积
{
return (float)(a*b);
}
float getC()//周长
{
return (float)((a+b)*2.0);
}
};class changfangxing:public juxing
{
public :
changfangxing(float a,float b):juxing(a,b)
{
}
};class zhengfangxing :public juxing //正方形
{
public:
zhengfangxing(float a):juxing(a,a)
{
}
float getS()//面积
{
return (float)(a*a);
}
float getC()//周长
{
return (float)(a*4.0);
}
};
void main()
{
changfangxing a(12.0,23.0);//构造长方形
zhengfangxing b(13.0);//构造正方形 cout<<"长方形面积:"<<a.getS()<<"长方形周长"<<a.getC()<<endl;
cout<<"正方形面积:"<<b.getS()<<"正方形周长"<<b.getC()<<endl;
return ;
}