#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:
B.ook(char*name):Publication(name){}
virtual const char*getType()const{return“书”;}
}.
void showPublication(Publication&p){
cout<<P.getType()<<“:”<<P.getName()<<endl;
}
int main(){
B.ook book(”精彩人生”);
showPublication(book);
return 0;
}
运行时的输出结果是
A.未知类型:未知名称
B.未知类型:精彩人生
C.书:未知名称
D.书:精彩人生
[单选题]有如下程序:#include<iostream>using namespace std;class AA{int k:protected:int n;void setK(int k){mis->k=k;}.public:void setN(int n){tllis->n=n;}};class BB:public AA{/*类体略*/};int main(){B.B X;x.n=l: //1x.setN(2); //2x.k=3: ///3X.setK(4); //4ret
[单选题]有如下程序:#include<iostream>using namespace std;class Book{public:B.ook(char*t=””){strcpy(title,t);}private:char title[40];};class Novel:public Book{public:Novel(char *t=””):Book(t){}char*Category()const{return”文学”;)};int main(){B.ook *pb;pb=new No
[单选题]有如下程序:#include<iostream>using namespace std;class Instrument{public:virtual void Display()=0;};class Piano:public Instrument {public:void Display(){/*函数体程序略*/}};int main(){Instrument s;Instrument *p=0;//…;return 0;}下列叙述中正确的是A.语句“Instrument *p=0
[单选题]有如下程序:#include<iostream>using namespace std;class Music{public:void setTitle(char*str){strcpy(title,str);}protected:char type[10];private:char title[20];};class Jazz:public Music{public:void set(char*str){strcpy(type,”Jazz”); //①strcpy(title,st
[单选题]有如下程序:#include<iostream>using namespace std;class AA{public:A.A(){tout<<‘l’;}};class BB:public AA{int k;public:B.B():k(0){cout<<…2;}B.B(int n):k(n){cout<<‘3’;}};int main(){B.B b(4),C;return 0;}A.1312B.132C.32 D、1412
[单选题]有如下程序:#include<iostream>using namespace std;class A{public:A.(int i):r1(i){}void print(){cout<<‘E’<<rl<<‘-’;}void print()const{cout<<‘C’<<rl*rl<<‘-’;}private:int rl:};int main(){A. a1(2); const A a2(4);a1.pri
[单选题]有如下程序:#include<iostream>using namespace std;class C1{public:-Cl()}cout<<1;}};class C2:public C1{public:~c2(){cout<<2;}};int main(){C.2 cb2;C.1*cbl:return 0;{运行时的输出结果是A.121B.21C.211 D、12
[单选题]有如下程序:#include<iostream>using namespace std;class Toy{public:Toy(char*_n){strcpy(name,_n);count++;}~Toy()}count--;}char*GetName(){return name;}static int getCount(){return count;}private:char name[10];static int count;};int Toy::count=O:int mai
[单选题]有如下程序: #include(iostream> using namespace std; Class Test { public: Test() {n+=2;} ~Test() {n-=3;) static int getNum() {return n;} private: static int n; }; int Test::n=1; int main() { Test*p=new Test;A.n=0B.n=1C.n=2D.n=3
[单选题]有如下程序:}}}}include<iostream>using namespace std;class Pair{int m;int n;public:Pair(int i,int J):m(i),n(J){}bool operator>(Pair P)const; //需在类体外给出定义};int main(){Pair pl(3,4),p2(4,3),p3(4,5);C.OUt<<(pl>p2)<<(p2>p1)<<(p2&