返回 计算机应用 - 资讯详情
2018自考c++程序设计10月试题答案
2019-10-28 来源: 作者:tao2018

完成程序题

 

第1题

把从键盘上输入的一批整数(以-1作为终止输入的标志)保存到文本文件“a:xxk1.dat”中。

#include ﹤iostream﹥

#include ﹤fstream.h﹥

#include ﹤stdlib. h﹥

void main( )

{

ofstream fout("a: xxk1.dat");

if( _____________ )

 {

cout﹤﹤"文件没有打开!"﹤﹤end;

exit(1);

}

int x; cin﹥﹥x;

while(x! =-1)

{

fout ﹤﹤x﹤﹤' ';

cin ﹥﹥x;

}

_____________; //关闭文件

}

 

 

 

查看答案解析及完整练习

 

第2题

#include ﹤iostream. h﹥

using namespace std;

_____________;

_____________;

{

T tmp =x*x+y*y+x*y; return tmp;

}

int main( )

{

int x1=1, y1 =4;

float x2=1.1, y2=2.2;

double x3=2.0, y3=3.1;

cout﹤﹤fun(x1, y1)﹤﹤endl;

cout ﹤﹤fun(x2, y2)﹤﹤endl;

cout ﹤﹤fun(x3, y3)﹤﹤ endl;

return 0;

}

 

 

 

查看答案解析及完整练习

 

第3题

完成程序,使其输出结果为79

#include ﹤iostream. h﹥

using namespace std;

int main( )

{

int a[6]={23,15,64,33,40,58

};

_____________;

s1=s2=a[0];

for(int *p=a+1;

 p﹤a+6; p++)

 {

if(s1﹥*p) s1=*p;

if _____________;

}

cout ﹤﹤s1 +s2 ﹤﹤endl;

return 0;

}

 

 

 

查看答案解析及完整练习

 

第4题

#include ﹤iostream.h﹥

class Point

{

int X,Y;

public:

Point(int x=0, int y=0)

{

 X=x; Y=y; Countp ++;

}

Point( point &p)

{

X=p. X; Y=p.Y;

 }

~Point( )

{

 Countp--;

 }

_____________;

static int Countp; void display( )

{

 cout ﹤﹤X﹤﹤", "﹤﹤Y﹤﹤", ";

 }

};

Point myfun( Point p1, Point p2, Point p3)

{

 Point tmp(p1. X+p2. X+P3. X, p1. Y+p2.Y+p3. Y);

return tmp;

}

int Point:: Countp =0;

void main( )

{

 Point pp,p1(1,2),p2(1);

Point p=myfun(pp0, pp1, pp2);

p. display ( );

_____________; //输出Countp的值

}

 

 

 

查看答案解析及完整练习

 

第5题

完成程序,使其结果为 x=6,y=10 x=11,y=10

#include ﹤iostream.h﹥

using namespace std;

class Sample

{

private: int x;

_____________;

public:

Sample (int a);

void print( );

};

Sample:

Sample( _____________ )

{

 x=a; y=x++;

}

void Sample:: print( )

{

cout ﹤﹤"x="﹤﹤x﹤﹤",y="﹤﹤y﹤﹤end;

}

int Sample: : y =25;

void main( )

{

 Sample s1(5);

Sample s2(10);

s1. print( );

s2. print( );

}

 

 

 

查看答案解析及完整练习

温馨提示 : 因考试政策、内容不断变化与调整,上学吧提供的以上信息仅供参考,如有异议,请考生以权威部门公布的内容为准。
扫码下载上学吧找答案APP
扫码下载上学吧找答案APP

作业考试网课答案应有尽有

点击一键安装
找答案微信小程序
找答案微信小程序

免下载,即可体验强大搜题神器

相关推荐 更多相关资讯
推荐试题 更多试题