问答题

请使用VC6或使用[答题]菜单打开考生文件夹proj1下的工程proj1,此工程中包含程序文件main.cpp,其中有ElectricFan(“电风扇”)类和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 品牌:清风牌,电源:关,风速:0 品牌:清风牌,电源:开,风速:3 品牌:清风牌,电源:关,风速:0 注意:只修改每个“//ERRO****found****”下的那一行,不要改动程序中的其他内容。 #include<iostream> using namespace std; class ElectricFan{ //"电扇"类 char * brand; int intensity; //风速: 0-关机, 1-弱, 2-中, 3-强 public: ElectricFan (const char * the_brand): intensity(0){ brand = new char [ strlen (the_brand) +1]; strcpy(brand, the_brand); } ~ElectricFan() {delete []brand; } //ERROR **********found********** const char * theBrand()const{ return* brand;} //返回电扇品牌 int theIntensity () const { returnintensity; } //返回风速 bool isOn()const{ return intensity>0;} //ERROR **********found********** void turnOff() { intensity=1; } //关电扇 void setIntensity (int inten){ //ERROR **********found********** if (intensity>=i && intensity <=3) intensity =inten; } void show () { cout<< "品牌:"<<theBrand () <<"牌" <<",电源:" <<(isOn () "开":"关") <<",风速:" <<theIntensity () <<endl; } }; int main() { ElectricFan fan ("清风"); fan. show () ; fan. setIntensity (3); fan. show (); fan. turnOff (); fan. show (); return 0; }

【参考答案】

(1)const chin*theBrand()conm{return brand;} //返回电扇品牌 (2)voi......

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