第一范文网 - 专业文章范例文档资料分享平台

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

来源:用户分享 时间:2025/6/9 17:21:28 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

}

4. 以下程序实现交换a,b变量的值,请用下横线标出错误所在行并给出修改意见。

#include void swap(int &a,int &b) {a=a+b; b=a-b; a=a-b; }

void main() {int a=19,b=15;

cout<<\swap(&a,&b); swap(a,b); cout<<\}

5. #include

void main() {int i(3),j(8);

int * const p=&i; int *p=&i; cout<<*p<

cout<<*p<

四、完成程序题(本大题共5小题,每小题4分,共20分)

1. 在下面程序横线处填上适当内容,使程序执行结果为:\。

#include #include using namespace std; class mystring {public:

char * pdata; mystring(int len)

{pdata=new char[len+1]; }

~mystring() {delete pdata;}

void show(){cout<

void fun(mystring** array,int len) {mystring*old=*array;

_*array=new mystring(len)______; memcpy(*array, old, len);

}

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<<\};

搜索更多关于: 自考C++试题及答案(9套合集)-3-4. 的文档
自考C++试题及答案(9套合集)-3-4..doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c6ile68d6gc0daes3y3831emx02sb8q00vrp_2.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top