华南俳烁实业有限公司

自考

各地資訊
當(dāng)前位置:考試網(wǎng) >> 自學(xué)考試 >> 自考真題 >> 工學(xué)類 >> C語言程序設(shè)計(jì) >> 文章內(nèi)容

排行熱點(diǎn)

  • 歷年真題
  • 模擬試題
  • 自考自答

全國2012年1月自學(xué)考試C++程序設(shè)計(jì)試題_第5頁

來源:考試網(wǎng) [ 2013年11月23日 ] 【大 中 小】

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

46.在下面程序的下劃線處填上正確的語句,使其得到下面的輸出結(jié)果。

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.在下劃線處填上適當(dāng)?shù)恼Z句,使程序的輸出結(jié)果如下:

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.在下劃線處填上適當(dāng)?shù)恼Z句,使程序的輸出結(jié)果如下:

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.在下劃線處填上適當(dāng)?shù)木渥,完成函?shù)的定義。

#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.輸入一個(gè)字符串,將其逆序后輸出。

#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;

}

責(zé)編:may1205
井研县| 甘肃省| 左权县| 科技| 柘城县| 邮箱| 新竹市| 平湖市| 扶风县| 佛山市| 永新县| 阿克苏市| 镇远县| 浦城县| 黔西县| 陆良县| 和平区| 错那县| 山西省| 宿松县| 武强县| 宜州市| 石阡县| 孙吴县| 石棉县| 金阳县| 贵定县| 遂川县| 麦盖提县| 专栏| 兴安县| 同仁县| 湘乡市| 绥棱县| 会宁县| 鸡东县| 江永县| 宁海县| 定兴县| 昔阳县| 铜川市|