问题 填空题

[程序]

#include

#include

class B{

public:

B(char *s){name=new char[strlen(s)+1];strcpy(name,s);}

virtual void print(){cout<<"姓名;"<

protected:

char *name;

};

class P1:public B{

public:

P1(char *s,float g):B(s){x=g;}

void print(int i)

{ cout<<"姓名:"<年薪:"<万元。 \n";}

private:

float x;

};

class P2:public B{

public:

P2(char *s,int n):B(s){ num=n;}

void print(){cout<<"姓名;"<月工资:"<元。\n";}

private:

int num;

};

void main(void)

{

B *p;

B x("张明");

P1 y("王虎",4.2);

P2 z("李建国",5000);

p=&x;p->print();

p=&y;p->print();

y.print(1);

p=&z;p->print();

}

执行以上程序后输出的第二行是() ,第四行是()。

答案

参考答案:姓名:王虎;姓名:李建国,月工资:E000元。

多项选择题
单项选择题