西安石油大学大二(上)C++面向对象程序设计课件各章习题

{ Car myCar;

SportsCar mySportsCar; int c = 5; float d = 5.0; myCar.f(c); mySportsCar.f(c); mySportsCar.f(d); mySportsCar.d();

}

程序阅读和设计题:

9.17 阅读程序,给出运行结果: (1)

#include \class A {

private: int a,b; public:

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

}

void move(int x,int y) { a+=x; b+=y; }

void show() { cout<

};

class B: private A {

private:

29

int x,y;

public:

B(int i,int j,int k,int l):A(i,j) { x=k; y=l;

}

void show() { cout<

void fun() { move(2,4);

}

void f1() { A::show(); }

};

void main() { A a1(10,10); a1.show(); B b1(5,5,6,6); b1.fun(); b1.show(); b1.f1(); }

2)

#include class Point { int x,y; public: Point(int x1=0, int y1=0) :x(x1), y(y1) { cout<<\

}

~Point() {

30

cout<<\

}

};

class Circle { Point center; //圆心位置

int radius; //半径

public: Circle(int cx,int cy, int r):center(cx,cy),radius(r) { cout<<\

}

~Circle() {cout<<\

};

void main() {

Circle c(3,4,5); }

3)

#include #include class Point { int x,y; public: Point(int x1=0, int y1=0) :x(x1), y(y1) { cout<<\

}

~Point() { cout<<\

}

};

class Text {

char text[100]; //文字内容 public:

Text(char * str) { strcpy(text,str); cout<<\ }

~Text() {c

>>展开全文<<
12@gma联系客服:779662525#qq.com(#替换为@)