c语言郑秋生答案对象,C 程序设计教程--面向对象分册(郑秋生)答案.doc

第1章 类和对象

一、 选择题

1.C 2.B 3.C 4.A 5.C

6.A 7.C 8 C 9A 10 C

二、阅读题

1.x=2,y=3

2.x=2,y=3

x!=y

3.

Cstatic::va1=0

cs1.vaI=1

cs2.val=2

cs1.val=4

cs2.vaI=4

四、改错题

#include

#include

class person

{

public:

person(int n,char* nam,char s

{

num=n;

strcpy(name,nam;

sex=s;

cout<

}

~person(

{

cout<

}

void display(

{

cout<

cout<

cout<

}

private:

int num;

char name[10];

char sex;

};

int main(

{

person s1(10010,"'Wang_li",'f';

s1.display( ;

person s2(10011,"Zhang_fun",'m';

s2.display( ;

return 0;

}

五、编程题

5.1

#include

using namespace std;

class CBox

{

public :

CBox(double l=0,double w=0,double h=0;

double area(;

double volume (;

private :

double lengh;

double width;

double high;

};

CBox::CBox(double l,double w,double h

{

lengh=l;

width=w;

high=h;

}

double CBox::area(

{

return 2*(lengh*width+lengh*high+width*high;

}

double CBox::volume (

{

return lengh*width*high;

}

void main(

{

CBox box1(4,5,6;

cout<

cout<

}

5.2

#include

using namespace std;

class CPoint

{

public :

CPoint(double a=0,double b=0

{

x=a;

y=b;

}

CPoint(CPoint & p

{

x=p.x;

y=p.y;

}

void print(

{

cout<

}

private :

double x,y;

};

class CLine

{

public:

CLine(double x1=0,double y1=0,double x2=0,double y2=0:p1(x1,y1,p2(x2,y2

{

}

CLine(CPoint x,CPoint y:p1(x,p2(y

{

}

CLine(CLine &lin

{

p1=lin.p1;

p2=lin.p2;

}

void DrawLine(

{

cout<

p1.print(;

cout<

p2.print(;

cout<

}

void Linedel(

{

cout<

}

void move(CPoint &x,CPoint &y

{

cout<

p1=x;

p2=y;

}

private :

CPoint p1,p2;

};

void main(

{

CPoint point1(1,5,point2(5,8,point3(20,30,point4(40,50;

CLine line1(point1,point2;

CLine line2(2,3,8,12;

line1.DrawLine (;

line2.DrawLine (;

line2.move(point3,point4;

line2.DrawLine (;

line2=line1;

line2.DrawLine (;

line1.Linedel (;

}

5.3

#include

using namespace std;

class CComplex

{

public:

CComplex(double, double;

CComplex(CComplex &c; //复数类的拷贝构造函数声明

double GetReal(;

double GetImag(;

void Print(;

privat

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值