写出执行完下列代码段之后指定变量的值: boolx=true,y=false,z=false; x=x&&y||z; y=x||
写出执行完下列代码段之后指定变量的值:
bool x=true ,y=false,z=false;
x=x&&y||z;
y=x||y&&z;
z=!(x!=y)||(y==z);
则x=false,y=【 】,z=【 】。
写出执行完下列代码段之后指定变量的值:
bool x=true ,y=false,z=false;
x=x&&y||z;
y=x||y&&z;
z=!(x!=y)||(y==z);
则x=false,y=【 】,z=【 】。
第2题
下列程序的执行结果为【 】。
inciude<iostream, h>
int f(int i) { return + +i; }
int g(int &i){return ++i; }
void main()
{ int a, b;
a=b=0;
a+ =f(g(A) );
b+=f(f(B) );
cout<<%= "<<a<<", b="<<(b<<end1;
}
第3题
下列程序不能通过编译,应该在划线部分填写的语句是【 】。
include<iostream. h>
include<stdlib. h>
double Fune(int a, int b, char ch)
{
double x;
switch(ch)
{
case '+':
x=double(a) +b;
break;
case '--':
x= double(a) --b;
break;
case '/':
x=double(a) * b;
break;
case '/':
if(B) x=double(a) /b;
else
exit(1)
break
default:
exit(1);
}
______
}
void main()
{
cout<<Func(32 , 6 ,'--')<< ",";
cout<<Func(32, 6 ,'*') <<",";
cout<<Func(32, 6 ,'/') <<end1;
}
第4题
请将每一个空的正确答案写在答题卡【 】~【 】序号的横线上。答在试卷上不得分。
某二叉树有5个度为2的结点以及3个度为1的结点,则该二叉树中共有【 】个结点。
第7题
下列程序中需要清理动态分配的数组,划线处应有的语句是_______。
include<iostream.h>
class person
{
int age,tall;
public:
person( ){age=0;tall=40;cout<<"A baby is born."<<endl;}
person(int i){age=i;tall=40;cout<<"A old person."<<endl;}
person(int i,int j){age=i;tall=j;cout<<"a old person with tall."<<endl;)
~person( ){cout<<"person dead."<<endl;}
void show( )
{
cout<<"age="<<age<<",tall="<<tall<<endl;
}
};
void main( )
{
person*ptr;
ptr=new person[3];
ptr[0]=person( );
ptr[1]=person(18);
ptr[2]=person(20,120);
for(int i=0;i<3;i++)
ptr[i].show( );
______
}
第8题
下列程序的执行结果是______。
include<iostream.h>
class Student
{
public:
Student(int xx){x=xx;}
virtual float calcTuition( );
protected:
int x;
};
float Studertt::calcTuition( )
{
return float(x*x);
}
class GraduateStudent:public Student
{
public:
GraduateStudent(int xx):Student(xx){}
float calcTuition( );
};
float Graduatestudent::calcTuition( )
{
return float(x*2);
}
void main( )
{
Student s(20);
GraduateStudent gs(30);
cout<<s.calcTuition( )<<" "<<gs.calcTuition( )<<endl;
//计算学生s和研究生gs的学费
}
第9题
,成员函数show用于输出两个数据成员的数值。
include<iostream>
using namespace std;
【 】
T1 i;
T2 j;
public:
dataClass(T1 a, T2 b){i=a;j=b;}
void show(){cout<<i<<","<<j<<'\n';}
};
int main() {
dataClass<int. double>ob1(10,0.23)
dataCllass<char,char *>ob2('X',"my data");
ob1.show();
ob2.show();
return 0;
}
请将程序补充完整,使程序在运行时输出:
10,0.23
X,my data
第10题
有如下程序:
include<iostream>
using namespace std
class Base{
int b;
public:
Base(int i) {b=i;}
Void disp ( ) {cout<<"Base:b="<<b<<''; }
};
class Base1:virtual public Base{
public:
Base1(int i):Base(i){}
};
class Base2:virtual public Base{
public:
Base2(int i):Base(i){}
};
class Derived:public Basepublic Base1{
int d;
public:
Derived(int i ,int j):Base1(j),Base2(j),【 】
{ d=i; }
void disp() {cout<<"Derived:d="<<d<<' ';}
};
int main()
Derived objD(1,2);objD. disp()
objD. Base::disp();
objD. Base1::disp()
objD. Base2::disp();
return 0;
}
请将程序补充完整,使程序在运行时输出:
Derivd:d=1 Base:b=2 Base:b=2 Base:b=2
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!