好文档 - 专业文书写作范文服务资料分享网站

C++期末热身第二部分

天下 分享 时间: 加入收藏 我要投稿 点赞

int main() {

A e(1,2); e.show(); B d(3,4,5,6); d.fun(); d.show(); d.f1(); return 0; }

8以下程序的执行结果是 a=0b=0c=0

a=1b=0c=0 a=1b=3c=0 a=1b=3c=5

#includeviostream>

using namespace std; class A { public:

A(){a=0;b=0;} A(int i){a=i;b=0;} A(int i,int j){a=i;b=j;}

void display(){coutvv\int a; int b; };

class B:public A { public:

B(){c=O;} B(int i):A(i){c=0;} B(int i,int j):A(i,j){c=O;} B(int i,int j,int k):A(i,j){c=k;}

void display\

{display。; coutvv\} private: int c; };

int main() {B b1; B b2(1); B b3(1,3); B b4(1,3,5); b1.display1(); b2.display1(); b3.display1(); b4.display1(); return 0; }

9、以下程序的执行结果是 ____________ 30,30 ________ #includeviostream>

using namespace std; class Point {

int x,y; public:

Point(int vx,int vy){x=vx;y=vy;} Point() {x=0;y=0;}

Point operator+(Point p1) {

Point p; int px=x+p.x;

int py=y+p.y; return Point(px,py); }

Point operator-(Point p1) Point p;

int px=x-p1.x; int py=y-p1.y; return Point(px,py); }

void print() {

coutvvxvv ” ”,vvyvvendl; } };

int main() {

Point p1(10,10),p2(20,20); p1= p1+p2; p1.print(); return 0; }

10、以下程序的执行结果是

base class

_________________________________derive class

derive2 class #includeviostream> using namespace std; class base

{ public: virtual void who() {

coutvv \} };

class derive:public base { public: void who() {

coutvv \derive class\vvendl; } };

class derive2:public base { public:

void who()

{

coutvv \

};

int main() {

base obj1,*p; derive obj2; derive2 obj3; p=&obj1; p->who(); p=&obj2; p->who(); p=&obj3; p->who(); return 0;

f1 function of base f2 function of base f3 function of base f1 function of derive f2 function of base f4 function of derive

#includeusing namespace std; class base {

public: }

11以下程序的执行结果是 virtual void f1() 、

{

cout<<\f1 function of base\<

virtual void f2() {

cout<<\f2 function of base\<

virtual void f3() {

cout<<\f3 function of base\<

virtual void f4() {

cout<<\f3 function of base\<

};

class derive:public base {

void f1()

{

coutvv ”1 function of derive ”vvendl;

C++期末热身第二部分

intmain(){Ae(1,2);e.show();Bd(3,4,5,6);d.fun();d.show();d.f1();return0;}8以下程序的执行结果是a=0b=0c=0a=1b=0c=0a=1b=3c=0a=1b=3c=5#includeviostream>using
推荐度:
点击下载文档文档为doc格式
6iy0s5ehgu6tck19hpxv8jj329nz7x003m1
领取福利

微信扫码领取福利

微信扫码分享