33 lines
649 B
C++
33 lines
649 B
C++
// 下面定义了一个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;
|
||
} |