请使用VC6或使用【答题】菜单打开考生文件夹pr092下的工程pros2。此工程中包含一个程序文件main.cpp,其中有“部门”类Department和“职工”类Staff的定义,还有主函数main的定义。在主函数中定义了两个“职工”对象,他们属于同一部门。程序展示,当该部门改换办公室后,这两个人的办公室也同时得到改变。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 改换办公室前: 职工号:0789姓名:张三部门:人事处办公室:521 职工号:0513姓名:李四部门:人事处办公室:521 改换办公室后: 职工号:0789姓名:张三部门:人事处办公室:311 职工号:0513姓名:李四部门:人事处办公室:311 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。 includeiostream using namespace std; class Department{ //“部门”类 public: Department(const char*name,const char*office){ strcpy(this一name,nanle); //**********found********** } const char*getNameconst{return name;}//返回部门名称 //**********found********** const char*getOfficeconst{________} //返回办公室房号 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,Departmentmy_dept):——{ strcpy(this一staff id,my_id); strcpy(this一name,my_name); } const char*getlDconst{return staff_id;} const char*getNameconsl{return name;} Department getDepartmentconst{return dept;} char staff=id[10];//职工号 char name[20];//姓名 Departmentdept;//所在部门 }; void showStaff(Staffstaff){ cout”职工号:”staff.getID””; cout”姓名:”staff.getName" "; cout”部门:”staff.getDepartment.getName" "; cout”办公室:”staff.getDepartment.getOfficeendl; } int main{ Department dept(”人事处”,”521”); Staff Zhang(”0789”,”张三”,dept),Li(”0513”,”李四”,dept); cout”改换办公室前:”endl; showStaff(Zhang); showStaff(Li); //人事处办公室由521搬到311 //**********found********** ———————————————————————一 cout”改换办公室后:”endl; showStaff(Zhang); showStaff(Li); return 0; }

请使用VC6或使用【答题】菜单打开考生文件夹pr092下的工程pros2。此工程中包含一个程序文件main.cpp,其中有“部门”类Department和“职工”类Staff的定义,还有主函数main的定义。在主函数中定义了两个“职工”对象,他们属于同一部门。程序展示,当该部门改换办公室后,这两个人的办公室也同时得到改变。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 改换办公室前: 职工号:0789姓名:张三部门:人事处办公室:521 职工号:0513姓名:李四部门:人事处办公室:521 改换办公室后: 职工号:0789姓名:张三部门:人事处办公室:311 职工号:0513姓名:李四部门:人事处办公室:311 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。 include<iostream> using namespace std; class Department{ //“部门”类 public: Department(const char*name,const char*office){ strcpy(this一>name,nanle); //**********found********** } const char*getNameconst{return name;}//返回部门名称 //**********found********** const char*getOfficeconst{________} //返回办公室房号 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*getlDconst{return staff_id;} const char*getNameconsl{return name;} Department getDepartmentconst{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; } int main{ Department dept(”人事处”,”521”); Staff Zhang(”0789”,”张三”,dept),Li(”0513”,”李四”,dept); cout<<”改换办公室前:”<<endl; showStaff(Zhang); showStaff(Li); //人事处办公室由521搬到311 //**********found********** ———————————————————————一 cout<<”改换办公室后:”<<endl; showStaff(Zhang); showStaff(Li); return 0; }


相关考题:

请使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl,此工程中含有一个源程碍文件 projl.epp。其中位于每个注释“//ERROR ****found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: ConstruCtor Called. The value is 10 Copy ConstruCtor Called. The value is 10 DestruCtor Called. DestruCtor Called. 注意:只修改注释“//ERROR ****found****”的下一行语句,不要改动程序中的其他内容。 //pwjl.Cpp inCludeiostream ’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.”endl; } void Print {Cout”The value is” valueendl;} //ERROR**********found********* void-MyClass {Cout”DestruCtor Called.”endl;} private: int value; }; int main { MyChas objl owl.Print; MyClmss obj2(owl); obj2.Print; retum 0;

请使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl,该工程含有一个源程序文件pn,jl.cpp。其中位于每个注释“//ERROR 木}}水found}}水木”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: The value is 10 注意:只修改注释“//ERROR **** found****”的下一行语句,不要改动程序中的其他内容。 //pmjl.cpp includeiostream using namespace std; class MyClass{ int value; public: //ERROR********found********* void MyClass(int val):value(val){} int GetValueconst{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.valueendl: return 0; }

请使用VC6或使用【答题】菜单打开考生文件夹progl下的工程progl,该工程中包含程序文件main. cpp,其中有Salary(“工资”)类和主函数main的定义。程序中位于每个“//ERROR ****found****”之后的一行语句行有错误,请加以改正。改正后程序的输出结果应为: 应发合计:3500应扣合计:67.5实发工资:3432.5 注意:只修改每个“//ERROR ****found****”下的那一行,不要改动程序中的其他内容。 includeiostream using 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 getGmssPayconst{retum base+bonus;}//返回应发项合计 double getNetPayconst}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::getNetPayendl; return 0; }

使用VC6打开考生文件夹下的工程test29_1,此工程包含一个源程序文件test29_1.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果为:A:no parametersB:int parameterA:no parametersB:int parameterC:int parameter源程序文件test29_1.cpp清单如下;include <iostream.h>class A{/***************** found *****************/private:A(){ cout<<"A:no parameters\n";}A(int a) {cout<<"A: int parameter\n";}};class B:public A{public:B(int a){cout<<"B:int Parameter\n";}};/***************** found *****************/class C:public B,public A{public:/***************** found *****************/C(int a) ::B(a) {cout<<"C: int parameter\n"; )};void main ( ){B b(1);C c(2);}

使用VC6打开考生文件夹下的工程RevProj3。此工程包含一个源程序文件 RevMain3.cpp。阅读文件中的程序代码,找出程序中的错误,并改正。源程序文件RevMain3.cpp清单如下://RevMain3.cppinclude<iostream>using namespace std;class MyClass{public:/* * * * * * * * *found * * * * * * + * * */void MyClass(int a){ value=a;}int Max(int x,int y){if(x>y)return x>y?x:y;elsereturn y>value?y:value;}/* * * * * * * * *found * * * * * * * * * */~MyClass(int a){value=a;}private:int value;};int main(){MyClass my(10);cout<<my.Max(20,30)<<end1;return 0;}

使用VC6打开考生文件夹下的工程proj2。此工程包含一个源程序文件main2.cpp,但该程序运行有问题。请改正main函数中的错误。源程序文件main2.cpp清单如下://main2.cppinclude <iostream>using namespace std;class MyClass{public:MyClass(int m){member=m;}~MyClass() {}int GetMember(){return member;}private:int member;};MyClass MakeObject(int m){MyClass *pMyClass=new MyClass(m);return *pMyClass;}int main ( ){int x=7;/************found**************/MyClass *myObj=MakeObject(x);/*************found*************/cout<<"My object has member"<<myObj.GetMember()<<end1;return 0;}

使用VC6打开考生文件夹下的工程test34_1,此工程包含一个源程序文件test34_1.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果为:David 3123 1000源程序文件test34_1.cpp清单如下:include <iostream.h>include <string.h>class person{public:char name[20];unsigned long id;float salary;void print(){cout<<name<<' '<<id<<' '<<salary<</***************** found *****************/}void main( ){person p;person *ptr;/***************** found *****************/ptr=p;/***************** found *****************/strcpy("David",ptr->name);ptr->id=3123;ptr->salary=1000;ptr->print();}

使用VC6打开考生文件夹下的工程test21_1,此工程包含一个源程序文件test21_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:The grade is 3源程序文件test21_1.cpp清单如下:include<iostream.h>class student{private:int grade;public:/**************** found*******************/student(int thegra):(thegra){}~student(){}int get_grade(){return grade;}};void main(){int thegra=3;/**************** found*******************/student point=new student(thegra);/**************** found*******************/cout<<"The grade is"<<point.get_grade()<<endl;delete point;}

请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件 main.cpp,其中有类CPolygon(“多边形”)、CRectangle(“矩形”)、CTriangle(“三角形”)的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。该程序的正确输出结果应为: 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。 includelostream {tout——endl;} class CRectangle:public CPolygon{ CReangle(int w,int h):width(w),height(h){} int area(void){return(width *height);} class CTriangle:public CPolygon{ int length;//三角形一边长 int height;//该边上的高 public: CTriangle(int l,int h):length(1),height(h){} //*********found********* int area(void){return(——)/2;} }; int main{ CRectangle rect(4,5); CTriangle trgl(4,5); //*********found********* ______ *ppolyl,* ppoly2; ppolyl=rect; ppoly2=trgl; ppolyl-printarea; ppoly2-printarea; retun 0;

使用VC6打开考生文件夹下的工程test15_1,此工程包含一个源程序文件test15_1.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果如下:My object has member 7源程序文件test15_1.cpp清单如下:include<iostream.h>class MyClass{public:MyClass(int mem){member=mem;}~MyClass(){}int GetAge()const{ return member;}private:int member;};/*****+********+** found *************/void main(){int mem=7;/*************** found ***************/MyClass myObj=MakeObject(mem);cout<<"My object has member"<<myObj->GetAge()<<endl;/***************** found ****************/delete;}MyClass *MakeObject(int mem){MyClass *pMyClass=new MyClass(mem);return pMyClass;}