有如下程序:#includeiostreamusing 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(Publicationp){coutP.getType()“:”P.getName()endl;}int main(){Book book(”精彩人生”);showPublication(book);return 0;}运行时的输出结果是A.未知类型:未知名称B.未知类型:精彩人生C.书:未知名称D.书:精彩人生

有如下程序:

#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.书:精彩人生


相关考题:

( 32 )有如下程序#includeiostreamusing 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){coutp.getType()":"p.getName()endl;}int main(){Book book(" 精彩人生 ");showPublication(book);return 0;}运行时的输出结果是A )未知类型:未知名称B )未知类型:精彩人生C )书:未知名称D )书:精彩人生

若有如下程序段: include using namespace std; int main() {char*p="abcdefgh",*r;l 若有如下程序段:include <iostream>using namespace std;int main(){char *p="abcdefgh",*r;long *q;q=(long *)p;q++;r=(char *)q;cout<<r<<end1;return 0;}该程序的输出结果是______。

有如下程序:includeusing namespace std;class Publication{//出版物类char name[30] 有如下程序: #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.书:精彩人生

有如下程序: #includeiostream usingnamespacestd; classPublication{//出版物类 charname[30]; public: Publication(char*name=”未知名称”){ ~strcpy(this一name,name); } constchar*getName( )const{returnname;} virtualconstchar*getType( )const{return”未知类型”;} }; classBook:publicPublication{//书类public: Book(char*name):Publication(name){} virtualconstchar*getType( )const{return"书";} }; voidshowPublication(Publicationp){ coutp.getType( )":"p.getName( ) endl; } intmain( ){ Bookbook(”精彩人生”); showPublication(book); return0; } 运行时的输出结果是( )。A.未知类型:未知名称B.未知类型:精彩人生C.书:未知名称D.书:精彩人生

阅读下列说明和C++代码,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。【说明】以下C++代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分类及其关系如图6-1所示。【C++代码】#include?#include?using?namespace?std;class?DrawCircle?{??????//绘制圆形,抽象类? ? ? public: (1);//定义参数为?int?radius,?int?x,?inty? ?virtual~DrawCircle()?{?}};class?RedCircle:public?DrawCircle?{????//绘制红色圆形? ? ? ? public: void?drawCircle(intradius,?int?x,?int?y)?{cout??drawCircle?=?drawCircle;? }? ?virtual~shape()?{?}? public:? ?virtual?void?draw()?=?0;};class?Circle:public?Shape?{????//圆形? ? private:? ? ?int?x,y,radius;? ? public:? Circle(int?x,inty,int?radius,DrawCircle?*drawCircle)? (3)? {? this->x?=?x;? ?this->y?=?y;? ? this->radius?=?radius; }? ? ? public:? void?draw(){? drawCircle?-> (4); }};int?main(){Shape?*redCirclenew?Circle(100,100,10,????(5)????);//绘制红色圆形? Shape?*greenCircle=new?Circle(100,100,10, (6)??);//绘制绿色圆形redCircle >draw();? ?greenCircle?->draw();? ?return?0;}

10、vector对象中可以保存的数据的类型包括A.intB.char*C.std::stringD.std::array<int,10>

vector对象中可以保存的数据的类型包括A.intB.char*C.std::stringD.std::array<int,10>

下列vector对象初始化语句正确的有A.std::vector<int> v {2, 3, 12.0};B.//C++17 std::vector v {2, 3, 12};C.std::vector<char> v {"Hello"};D.std::vector<std::string> sv{"Hello", "World"};

8、如下代码的运行结果是__________。str1='abcd' print(type(str1[0]))A.<class 'char'>B.<class 'int'>C.<class 'float'>D.<class 'str'>