自考C++程序设计2017年4月试题及答案解析,该试卷为自考C++程序设计历年真题试卷,包含答案及详细解析。
定义一个生日类,数据成员有年、月、日。定义一个人员类,数据成员有姓名、性别、生日。人员类中的生日是生日类的对象,两个类都有构造函数和显示函数。在主函数中声明一个人员类对象,屏幕显示其数据。
#include ﹤iostream﹥
using namespace std;
void sort( int L[ ], int n)
{
int i, k, flag, temp;
flag=n-1;
while( flag﹥0)
k=flag -1;
flag=0;
for(j=0; j﹤=k; j++)
if(L[j]﹥L[j+1])
temp=L[j];
L[j]=L[j+1];
L[j+1]=temp;
flag =j;
}
void main( )
int array[4]={7,2,3,4};
sort( array, 4);
cout ﹤﹤"The sorted numbers:";
for(int i=0; i﹤4; i++)
cout ﹤﹤ array[i];
class x
{protected: int a;public: x( ) {a=1; }
};
class x1;
virtual public x
public:
x1( )
{a+=1; cout﹤﹤"x1: "﹤﹤a﹤﹤","; }
class x2:
public:x2( )
{a+=2; cout﹤﹤"x2: "﹤﹤a﹤﹤","; }
class y:
public x1,
public x2
public:y( )
{ cout ﹤﹤"y: "﹤﹤a﹤﹤ endl; }
y obj;
程序运行结果为3
int main( )
int a=16, b=21, m=0;_________
case 0: m++; break;
case 1: m++ ;
switch(b%3)
_________
case 1: m++; break;
cout ﹤﹤m﹤﹤ endl;
return 0;
定义平面上一个点的类point,有双精度型私有数据成员横坐标x和纵坐标y,公有成员函数有写入函数input( )、求原点距离函数distance( )和显示函数show( ),请完成point( )的类图。
程序的运行结果为:12
class Base
int a;Base (int i)
a=i;
class Derived:
public Base
int a;
Derived(int x):
Base(x) { }
void show( )
_________; //输出基类数据成员a的值
void main( }
{_________d. show ( );
class F
double F:: operator( ) (double x, double y) const
retum(x+5)*y;
F f;cout﹤﹤f(1.5, 2.2)﹤﹤endl;
程序在主函数中创建派生类Derived的对象obj,调用f( )函数后输出DBC
virtual void f( )
cout ﹤﹤"B";
Derived( )
cout ﹤﹤"D";
Base:: f( );
cout ﹤﹤"C";
Base *ptr;
Derived obj;
ptr=&obj;
retun 0;
此程序调用 findmax( )函数,返回数组中的最大值。
include ﹤iostream﹥
int findmax (int *a, int n)
int *p, *s;
for(p=a, s=a; p-a﹤n; p++)
if(*P﹤*s) *s=*p;
return(* s);
int x[5]={12,2,8,47};
cout﹤﹤ findmax(x, 5)﹤﹤endl;
int x=15;
while(10﹤x﹤50)
x++;if(x/3)
x ++; break;
cout﹤﹤x﹤﹤endl;
相关试卷
2018年4月电子商务全国自考(电子
2017年10月电子商务全国自考(电
2017年4月电子商务全国自考(电子
2016年10月电子商务全国自考(电
2016年4月电子商务全国自考(电子
2015年10月电子商务全国自考(电
2015年4月电子商务全国自考(电子
2014年10月电子商务全国自考(电
2014年4月电子商务全国自考(电子
2013年10月电子商务全国自考(电