填空题使用VC++6.0打开考生文件夹下的源程序文件1.cpp,该程序运行时有错误,请补充程序中的丢失部分,使得程序运行。可以在修改处增加或者删除一条语句。 本程序完成以下功能: (1)获得输入的两个数字d1,d2(d1=6,d2=1)。 (2)输出两个中较大的一个(输出6)。 (3)计算d1/d2如果d2等于0,返回-1(输出结果6)。 (4)输出d1+d2的结果(输出结果7)。 (5)输出d1+1的结果(输出结果7)。 (6)输出d2-1的结果(输出结果0)。 注意:错误的语句在/********error********/的下面。修改该语句即可。其他的语句不能修改。 试题程序: #include<iostream.h> void main() int d1; int d2; int d3; cout<<"please input two number:"<<end1; cin>>d1>>d2; /********error********/ d3=(d1(d2)?d1:d2; cout<<"Max data is:"<<d3<<end1; //计算d1/d2如果d2等于0,返回-1 /********error********/ d3=(d2)?d1/d2:-1; cout<<"d1/d2="<<d3<<end1; /********error********/ d3=(--d1)+(d2++); cout<<"d1+d2="<<d3<<end1; cout<<"d1+1="<<d1<<end1; cout<<"d2-1="<<d2<<end1; return;
填空题下面程序的输出结果为{{U}} 【8】 {{/U}}。
# include <iostream.h>
void main( )
{
int num=0,i=8;
do {
i --;
num++;
} while(--i);
cout << num << endl;
}
填空题定义类对象时自动调用 【9】 为类对象中的数据成员赋初值。
填空题以下程序运行后的输出结果是{{U}} [10] {{/U}}。
#include<iostream.h>
void main(){
char s[]=“123456”,*p;
for(p=s; p<s+2; p++)
cout<<p<<end1;
}
填空题标识虚函数的关键字是______。
填空题若以非成员函数形式,为类Bounce重载“!”运算符,其操作结果为一bool型数据,则该运算符重载函数的原型是______。
填空题以下程序的输出是 【8】 。 #include<iostream> using namespace std; fun(intm) static int n=1; n=m*n; return(n); void main() int i; for(i=1;i<=3;i++) cout<<fun(i);
填空题一个结构占用的空间理论上等于{{U}} 【10】 {{/U}}。
填空题以下程序的执行结果是______。
#include<iostream.h>
class Sample
{
int n;
public:
Sample(){}
Sample(int m){n+m;)
int&operator--(int)
{
n--
return n;
}
void disp () {cout<<"n= "<<n<<end1;}
}
void main ()
{
Sample s (10);
(s--) ++;
s.disp();
}
填空题C++语言提供的“::”运算符的作用是在同名局部变量的作用域中访问{{U}} 【8】 {{/U}}。
填空题二叉树由三个基本单元组成,即左子树,右子树和{{U}} 【4】 {{/U}}。
填空题按“先进先出”原则组织数据的数据结构是{{U}} 【3】 {{/U}}。
填空题下列程序的执行结果为 【15】 。 #include<iostream.h> void main() cout.fill(‘*’); cout.width(10); tout <<"hello"<<end1;
填空题如果类中的一个成员函数的定义实现在类内,则该函数系统自动默认为该类的{{U}} 【9】 {{/U}}函数。
填空题以下程序的执行结果为______。 #include<iostream.h> class A public:A()cout<<“a”; ~A()cout<<“b”;; class B:public A public: B()cout<<“c”;) ~B()cout<<“d”;; void main() B b;
填空题高度为h(h>0)的二叉树最少有 [3] 个结点。
填空题下列程序的运行结果是______。 #include<iostream.h> class A public: virtual void use()cout<<"in A/n";; class B:public A public: virtual void use()cout<<"in B/n";; class C:public B public: virtual void use()cout<<"in C/n";; void main() A *obj; obj=new C; obj—>use(); delete obj;
填空题在下面横线上填上适当的语句,完成程序。
#include<iostream>
using namespace std;
class Base
{
int x;
public:
Base(int 0{x=i;}
~Base(){}
};
class Derived:public Base
{
public:
//完成类Derive构造函数的定义
};
int main()
{
Derived Obj;
return 0;
}
填空题数据结构分为逻辑结构与存储结构,线性链表属于 。
填空题类中包含了一个静态成员函数,则main函数中和P. f1 (P); 语句具有同样功能的语句为{{U}} 【11】 {{/U}}。
#include <iostream. h>
class M
{
public,
M(int a) { A=a; B+=a;
static void f1(M m)
private:
int A;
static int B:
}
void M: :f1(M m)
{
cout<<"A="<<m. A<<endl;
cout<<"B="<<m. B<<endl;
}
int M: :B=10,
void main( )
{
M P(5);
P. f1(P);
}
