Files
2023-06-02 00:03:58 +08:00

33 lines
649 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 下面定义了一个shape抽象类派生出Rectangle类用于计算Rectangle类对象的面积Area()。请补充完整下面的程序使程序输出60。
#include <cstring>
#include <iostream>
using namespace std;
class Shape {
public:
// _________________
virtual void Area() = 0;
};
class Rectangle : public Shape {
public:
// _________________
int width, height;
Rectangle(int _width, int _height) : width(_width), height(_height) {
}
void Area() {
cout << width * height << endl;
}
};
int main() {
Shape *sp;
Rectangle re1(10, 6);
sp = &re1;
sp->Area();
return 0;
}