清使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl,此工程中包含了类Pets(“宠物”) 和主函数main的定义。程序中位于每个“//ERROR****found ****”之后的一行语句有错误,请加以改 正。改正后程序的输出结果应为: Name:sonny Type:dog Name:John Type:dog Name:Danny Typc:cat Name:John Type:dog 注意:只修改每个“//ERROR ****found ****”下的那一行,不要改动程序中的其他内容。 include<iostream> using namespace sm; enum Pets_type{d09,cat,bird,fish}; class Pets{ private: char *name; Pets_type type; public: Pets(const char *name=”sonny”,Pets_type type=dog); Pets&operator=(const Pets&s); ~Pets; void showeonst;}; Pets::Pets(eonst char$naIne,Pets_type type) //构造函数 { This ->name=new char[strlen(name)+1]; strcpy(this一>name,name); //ERROR *********found********* type=type; }{ Pets::~Pets//析构函数,释放name所指向的字符串 { //ERROR *********found********* name=’/0‘; } Pets&Pets::0perator=(const Pets&s){ if(&s==this)//确保不要向自身赋值 return *this; delete[]name; name=new char[strlen(S.name)+1];//ERROR *********found********* strcpy(this一>nmne,name); type=S.type: return *this;} void Pets::showconst cout<<“Name:”<<name<<”Type:”: Pets mypetl,mypet2(’’John”,dog);
80
150
100
1
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
include<iostream.h>
class vehicle
{
private:
int MaxSpeed;
int Weight;
public:
//*************found************
vehicle(int maxspeed,int weight):——
~vehicle{};
int getMaxSpeed{return MaxSpeed;}
int getWeight{retum Weight;}
};
//****************found************
class bicycle:——public vehicle
{
private:
int Height;
public:
bicycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),Height(height){}
int getHeight{retum Height;};
};
//*******************found**************
class motorcar:——public vehicle
{
private:
int SeatNum;
public:
motorcar(int maxspeed。int weight,int seatnum):vehicle(maxspeed,weight),SeatNum(seatnum){}
int getSeatNum{return SeatNum;};
};
//*****************found***************
class motorcycle:——
{
public:
motorcycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),bicycle(maxspeed,weight,
height),motorcar(maxspeed,weight,1){}
};
void main
{
motorcycle a(80,150,100);
cout<<a.getMaxSpeed<<endl;
cout<<a.getWeight<<endl;
cout<<a.getHeight<<endl;
cout<<a.getSeatNum<<endl;
}
class doc { private: char*sir;//文本字符串首地址 int length;//文本字符个数 public: //构造函数,读取文件内容,用于初始化新对象,filename是文件名字符串首地址 doc(char*filename); void reverse;//将字符序列反转 一doc; void writeToFile(char*filename); }; doc::doc(char}filename) { ifstream myFile(filename); int len=1001,tmp; atr=new char[1en]; length=0; while((trap=myFile.get)!=EOF) { str[1ength++]=trap; } str[1ength]=‘\0’; myFile.close; } void doc::reverse{ //将数组atr中的length个字符中的第一个字符与最后一个字符交换,第二个字符与倒数第二个 //字符交换…… //*************333*************
//*************666*************
} doc::~doe { delete[]str; } void doc::writeToFile(char*filename) { Ofstream outFile(filename); outFile<<str; outFile.close; } void main { doc myDoc(”in.dat”); myDoc.reveme; myDoc.writeToFile(”out.dat”); }
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!