网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

使用VC6打开考生文件夹下的工程MyProj2。此工程包含一个源程序文件 MyMain2.cpp,此程序的运行结果为:

Derive1's Print() Called.

Derive2's Print() called.

其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。

①定义函数Print()为无值型纯虚函数。请在注释“//**1**”之后添加适当的语句。

②建立类Derivel的构造函数,请在注释“//**2**”之后添加适当的语句。

③完成类Derive2成员函数Print()的定义。请在注释“//**3**”之后添加适当的语句。

④定义类Derivel的对象指针d1,类Derive2的对象指针d2。其初始化值分别为1和2。

源程序文件MyMain2.cpp中的程序清单如下:

//MyMain2. cpp

include <iostream>

using namespace std;

class Base

{

public:

Base(int i)

{

b=i;

}

//* * 1 * *

protected:

int b;

};

class Derivel: public Base

{

public:

//* * 2 * *

void print ()

{

cout<<" Derivel's Print() called."<<end1;

}

};

class Derive2 : public Base

{

public:

Derive2(int i) :Base(i) { }

//* * 3 * *

};

void fun (Base *obj)

{

obj->Print ();

}

int main ( )

{

//* * 4 * *

fun (d1);

fun (d2);

return 0;

}


参考答案

更多 “ 使用VC6打开考生文件夹下的工程MyProj2。此工程包含一个源程序文件 MyMain2.cpp,此程序的运行结果为:Derive1's Print() Called.Derive2's Print() called.其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。①定义函数Print()为无值型纯虚函数。请在注释“//**1**”之后添加适当的语句。②建立类Derivel的构造函数,请在注释“//**2**”之后添加适当的语句。③完成类Derive2成员函数Print()的定义。请在注释“//**3**”之后添加适当的语句。④定义类Derivel的对象指针d1,类Derive2的对象指针d2。其初始化值分别为1和2。源程序文件MyMain2.cpp中的程序清单如下://MyMain2. cppinclude <iostream>using namespace std;class Base{public:Base(int i){b=i;}//* * 1 * *protected:int b;};class Derivel: public Base{public://* * 2 * *void print (){cout<<" Derivel's Print() called."<<end1;}};class Derive2 : public Base{public:Derive2(int i) :Base(i) { }//* * 3 * *};void fun (Base *obj){obj->Print ();}int main ( ){//* * 4 * *fun (d1);fun (d2);return 0;} ” 相关考题
考题 使用VC6打开考生文件夹下的工程test28_1,此工程包含一个源程序文件test28_1.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果为:55源程序文件test28_1.cpp清单如下:include <iostream.h>class A{public:/***************** found *****************static int n=1;A(){n++;};~A() (n--;};};/***************** found *****************int n=0;int main() {A a;A b[3];A *c=new A;c=a;/***************** found *****************cout<<c.n<<end1;cout<<A::n<<end1;return 0;}

考题 使用VC6打开老考生文件夹下的工程test5_1,此工程包含一个源程序文件test5_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:x=3 y=5 z=08源程序文件test5_1.cpp清单如下:include<iostream.h>static int x=5;int z=0;int *add(int x,int y){cout<<"X="<<X<<"y="<<y<<" Z="<<z<<endl;z=z+x+y;/********found*********/return z;/********found*********/};void main(){int y=5;int x=3;/*********found********/cout<<(add(X,y))<<endl;}

考题 使用VC6打开考生文件夹下的工程test30_1,此工程包含一个源程序文件test30_1.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果为:Previous=9,Next=11源程序文件test30_1.cpp清单如下:include <iostream.h>/***************** found *****************/void prevnext (int,int ,int);int main ( ){int x=10,y,z;prevnext (x,y,z);cout << "Previous=" << y << ", Next=" << z<<end1;return 0;}/***************** found *****************/void prevnext (int x, int prev, int next){/***************** found *****************/prev=x--;next=++x;}

考题 使用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打开考生文件夹下的工程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打开考生文件夹下的工程test41_1,此工程包含一个源程序文件test41_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为:7源程序文件test41_1.cpp清单如下:include<iostream.h>class myclass{int a, b;public:/***************** found *****************/int sum(myclass x);void set_ab(int i, int j);}:/**************** found ****************/void myclass:set_ab(int i, int j){a=i;b=j;}int sum (myclass x){/***************** found ***************/x.a+x.b;}void main ( ){myclass n;n.set_ab (3, 4);cout <<sum(n)<<endl;}

考题 使用VC6打开考生文件夹下的工程test35_1,此工程包含一个源程序文件test35_1.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果为:40040源程序文件test35_1.cpp清单如下:include <iostream.h>class Student{public:Student(int xx){x=xx;}virtual float calcTuition();/***************** found *****************/private:int x;};float Student::calcTuition(){return float(x'x);}/***************** found *****************/class GraduateStudent::public Student{public:/***************** found *****************/GraduateStudent(int xx) ::Student(xx){}virtual float calcTuition();};float GraduateStudent::calcTuition(){return float(x*2);}void main(){Student s(20);GraduateStudent gs(20);cout<<s.calcTuition()<<end1;cout<<gs.calcTuition()<<end1;}

考题 使用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;}