class Circle :public Shap
Circle(const Circle& other);
double getPerimeter()const;
Rect(double l, double w);
double getPerimeter()const;
Shap::Shap():perimeter(0),area(0)
cout << "Shap::无参构造" << endl;
cout << "Shap::析构函数" << endl;
Circle::Circle():radius(0)
cout << "Cricle::无参构造" << endl;
Circle::Circle(double r):radius(r)
cout << "Circle::有参构造" << endl;
perimeter = 2 * 3.1415926 * radius;
area = 3.1415926 * radius * radius;
Circle::Circle(const Circle& other):radius(other.radius)
cout << "Circle::拷贝构造函数" << endl;
perimeter = 2 * 3.1415926 * radius;
area = 3.1415926 * radius * radius;
double Circle::getPerimeter() const
double Circle::getArea() const
Rect::Rect():width(0),length(0)
cout << "Rect::无参构造" << endl;
Rect::Rect(double l, double w):length(l),width(w)
cout << "Rect::有参构造" << endl;
perimeter = 2 * (length + width);
Rect::Rect(const Rect& other):width(other.width),length(other.length)
cout << "Rect::拷贝构造函数" << endl;
perimeter = 2 * (length + width);
double Rect::getPerimeter() const
double Rect::getArea() const
cout << "c1: Perimeter = " << c1.getPerimeter() << ", Area = " << c1.getArea() << endl;
cout << "r1: Perimeter = " << r1.getPerimeter() << ", Area = " << r1.getArea() << endl;
cout << "c2: Perimeter = " << c2.getPerimeter() << ", Area = " << c2.getArea() << endl;
cout << "r2: Perimeter = " << r2.getPerimeter() << ", Area = " << r2.getArea() << endl;
面试题 - GitMind
C++ - day4 - GitMind
在线思维导图 - GitMind