自考C++程序设计2016年10月试题及答案解析,该试卷为自考C++程序设计历年真题试卷,包含答案及详细解析。
有一个Person类,私有数据成员name、age和sex分别表示人的姓名、年龄和性别。雇员类Employee是Person的派生类,新增数据成员部门department和薪水salary。请用C++代码描述这两个类,并用Employee类的成员函数Display实现雇员的姓名、年龄、性别、部门和薪水的输出。(要求编写派生类的构造函数)
给出下面程序的输出结果
#include ﹤iostream﹥
using namespace std;
void main( )
{
void sort( int s[ ]);
int score[5];
int i;
for(i=0;i﹤5;i++)
score[i]=i;
sort( score);
cout﹤﹤"运行结果是:";
cout﹤﹤score[i]﹤﹤" ";
}
void sort int s[ ])
int t;
for(int i=0; i﹤4; i++)
for (int j=i+1; j﹤5; j++)
if(s[i]﹤s[j])
t=s[i];s[i]=s[j];s[j]=t;
class Clock{
public:
Clock( )
cout﹤﹤"clock的构造函数"﹤﹤endl;
~Clock( )
cout﹤﹤" clock的析构函数﹤﹤endl;
};
class Date
Date( )
cout﹤﹤"Date的构造函数"﹤﹤endl;
~Date( )
cout﹤﹤"Date的析构函数"﹤﹤endl;
Clock c;
Date d;
一个通讯录contacts有姓名name和电话tel两个属性,有三个成员函数searehN、insertN和deleteN分别完成查找、插入和删除功能,请完成contacts的类图。
类book,含有2个数据成员num编号和price价格,有成员函数set和display分别输入和显示书的编号和价格,在main中调用所有成员函数。
#include ﹤ iostream﹥
class book
private:char num[8];
void set( )
cin﹥﹥mum﹥﹥price;
void display( )
cout﹤﹤ num﹤﹤" "﹤﹤ price﹤﹤ endl;
book b;________;
b. display( );
完成程序空白处,可参考以下运行结果:
4!=24
n=-2!
不能计算n!
程序执行结束
#include ﹤iostream. h﹥
int f(int n)
if(n﹤=0) throw n;
int s=1;
for( ________ )
s *=i; //计算1*2*3…*n的值retum s;
try
cout﹤﹤________﹤﹤endl;
cout﹤﹤"-2!="﹤﹤f(-2)﹤﹤endl;
catch(int n)
cout﹤﹤"n="﹤﹤n﹤﹤"不能计算n!"﹤﹤endl;
catch(...) { cout﹤﹤"出现异常!"﹤﹤endl;
cout﹤﹤"程序执行结束"﹤﹤endl;
程序用于在屏幕上显示指定的文本文件的内容。
#include ﹤fstream﹥
int main( )
ifstream ifile;
char fn[ 20], ch;
cout﹤﹤"输入文件名";cin﹥﹥fn;
________; //打开指定的文件
if(! ifile)
cout﹤﹤fn﹤﹤"文件不能打开"﹤﹤endl;
retum 0;
while((ch = ifile. get())!=EOF)________; //输出字符
cout﹤﹤ endl;
ifile. close(); //关闭文件
return 1;
________ PI=3.1415;
double length( float r) //圆的周长
return 2*PI*r;
________ //矩形的周长{return 2*(x+y);
float a =2, b=3, r=4;
cout﹤﹤"圆周长"﹤﹤ length(r)﹤﹤endl;
cout﹤﹤"矩形周长"﹤﹤ length(a,b)﹤﹤endl;
template ﹤typename AT﹥
AT max(AT x, AT y)
retum(x﹥y)? x:y;void main( )
int i1=10, i2=56;
double d1=50.344, d2=56.346;
char c1='k', c2='n';
cout﹤﹤"较大的整数是:"﹤﹤max(i1, i2)﹤﹤endl;cout﹤﹤"较大的双精度型数是:"﹤﹤max(d1, a);
cout﹤﹤"较大的字符是:"﹤﹤max(c1, c2)﹤﹤endl;
#include ﹤string﹥
int change( string s)
s=s+"dog!";
cout﹤﹤ s﹤﹤ endl;
string str("it is a ");
change(str);
相关试卷
2018年4月电子商务全国自考(电子
2017年10月电子商务全国自考(电
2017年4月电子商务全国自考(电子
2016年10月电子商务全国自考(电
2016年4月电子商务全国自考(电子
2015年10月电子商务全国自考(电
2015年4月电子商务全国自考(电子
2014年10月电子商务全国自考(电
2014年4月电子商务全国自考(电子
2013年10月电子商务全国自考(电