几道关于C++的程序填空题 哪位高手能帮忙解答一下啊
4.在下面程序横线处填上适当的内容,使该程序输出结果为:CreatingBendofBendofA#include<iostream.h>classA{public:A(...
4.在下面程序横线处填上适当的内容,使该程序输出结果为:
Creating B
end of B
end of A
#include<iostream.h>
class A
{
public:
A(){}
______ {cout<<"end of A"<<endl;}
};
class B:public A
{
public:
B(){____________}
~B(){cout<<"end of B"<<endl;}
};
void main()
{
B b;
}
5.在下面程序横线处填上适当的内容,完成该程序。
class base{
protected:
int a;
public:
base () {a=0;}
base (int i) {a=i;}
base (base&b) {a=b.a;}
};
class derived: public base {
private:
int d;
public:
derived () {d=0;}
derived (int i, int j) :______ {d=j;}
derived (derived&b):__ base(b.a)__ {d=b.d;}
};
6.在下面程序的底画线处填上适当的字句,使该程序执行结果为100。
# include <iostream.h>
class base{int X;
public:
void init(int initX){X=initX; }
int Getnum() {return X+7; }
};
void main()
{_______
________
cout<<test.Getnum();
}
7.在下面程序的横线处填上适当字句,使该程序完成。
#include <iostream.h>
class A{
public:
void f(int i){cout<<i<<endl;}
void g(){cout<<"g\n";}
};
class B: _____ A{
public:
void h(){cout<<"h\n";}
};
void main()
{ B d1;
d1.f(6);
_____.h();
}
8.在下面程序的横线处填上适当字句,使该程序完成。
#include <iostream.h>
class base{
public:
_________func( ){return 0;}
};
class derived:public base{
public:
int a,b,c;
_________ setValue(int x,int y,int z){a=x;b=y;c=z;}
int func( ){return(a+b)*c;}
};
void main(){
base b;
derived d;
cout<<b.func( )<<",";
d.setValue(13,15,17);
cout<<d.func( )<<",";
base& pb=d;
cout<<pb.func( )<<endl;
} 展开
Creating B
end of B
end of A
#include<iostream.h>
class A
{
public:
A(){}
______ {cout<<"end of A"<<endl;}
};
class B:public A
{
public:
B(){____________}
~B(){cout<<"end of B"<<endl;}
};
void main()
{
B b;
}
5.在下面程序横线处填上适当的内容,完成该程序。
class base{
protected:
int a;
public:
base () {a=0;}
base (int i) {a=i;}
base (base&b) {a=b.a;}
};
class derived: public base {
private:
int d;
public:
derived () {d=0;}
derived (int i, int j) :______ {d=j;}
derived (derived&b):__ base(b.a)__ {d=b.d;}
};
6.在下面程序的底画线处填上适当的字句,使该程序执行结果为100。
# include <iostream.h>
class base{int X;
public:
void init(int initX){X=initX; }
int Getnum() {return X+7; }
};
void main()
{_______
________
cout<<test.Getnum();
}
7.在下面程序的横线处填上适当字句,使该程序完成。
#include <iostream.h>
class A{
public:
void f(int i){cout<<i<<endl;}
void g(){cout<<"g\n";}
};
class B: _____ A{
public:
void h(){cout<<"h\n";}
};
void main()
{ B d1;
d1.f(6);
_____.h();
}
8.在下面程序的横线处填上适当字句,使该程序完成。
#include <iostream.h>
class base{
public:
_________func( ){return 0;}
};
class derived:public base{
public:
int a,b,c;
_________ setValue(int x,int y,int z){a=x;b=y;c=z;}
int func( ){return(a+b)*c;}
};
void main(){
base b;
derived d;
cout<<b.func( )<<",";
d.setValue(13,15,17);
cout<<d.func( )<<",";
base& pb=d;
cout<<pb.func( )<<endl;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询