打开解决方案文件proj1。程序中位于每个“//ERRORfound”下的语句行有错误,请加以更正。
更正后程序的输出应该是:
fruit1 是苹果吗?true
fruit1 是梨吗?false
fruit2 是苹果吗?false
fruit2 是梨吗?true
[程序]
//main.cpp
#include
#pragma warning(disable:4996)
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**********
name=the_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 是苹果吗?"<<fruit2.isFruit("苹果")<<endl;
cout<<"fruit2 是梨吗?"<<fruit2.isFruit("梨")<<endl;
system("pause");
return 0;
}