欢迎来到牛牛题库网 牛牛题库官网
logo

未知题型

使用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;
}

A.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为:
B.cpp清单如下:
C.h>
D.area()
E.area()
【参考答案】

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

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

点击查看答案
微信小程序免费搜题
微信扫一扫,加关注免费搜题

微信扫一扫,加关注免费搜题