自考C++试题及答案(9套合集)-3-4.

内容发布更新时间 : 2024/4/28 8:47:25星期一 下面是文章的全部内容请认真阅读。

}

void main()

{mystring str(20); mystring*pstr=&str; mystring**ppstr=&pstr;

strcpy(str.pdata,\fun(ppstr, 20); str.show();_______ }

2. 在下面程序横线处填上适当字句,完成类的定义。

class line; class box { private: int color; int upx, upy; int lowx, lowy; public:

friend int same_color(line l, box b); void set_color (int c){color=c;}

void define_box (int x1, int y1, int x2, int y2) {upx=x1;upy=y1;lowx=x2;lowy=y2;} };

class line { private: int color;

int startx, starty; int endx, endy; public:

friend int same_color(line l,box b); void set_color (int c) {color=c;}

void define_line (int x1,int y1,int x2,int y2) {startx=x1;starty=y1;endx=x2;endy=y2;} };

int same_color(line l, box b) {if (l.color==b.color) return 1; return 0; }

3. 下面程序用来求直角三角形斜边长度。

#include #include class Point {private: double x,y;

friend Line;__________ public:

Point(double i=0,double j=0) {x=i;y=j;}

Point(Point &p) {x=p.x;y=p.y;} };

class Line {private: Point p1,p2; public:

Line(Point &xp1,Point &xp2):p1(xp1),p2(xp2)________{} double GetLength(); };

double Line::GetLength() {double dx=p2.x-p1.x; double dy=p2.y-p1.y;

return sqrt(dx*dx+dy*dy); }

void main()

{ Point p1,p2(6,8); Line L1(p1,p2);

cout<

4. 在下面程序的底画线处填上适当的字句,使该程序执行结果为40。

#include class Test { public:

static int x______; Test (int i=0) {x=i+x;} int Getnum()

{return Test::x+7;} };

int Test::x=33_______; void main() {Test test;

cout<

5. 在下列程序的空格处填上适当的字句,使输出为:0,2,10。

#include #include class Magic {double x; public:

Magic(double d=0.00):x(fabs(d)) {}

Magic operator+(Magic &c______) {

return Magic(sqrt(x*x+c.x*c.x)); }

friend ostream& operator<<(ostream & stream,Magic & c) { stream<

void main() {Magic ma;

cout<

五、程序分析题(本大题共2小题,每小题5分,共10分) 1. 运行程序,写出程序执行的结果。

#include void main() {int a,b,c; char ch;

cin>>a>>ch>>b>>c;//从键盘上输入1.5×c×10×20,×表示一个空格 cout<

0

2. 给出下面程序输出结果。

#include class A {public: A()

{cout<<\virtual ~A()

{cout<<\virtual void f()

{cout<<\void g() {f();} };

class B:public A {public: B()

{f();cout<<\~B()

{cout<<\};

class C:public B {public: C()

{cout<<\~C()

{cout<<\void f()

{cout<<\};

void main() {A *a=new C; a->g(); delete a; }

As cons. As f(). Bs cons. Cs cons. Cs f(). Cs des. Bs des. As des.

六、程序设计题(本大题共1小题,共10分) 1. 已知交通工具类定义如下。

要求:(1)实现这个类;(2)定义并实现一个小车类car,是它的公有派生类,小车本身的私有 属性有载人数,小车的函数有init(设置车轮数,重量和载人数),getpassenger(获取载人数 ),print(打印车轮数,重量和载人数)。 class vehicle {protected:

int wheels;//车轮数 float weight;//重量 public:

void init(int wheels,float weight); int get_wheels(); float get_weight(); void print(); };

void vehicle::init(int wheels,float weight) {this->wheels=wheels; this->weight=weight; cout<

int vehicle::get_wheels() {return wheels; }

float vehicle::get_weight() {return weight;}

void vehicle::print()

{cout<<\车轮数:\重量:\

2009年全国自考C++程序设计模拟试卷(四)

一、单项选择题(本大题共20小题,每小题1分,共20分)在每小题列出的四个备选项中 只有一个是符合题目要求的,请将其代码填写在题后的括号内。错选、多选或未选均无 分。

1. 当一个类的某个函数被说明为virtual时,该函数在该类的所有派生类中() A. 都是虚函数

B. 只有被重新说明时才是虚函数

C. 只有被重新说明为virtual时才是虚函数 D. 都不是虚函数

2. 要禁止修改指针p本身,又要禁止修改p所指向的数据,这样的指针应定义为() A. const char *p=“ABCD”; B. char *const p=“ABCD”; C. char const *p=“ABCD”;

D. const char * const p=“ABCD”;

3. 函数调用func((exp1,exp2),(exp3,exp4,exp5))中所含实参的个数为() A. 1 B. 2 C. 4 D. 5

4. 设有函数模板

template Q Sum(Q x,Q y) {return (x)+(y);}

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4 ceshi