问答题
基本操作
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,程序中位于每个"// ERROR ****found****"之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:
fruit1 是苹果吗? true
fruit1 是梨吗? false
fruit2 是苹果吗? true
fruit2 是梨吗? False
注意:只修改"/ ERROR****found****"的下一行语句,不要改动程序中的其他内容。
#include
using namespace std;
class Fruits{ //水果类
public:
Fruits(char *the_name, float the_price);
// ERROR **********found**********
void ~Fruits() {}
bool isFruit(char *name)const; //判断是否是参数所指定的水果
private:
char name[50]; //水果名称
float price; //水果价格
};
Fruits::Fruits(char *the_name, float the_price){
// ERROR **********found**********
strcpy(the_name,name);
price = the_price;
}
bool Fruits::isFruit(char *name)const{
// ERROR **********found**********
return strcmp(name,name)==0;
}
int main(){
Fruits fruit1("苹果",3.00);
Fruits fruit2("梨",2.50);
cout << boolalpha;
cout << "fruit1 是苹果吗? " << fruit1.isFruit("苹果") << endl;
cout << "fruit1 是梨吗? " << fruit1.isFruit("梨") << endl;
cout << "fruit2 是苹果吗? " << fruit1.isFruit("苹果") << endl;
cout << "fruit2 是梨吗? " << fruit1.isFruit("梨") << endl;
return 0;
}
【参考答案】
(1)~Fruits() {}(2)strcpy(name,the_name);(3)return strcmp(thi......
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)