请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehiele类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将Vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:801501001注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。includeiostream.hclass 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);couta.getMaxSpeedendl;couta.getWeightendl;couta.getHeightendl;couta.getSeatNumendl;}

请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehiele类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将Vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:

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;

}


相关考题:

请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,此工程包含有一个源程序文件proj2.cpp,其中定义了Stack类和ArrayStack类。 Stack是一个用于表示数据结构“栈”的类,栈中的元素是字符型数据。Stack为抽象类,它只定义了栈的用户接口,如下所示: 公有成员函数 功能 push 入栈:在栈顶位置添加一个元素 pop 退栈:取出并返回栈顶元素 ArrayStack是Stack的派生类,它实现了Stack定义的接口。ArrayStack内部使用动态分配的字符数组作为栈元素的存储空间。数据成员maxSize表示的是栈的最大容量,top用于记录栈顶的位置。成员函数push和pop分别实现具体的入栈和退栈操作。 请在程序中的横线处填写适当的代码,然后删除横线,以实现上述功能。此程序的正确输出结果应为: a,b,C C,b,a 注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“//****料found****”。 //proj2.cpp includeiostream using namespacc std; class Stack{ public: virtual void push(char C)=0; virtual char pop=0; };class ArrayStack:public Stack{ char*P; int maxSizc; int top; public: ArravStack(int s) { top=0; maxSize=s: //*********found********* P=______; } ~ArrayStack { //*********found********* _______; } void push(char c) } if(top==maxSize){ cerr”Overflow! \n”: return; } //*********found********* _______; top++: } char pop { if(top==0){ cerr”Underflow!、n”; return‘\0’; } Top--; //*********found********* ______; } }; void f(StacksRef) { char ch[]={‘a’,‘b’,‘c’}; coutch[0]”,”ch[1]”,”ch[2]endl; sRef.push(oh[0]);sRef.push(ch[1]);sRef.push(ch[2]); coutsRef.poP”,”; coutsRef.poP”,”; coutsRef.poPendl; } int main { ArrayStack as(10); f(as): 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或使用【答题】菜单打开考生文件夹proj2下的工程proj2。此工程中包含一个源程序文件main.cpp,其中有“房间”类Room及其派生出的“办公室”类0ffice的定义,还有主函数main的定义。请在程序中“//****found****”下的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 办公室房间号:308 办公室长度:5.6 办公室宽度:4.8 办公室面积:26.88 办公室所属部门:会计科 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“///料料found??料”。 includeisotream using namespaee std; class Room{ //“房间”类 int room_n0;//房间号 double length;//房间长度(m) double width;//房间宽度(n1) public: Room(int the—room—n0,double the~length,double the—width):loom—no(the—room—no),length(the— length),width(the—width){} int theRoomNoeonst{return iDonl—n0;} //返回房间号 double theLengthconst{return length;}//返回房间长度 double theWidthconst{return width;}//返回房间宽度 //**********found********** double theAreaconst{_______________}//返回房间面积(矩形面积) }; class Office:public Room{//“办公室”类 char*depart;//所属部门 public: Office(int the_room_n0,double the_length,double the_width,eonst char木the_depart) //**********found********** :_______________{ depart=new char[strlen(the depart)+1]; //**********found********** strcpy(_______________); } ~Office{delete[]depart;} const char*theDepartmentconst{return depart;}//返回所属部门 }; int main{ //**********found********** Office_______________; cout”办公室房间号:”au_office.theRoomNoendl ”办公室长度:”an office.theLengthendl ”办公室宽度:”an 0ffice.theWidthendl ”办公室面积:”an office.theAreaendl ”办公室所属部门:”all—office.theDepartmentendl; 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打开考生文件夹下的工程prog3,其中声明了ValArray类,该类在内部维护一个动态分配的整型数组。ValArray类的复制构造函数应实现对象的深层复制。请编写ValArray类的复制构造函数。在main函数中给出了一组测试数据,此种情况下程序的输出应该是: ValArray vl={1,2,3,4,5} ValArray v2={1,2,3,4,5} 要求: 补充编制的内容写在“//*********333*********”与“//*********666*********”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件out.dat中。输出函数write To File已经编译为boj文件,并且在本程序中调用。 //ValArray.h includeiostream using namespace std; class ValArray{ int *v: int size; public: ValArray(const int * P,int n):size(n) { v=new int[size]; for(int i=0;isize;i++) v[i]=P[i];

使用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或使用【答题】菜单打开考生文件夹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或使用【答题】菜单打开考生文件夹projl下的工程projl。程序中位于每个“//ERROR****found料****之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: Name:Smith Age:21 ID:99999 CourseNum:12 Record:970 注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。 includeiostream using 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 showconst{ cout”Name:”Name”Age:”Age”ID:”ID ”CourseNum:”CourseNum”Record:”Recordendl; } }; //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; }