📄 1354520.txt
字号:
shape.cpp
#include "shape.h"
#include <iostream.h>
#define PI 3.1415926
Rectangle::Rectangle(int m, int n):shape(m,n)
{
}
float Rectangle::GetArea()
{
return x*y;
}
float Rectangle::GetPerim()
{
return 2*(x+y);
}
Circle::Circle(int r):shape(r)
{
}
float Circle::GetArea()
{
return (PI*x*x);
}
float Circle::GetPerim()
{
return (2*PI*x);
}
Squre::Squre(int m):Rectangle(m, m)
{
}
void main()
{
Rectangle obj1(3,5);
cout<<"矩形,长3,5,面积周长分别为:"<<endl;
cout<<obj1.GetArea()<<endl;
cout<<obj1.GetPerim()<<endl;
Squre obj2(4);
cout<<"正方形,边长为4,面积周长分别为:"<<endl;
cout<<obj2.GetArea()<<endl;
cout<<obj2.GetPerim()<<endl;
Circle obj3(10);
cout<<"圆,半径为5,面积周长分别为:"<<endl;
cout<<obj3.GetArea()<<endl;
cout<<obj3.GetPerim()<<endl;
}
shape.h
class shape{
protected:
int x, y;
public:
shape(int m = 0, int n = 0)
{ x = m; y = n; }
virtual float GetArea() = 0;
virtual float GetPerim() = 0;
};
class Rectangle:public shape{
public:
Rectangle(int m, int n);
float GetArea();
float GetPerim();
};
class Circle:public shape{
public:
Circle(int r);
float GetArea();
float GetPerim();
};
class Squre:public Rectangle{
public:
Squre(int m);
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -