清使用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
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 show()eonst;};
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::show()const
cout<<“Name:”<<NAME<
发布于 2022-05-13 21:36:48
登录后免费查看答案
关注者
0
被浏览
19
1 个回答
推荐阅读
-
请使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl。程序中位于每个“//ERROR****found料****之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:Name:Smith Age:21 ID:99999 CourseNum:12Record:970注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。#includeusing namespace std;class Studentlnfo{protected://ERROR********************found****************char Name;int Age;int ID:int CourseNum;float Record;public:Studentlnfo(char*name,int Age,int ID,int coumeNum,float record);//ERROR ********************found********************void~Studentlnfo(){}float AverageRecord(){return Record/CourseNum;}void show()const{cout<<”Name:”<<NAME<<”AGE:”<<AGE<<”ID:”<<ID<<”CourseNum:”<<COURSENUM<<”RECORD:”<<RECORD<}};//ERROR ******************found**************StudentInfo StudentInfo(char*Name,int Age,int ID,int CourseNum,float Record){Name=name;Age=age;this一>ID=ID:CourseNum=courseNum:Record=record;}int main(){Studentlnfo st(’’Smith”,21,99999,12,970);st.show();return 0;}
2022-05-13 关注 0 浏览15 1答案
-
请使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl,其中有枚举DOGCOLOR、狗类Dog和主函数main的定义。程序中位于每个“//ERROR ****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:There is a white dog named Hoh0. There is a blaCk dog named Haha. There is a motley dog named Hihi. 注意:只修改每个//ERROR****found****女料下的那一行,不要改动程序中的其他内容。#inClude using namespaCe std; //狗的颜色:黑、白、黄、褐、花、其他enum DOGCOLOR{BLACK,WHITE,YELLOW,BROWN,PIEBALD,OTHER}; Class Dog{//狗类DOGCOLOR Color; Char name[20]; statiC int Count; publiC:Dog(Char nalTle[],DOGCOLOR Color){ strCpy(this一>name,name);//ERROR**********found**********、strCpy(this一>Color,Color);} 1 DOGCOLOR getColor()Const{retum Color;}//ERROR**********found**********Const Char * 9etName()Const{return*finin9;} Const Char * 9etColorString()Const{switCh(Color){Case BLACK:return”blaCk“; Case WHITE:return”white”:Case YELLOW:return’"yellow”: Case BROWN:return”brown”; ease PIEBALD:return”piebald”:}return”motley”;}void show()Const{ . Cout<<”There is a”<<GETCOLORSTRING()<} }; int main(){//ERROR**********found**********Dog dogl(”Hoh0”,WHITE),dog2(”Haha”,BLACK);d0g3(”Hihi”,0THER); d091.show();dos2.show(); dos3.show(); return 0;}
2022-05-13 关注 0 浏览14 1答案
-
有如下程序:#includeusingnamespacestd;className{charname[20];public:Name( ){strcpy(name,"");cout<<'?';}Name(char*fname){strcpy(name,fname);cout<<'?';}};intmain( ){Namenames[3]={Name(”张三”),Name(”李四”));return0;}运行此程序输出符号?的个数是( )。
2022-05-13 关注 0 浏览33 1答案
-
有如下程序:#includeusingnamespacestd;classPublication{//出版物类charname[30];public:Publication(char*name=”未知名称”){~strcpy(this一>name,name);}constchar*getName()const{returnname;}virtualconstchar*getType()const{return”未知类型”;}};classBook:publicPublication{//书类public:Book(char*name):Publication(name){}virtualconstchar*getType()const{return"书";}};voidshowPublication(Publication&p){cout<<<":"<<<endl;}intmain(){Bookbook(”精彩人生”);showPublication(book);return0;}运行时的输出结果是()。
2022-05-13 关注 0 浏览22 1答案
-
有以下程序 # include struct STU { char name[10]; int num; }; void f(char *name, int num) { struct STU s[2]={{"SunDan",20044},{"Penghua",20045}}; num = s[0].num; strcpy(name, s[0].name); } main() { struct STU s[2]={{"YangSan",20041},{"LiSiGuo",20042}},*p; p=&s[1]; f(p->name, p->num); printf("%s %d\n", p->name, p->num); }程序运行后的输出结果是( )。
2022-05-11 关注 0 浏览22 1答案
-
请使用VC6或使用【答题】菜单打开考生文件夹pr092下的工程pros2。此工程中包含一个程序文件main.cpp,其中有“部门”类Department和“职工”类Staff的定义,还有主函数main的定义。在主函数中定义了两个“职工”对象,他们属于同一部门。程序展示,当该部门改换办公室后,这两个人的办公室也同时得到改变。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:改换办公室前:职工号:0789姓名:张三部门:人事处办公室:521职工号:0513姓名:李四部门:人事处办公室:521改换办公室后:职工号:0789姓名:张三部门:人事处办公室:311职工号:0513姓名:李四部门:人事处办公室:311注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。#includeusing namespace std;class Department{ //“部门”类public:Department(const char*name,const char*office){strcpy(this一>name,nanle);//**********found**********}const char*getName()const{return name;}//返回部门名称//**********found**********const char*getOffice()const{________} //返回办公室房号void changeOfficeTo(const char*office){ //改换为指定房号的另一个办公室strcpy(this一>office,office);}private:char name[20];//部门名称char office[20];//部门所在办公室房号};class staff{//“职工”类public://**********found**********Staff(const char*my—id,const char木my_name,Department&my_dept):——{strcpy(this一>staff id,my_id);strcpy(this一>name,my_name);}const char*getlD()const{return staff_id;}const char*getName()consl{return name;}Department getDepartment()const{return dept;} char staff=id[10];//职工号char name[20];//姓名Department&dept;//所在部门}; void showStaff(Staff&staff){cout<<”职工号:”<<STAFF.GETID()<cout<<”姓名:”<<STAFF.GETNAME()<<"cout<<”部门:”<<STAFF.GETDEPARTMENT().GETNAME()<<"cout<<”办公室:”<<STAFF.GETDEPARTMENT().GETOFFICE()<<ENDL;&NBSP;&NBSP;&NBSP; }int main(){Department dept(”人事处”,”521”);Staff Zhang(”0789”,”张三”,dept),Li(”0513”,”李四”,dept);cout<<”改换办公室前:”<showStaff(Zhang); showStaff(Li);//人事处办公室由521搬到311 //**********found********** ———————————————————————一cout<<”改换办公室后:”<showStaff(Zhang); showStaff(Li);return 0; }
2022-05-13 关注 0 浏览11 1答案
-
请使用VC6或使用【答题】菜单打开考生文件夹progl下的工程progl,该工程中包含程序文件main. cpp,其中有Salary(“工资”)类和主函数main的定义。程序中位于每个“//ERROR ****found****”之后的一行语句行有错误,请加以改正。改正后程序的输出结果应为:应发合计:3500应扣合计:67.5实发工资:3432.5注意:只修改每个“//ERROR ****found****”下的那一行,不要改动程序中的其他内容。#includeusing namespace std; class Salary{public:Salary(const char *id,double the_base,double the bonus,double the_tax) //ERROR **********found**********:the_base(base),the_bonus(bonus),the_tax(tax) {staff_id=new char[strlen(id)+1]; strcpy(staff_id,id);}//ERROR **********found********** ~Salary(){delete * staff_id;}double getGmssPay()const{retum base+bonus;}//返回应发项合计double getNetPay()const}retum getGmssPay()-tax;}//返回实发工资额 private:char * staff id;//职工号 double base;//基本工资 double bonus;//奖金double tax;//代扣个人所得税 };int main(){Salary pay(”888888”,3000.0,500.0,67.50);cout<<”应发合计:”<<PAY.GETGROSSPAY()<<"cout<<”应扣合计:”<<PAY.GETGROSSPAY()一PAY.GETNETPAY()<<””;//ERROR**********found**********cout<<”实发工资:”<<PAY::GETNETPAY()<<ENDL;return 0;}
2022-05-13 关注 0 浏览12 1答案
-
请使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl,此工程中含有一个源程碍文件 projl.epp。其中位于每个注释“//ERROR ****found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:ConstruCtor Called. The value is 10Copy ConstruCtor Called. The value is 10DestruCtor Called. DestruCtor Called. 注意:只修改注释“//ERROR ****found****”的下一行语句,不要改动程序中的其他内容。//pwjl.Cpp#inClude ’using namespaCe std; Class MyClass{publiC://ERROR**********found**********MyClass(int i){value=i;Cout<<”ConstruCtor Called.” <<ENDL;}//ERROR**********found********** MyClass(eonst MyClass P){value = P.value;eout<<”Copy ConstruCtor Called.”<}void Print(){Cout<<”The value is” <<VALUE<<ENDL;}//ERROR**********found********* void-MyClass(){Cout<<”DestruCtor Called.”<<ENDL;}private:int value;}; int main(){ MyChas objlowl.Print();MyClmss obj2(owl); obj2.Print();retum 0;
2022-05-13 关注 0 浏览19 1答案
-
有以程序#include <stdio.h>#include <string.h>typedef struct { char name[9]; char sex; float score[2]; } STU;void f( STU a){ STU b={“Zhao” ,’m’,85.0,90.0} ; int i;strcpy(a.name,b.name);a.sex=b.sex;for(i=0;i<2;i++) a.score[i]=b.score[i];}main(){ STU c={“Qian”,’p’,95.0,92.0};f(c); printf(“%s,%c,%2.0f,%2.0f\n”,c.name,c.sex,c.score[0],c.score[1]);}程序的运行结果是
2022-05-11 关注 0 浏览14 1答案
-
请使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl,该工程含有一个源程序文件pn,jl.cpp。其中位于每个注释“//ERROR 木}}水found}}水木”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:The value is 10注意:只修改注释“//ERROR **** found****”的下一行语句,不要改动程序中的其他内容。//pmjl.cpp#includeusing namespace std;class MyClass{int value;public://ERROR********found*********void MyClass(int val):value(val){}int GetValue()const{return value;}void SetValue(int val);};//ERROR********found********inline void SetValue(int val){value=val;}int main()MyClass obj(O);obj.SetValue(10);//ERROR********found********下列语句功能是输出obj的成员value的值tout<<”The value is”<<OBJ.VALUE<return 0;}
2022-05-13 关注 0 浏览14 1答案