#include <iostream>
#include "Rectangle.h"
using namespace std;
int main(){
const int N = 3;
Rectangle *pRectangle[N];
int width,height;
for (int i = 0; i < N; ++i) {
cout << "请输入第" << i << "个矩形的宽度和高度";
cin >> width >> height;
pRectangle[i] = new Rectangle(width,height);
pRectangle[i] -> display();
}
for (int i = 0; i < N; ++i) {
delete pRectangle[i];
}
return 0;
}
不太理解,明天再看看。
输出结果
请输入第0个矩形的宽度和高度3 5
Constructor called.
Width = 3 Height = 5 Area = 15 Perimeter = 16
请输入第1个矩形的宽度和高度1 5
Constructor called.
Width = 1 Height = 5 Area = 5 Perimeter = 12
请输入第2个矩形的宽度和高度4 9
Constructor called.
Width = 4 Height = 9 Area = 36 Perimeter = 26
Destrcutor called.
Destrcutor called.
Destrcutor called.
|