题目
(30 )有如下程序:
#include<iostream>
using namespace std;
class Base{
public:
Base(int x=0){cout<<x;}
};
class Derived:public Base{
public:
Derived(int x=0){cout<<x;}
private:
Base val;
};
int main(){
Derived d(1);
return 0;
}
程序的输出结果是
A ) 0
B ) 1
C ) 01
D ) 001
第1题
A.30
B.15
C.20
D.10
第2题
(30 )有如下程序:
#include<iostream>
using namespace std;
public:
AA(){ cout<<'1'; }
};
class BB: public AA{
int k;
public:
BB():k(0){ cout<<'2'; }
BB(int n):k(n){ cout<<'3';}
}
int main(){
BB b(4), c;
return 0;
}
运行时的输出结果是
A ) 1312
B ) 132
C ) 32
D ) 1412
第3题
(30 ) 有如下程序
#include
using namespace std;
class Base {
protected:
Base(){ cout<<'A'; }
Base(char c){ cout<
};
class Derived: public Base{
public:
Derived(char c ){ cout<
};
int main(){
Derived d1('B');
return 0;
}
执行这个程序屏幕上将显示输出
A ) B
B ) BA
C ) AB
D ) BB
第4题
A.2329
B.2923
C.3292
D.9232
第5题
现有如下程序段,此程序段编译有错误,则程序段的错误出在
#include
main()
{ int a=30,b=40,c=50,d;
d=a >30?b:c;
switch(d){case a:printf("%d,",a);
case b:printf("%d,",b);
case c:printf("%d,",c);
default:printf("#");}}
A.default:printf("#");这个语句
B.d=a>30?b:c;这个语句
C.case a:printf("%d,",a); case b:printf("%d,",b); case c:printf("%d,",c);这三个语句
D.switch(d)这个语句
第6题
现有如下程序段,此程序段编译有错误,则程序段的错误出在 #include<stdio.h> main() { int a=30,b=40,c=50,d; d=a>30? b:c; swish(d) { case a: Printf("%d,",a); case b: printf("%d,",b); case c: printf("%d,",c); default printf("#");}}
A.default:printf("#");这个语句
B.d=a>30? b:c;这个语句
C.case a:printf("%d,",a);case b:printf("%d,",b);case c:printf("%d,",c);这三个语句
D.switch(d)这个语句
第7题
(30 )有如下程序:
#include<iostream>
using namespace std;
class AA{
lilt k;
protected:
int n;
void setK (int k ) { this->k=k;}
public:
void setN (int n ) { this->n=n;}
};
class BB: public }{/* 类体略 */};
int main () {
BB x_ ; //1
x .n=1; //2
x.setN (2 ) ; //3
x.k=3; //4
x .setK (4 ) ;
return 0;
}
在标注号码的四条语句中正确的是
A ) 1
B ) 2
C ) 3
D ) 4
第8题
有如下程序: #include<iostreanl> using namespace std; class MyClass{ public: MyClass(int x):val(x){ } void Set(int x){val=x;} void Print()eonst{eout<<"val="<<val<<'\t';} private: int val; }; int main(){ eonst MyClass objl(10); MyClass obj2(20); objl.Print(); //语句1 obj2.Print(); //语句2 objl.Set(20); //语句3 obj2.Set(30); //语句4 return 0; } 其主函数中错误的语句是
A.语句1
B.语句2
C.语句3
D.语句4
第9题
有如下程序: #include<iostream> using namespace std; class Publication{//出版物类 char name[30]; public: Publication(char*name="未知名称"){strcpy(this->name,name);} const char*getName()const{return name;} //常数据成员 virtual const char*getType()const{return"未知类型";}//虚常数据成员 }; class Book:public Publication{ //书类 public: Book(char*name):Publication(name){ } virtual const char*getType()const{return"书";} //虚常数据成员 }; void showPublication(Publication &p){cout<<p.getType()<<":"<<P.getName()<<endl;} int main(){ Book book("精彩人生"); showPublication(book); return 0; } 程序的输出结果是
A.未知类型:未知名称
B.未知类型:精彩人生
C.书:未知名称
D.书:精彩人生
第10题
有如下程序:
#include<iostream>
using namespace std;
class Publication{//出版物类
char name[30];
public:
Publication(char*name=”未知名称”){
strcpy(this->name,name);
}
const char*getName()const{return name;}
virtual const char*getType()const{return“未知类型”;}
};
class Book:public Publication{//书类
public:
Book(char*name):Publication(name){}
virtual const char*getType()const{return“书”;}
}.
void showPublication(Publication&p){
cout<<P.getType()<<“:”<<P.getName()<<endl;
}
int main(){
Book book(”精彩人生”);
showPublication(book);
return 0;
}
运行时的输出结果是
A.未知类型:未知名称
B.未知类型:精彩人生
C.书:未知名称
D.书:精彩人生
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!