填空题

使用VC6打开考生文件夹下的工程test42_1,此工程包含一个源程序文件test42_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为: rect area: 12 rectb area: 30 源程序文件test42_1.cpp清单如下: #include <iostream.h> class CRectangle { /***************** found *****************/ int *width, height; public: CRectangle (int,int); ~CRectangle (); int area (void) {return (*width * *height);} }; CRectangle::CRectangle (int a, int b) { width = new int; height = new int; /***************** found *****************/ width = a; *height = b; } CRectangle::~CRectangle () { delete width; delete height; } /***************** found *****************/ void main () { CRectangle rect (3,4), rectb (5,6); cout << "rect area: "<< rect.area() << endl; cout << "rectb area: "<< rectb.area() << endl; return 0; }

【参考答案】

(1) 错误:int*width,height; 正确:int*width,*height; (2) 错误:width=......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)