13年题。
This commit is contained in:
33
OOP/13Exam/2.5.cpp
Normal file
33
OOP/13Exam/2.5.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// 下面定义了一个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;
|
||||
}
|
||||
Reference in New Issue
Block a user