C程序设计语言资料

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

第3次作业

一、填空题(本大题共20分,共5小题,每小题4分)

1•假定一个二维数组为a[M][N],则a[i]的地址值(以字节为单位)为 2.

类型兼容原则指的是:任何在需要________ 对象的地方,都可以用_______________________________________ 的对象

去替代。

3.

重新抛出异常的表达式为:__________

4.

以下程序的执行结果是______________________

#i nclude

using n amespace std;

class Base{

public:

Base(){cout<< ” T ;}

~Base(){cout<< ” 2” ;}

};

class Derived : public Base{

public:

Derived(){cout<< ” 3” ;}

~Derived(){cout<< ” 4” ;}

};

void mai n(){

Derived d;

5.

以下程序的执行结果是______________________

#i nclude

using n amespace std;

class A{

int x;

public:

A(int x){this->x=x;}

A &operator--(){x--;return *this;}

A operator— nt){A a(x-=2);retur n a;}

void show(){ cout« x;}

};

void mai n(){

A a(3),b(3);

(a--).show();

(--b).show();

}

二、程序阅读题(本大题共40分,共5小题,每小题8分) 1.写出下面程序运行结果。

#i nclude

void rev(i nt a[],i nt n)

{

int t;

for(int i=0,j=n-1;i

t=a[i],a[i]=a[j],a[j]=t;

}

int main()

{

int b[]={1,2,3,4,5,6,7,8,9};

rev(b,9);

for(int i=0;i<9;i++) cout

cout«e ndl;

return 0;

}

2.

#i nclude

using n amespace std;

int main()

{

int i,j,m=3;

for(i=0;i

for(j=m-1;j>=0;j--)

cout

cout«e ndl;

return 0;

}

3.

#in clude

#in clude

int coun t(char *s,char *t);

int main()

{

char s1[200]="ab1234cdabcdabcABCDAGBCDdabcd";

char s2[100]="bc";

cout<<"co un t="<

return 0;

}

int coun t(char *s,char *t)

{

int i=0,c=0;

while(*(s+i))

{

if(strncmp(s+i,t,strle n( t))==0)

c++;

i++;

}

return c;

}

#in clude

int avere(i nt x,i nt y,i nt z);

double aver(double x,double y,double z);

int main()

{

int ai=1,bi=2,ci=3;

double ad=1.5,bd=5.5,cd=7.5;

cout

p(a,b);

coutvvavv","vvbvv","v

return 0;

}

void p(i nt a,i nt b)

{

static int c;

a++,b++;

c-=1,d+=1;

if(a<3)

{

p(a,b); coutvvavv","vvbvv","v

}

}

三、程序设计题(本大题共40分,共8小题,每小题5分)

1.

一个正整数与3的和是5的倍数,与3的差是6的倍数,编程序求出符合此

条件的最小正整数。

2.

编制程序实现功能:将从键盘输入的若干字符依次存入到磁盘文件data.txt 中,直到输入字符#时为止。

相关文档
最新文档