13年题。

This commit is contained in:
unlockable
2023-06-02 00:03:58 +08:00
parent 955977fef2
commit 9cecf352c2
11 changed files with 401 additions and 0 deletions

33
OOP/13Exam/2.5.cpp Normal file
View 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;
}