全国2012年1月自学考试C++程序设计真题(打印word版)(四)

时间:2015-02-09 17:54:13

微信搜索关注"91考试网"公众号,领30元,获取事业编教师公务员等考试资料40G

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

46.在下面程序的下划线处填上正确的语句,使其得到下面的输出结果。

x=2,y=3

#include<iostream.h>

class Sample

{

int x,y;

public:

Sample( ){

x=y=0;

}

Sample(int a,int b){

x=a;

(__________)

}

void disp( )

{

cout<<"x="<<x<<",y="<<y<<endl;

}

}(____­_______)

void main( )

{

Sample s(2,3),*p=&s;

p - >disp();

}

47.在下划线处填上适当的语句,使程序的输出结果如下:

n=30

#include< iostream.h >

template< class T >

class Sample

{

T n;

public:

Sample( ){ }

Sample(T i){_________}

Sample<T>&operator+(const Sample<T>&);

void disp( ){cout<<"n="<<n<<endl;}

};

template<class T>

Sample<T>&Sample<T>::operator+(const Sample<T>&s)

{

static Sample<T>temp;

return temp;

}

void main( )

{

Sample<int>s1(10),s2(20),s3;

s3=s1+s2;

s3.disp();

}

48.在下划线处填上适当的语句,使程序的输出结果如下:

1 2 3 4 5 6 7 8 9 10

#include<iostream.h>

class Sample

{

int A[10][10];

public:

int &operator()(int,int);

};

int &Sample::operator()(int x,int y)

{

return A[x][y];

}

void main()

{

Sample a;

int i,j;

_________

for(j=0;j<10;j++)

_________

for(i=0;i<l0;i++)

cout<<a(i,1)<< " ";

cout<<endl;

}

49.在下划线处填上适当的句子,完成函数的定义。

#include<iostream.h>

class Sample

{

int x;

public:

Sample( ){ };

_________{x=a;}

   _________{x=a.x++   +10;}

void disp( ){cout<<"x="<<x<<endl;}

};

void main( )

{

Sample s1(2),s2(s1);

s1.disp( );

s2.disp( );

}

50.输入一个字符串,将其逆序后输出。

#include<iostream>

using namespace std;

void main()

{

char a[50];memset(a,0,sizeof(a));

int i=0,j;

char t;

cin.getline(a,50,' n';

for(i=0,j=strlen(a)-1;i<_________;i++,j ―― )

{

t=a[i];

a [j]=t;

}

cout<<a<<endl;

}


首页 上页 3 4 5 下页 尾页 4/6/6
微信搜索关注"91考试网"公众号,领30元,获取公务员事业编教师考试资料40G
【省市县地区导航】【考试题库导航】
 ★ 自学考试省级导航 ★ 
全国 A安徽 B北京 C重庆 F福建 G广东 广西 甘肃 贵州 H河南 河北 湖南 湖北 黑龙江 海南 J江苏 江西 吉林 L辽宁 N内蒙古 宁夏 Q青海 S山东 山西 陕西 四川 上海 T天津 X新疆 西藏 Y云南 Z浙江 历年真题分类检索
 ★ 自学考试导航 ★ 
 ★ 自考报名 ★ 

电脑版  |  手机版  |  返回顶部