题目
(32 )有如下程序
#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 )书:精彩人生
第1题
(32 )有如下程序:
#include<iostream>
Using namespace std;
class A{
public:
virtual void f () {cout+1;}
void g () {cout<<2;}
};
class B:public A{
public:
virtual void f () {cout<<3;}
void g () {ecut<<4;}
};
void show (A &a ) {a.f () ; a.g () ; }
int main () {
B b;
show (b ) ;
return 0;
}
运行时的输出结果是
A ) 12
B ) 34
C ) 14
D ) 32
第2题
A.16
B.32
C.40
D.80
第3题
(32 )有如下程序;
#include<iostream>
using namespace std;
class Base{
public:
void output(){cout<<1;}
virtual void Print(){cout<<'B';}
};
class Derived:public Base{
public:
void output(){cout<<2;}
void Print(){cout<<'D';}
};
int main(){
Base *ptr=new Derived;
ptr->output();
ptr->Print();
delete ptr;
return 0;
}
程序的输出结果是
A ) 1B
B ) 1D
C ) 2B
D ) 2D
第4题
有如下程序 #include<iostream.h> viod main() { int i,sum=0; for(i=1;i<=3;sum++) sum+=i; cout<<sum<<end1; } 该程序的执行结果是 ______。
A.6
B.3
C.死循环
D.0
第5题
A.beijing
B.china
C.welcome
D.tiananmen
第6题
有如下程序:
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int S[]={123,234};
cout<<right<<setfill(‘*’)<<setw(6);
for(int i=0;i<2;i++){cout<<s[i]<<endl;}
retum 0;
}
运行时的输出结果是
A.123
B.***123
C.***123
D.***123 234 234 ***234 234***
第7题
有如下程序 #include<stdio.h> main() { int a[4][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16)); int i,s=0; for(i=0;i<4;i++)s+=a[i][1]; printf("%d\n",s); }程序运行后的输出结果是______。
A.11
B.32
C.13
D.20
第8题
有如下程序: #include<iostream> using namespace std; int main(){ int sum; for(int i=0;i<6;i+=3){ sum=i; for(int j=i;j<6;j++)sum+=j; } cout<<sum<<end1; return 0; } 运行时的输出结果是()。
A.3
B.10
C.12
D.15
第9题
有如下程序: #include<iostream> #include<iomanip> using namespace std; int main(){ int S[ ]={123,234}; cout<<right<<setfill('*')<<setw(6); for(int i=0;i<2;i++){COUt<<s[i]<<endl;} return 0; } 程序的输出结果是
A.123 234
B.***123 234
C.***123 ***234
D.***123 234***
第10题
(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
第11题
有如下程序 #include<iostream.h> #define N2 #define M N+1 #define NUM2*M+1 void main() { int i; for(i=1;i<=NUM;i++) cout<<i;} 该程序中的for循环执行的次数是
A.5
B.6
C.7
D.8
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!