2008自考c 试题(附答案) 下载本文

内容发布更新时间 : 2024/6/3 19:25:23星期一 下面是文章的全部内容请认真阅读。

char*title;

char*author;

int numsold;

public:

Book( ){ }

Book(const char*strl,const char*str2,const int num) {

int len=strlen(strl);

title=new char[len+1];

strcpy(title,str1);

len=strlen(str2);

author=new char[len+1];

strcpy(author,str2);

numsold=num; }

void setbook(const char*str1,const char*str2,const int num) {

int len=strlen(str1);

title=new char[len+1];

strcpy(title,str1);

len=strlen(str2);

author=new char[len+1];

strcpy(author,str2);

numsold=num;

}

~Book( ) {

delete title;

delete author;

}

void print(ostream&output) {

output<<″书名:″<

output<<″作者:″<

output<<″月销售量:″<

} .

};

void main( ) {

Book obj1(″数据结构″,″严蔚敏″,200),obj2;

obj1.print(cout);

obj2.setbook(″C++语言程序设计″,″李春葆″,210);

obj2.print(cout);

}

六、程序设计题(本大题共1小题,共10分)

55.在三角形类TRI实现两个函数,功能是输入三个顶点坐标判断是否构成三角形

#include

#include

class point{

private:float x,y;

public:point(float a,float b){x=a;y=b;}

point( ){x=0;y=0;} ,

void set(float a,float b){x=a;y=b;}

float getx( ){return x;}

float gety( ){return y;}

};

class tri{

point x,y,z;

float s1,s2,s3;

public;...settri(....);//用于输入三个顶点坐标

....test(....);//用于判断是否构成三角形

}; 请写出两个函数的过程(如果需要形式参数,请给出形参类型和数量,以及返回值

类型)

答案:

全国2008年10月自学考试C++程序设计试题答案

(供同学们参考,有争议的答案,请留言)

一、选择题

1. A 2. C 3.C 4. A 5. A 6.A 7. C 8.A 9.B 10.C 11.D 12.A 13.B 14.B 15.A 16.B 17.B 18.A 19.B 20.B

二、填空题

21.ofstream myFile(“f:\\\\myText.txt)

22.ios

23. 类

24.virtual

25.front()

26.vector E(20,’t’)

27. 数据成员

28.多态性

29.#include

30.void (A::*pafn) (void)

31.delete [] prt

32.不可访问的 33.7

34. 必要的参数

35. 地址值

36.-1

37. bool

38. 29100

39.Hex:ff

40.endl

三、改错题

41.错误 *p=y;

修改意见:将const int *p=&x 中的const去掉

42.错误:a.f1(1,1)

修改意见:增加一个f1的函数重载:void f1(int I,int j){x=I; y=j;}

43.错误:private:int x=0,y=0;

修改意见:private:int x,y;

44.错误:cout<

修改意见:cout<

45.错误:f a;

改为:f a;

四、完成程序题

46.(1) n (2) point &t

47. (1) const (2) cin<

48. (1)complex & a

(2) complex (r,i);

49.(1)ptr+1 (2) prt->get()

50.(1) float cha(float, float);

(2) cha(a,b)

五、程序分析题

51. s1 和s2的数据成员不相等

s3和s4的数据成员相等

52. 7 5.0