资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,*,*,习题课,一、写出下列程序的结果,#include,int,x=2,y=x+30;,class A,int,y;,static,int,x;,public:,operator,int,(),return,x+y,;,A operator+(,int,),return,A(x+,y,+);,A(int,x=2,int y=3),A:x,=:,x+x,;,A:y,=:,y+y,;,void print(),cout,x=x,ty=y,endl,;,;,int,A:x,=23;,void,main(void,),A a(54,3),b(65),c;,a.print,();,int,i=,a+b,;,cout,i=i,endl,;,c+;,c.print,();,(2),#include,#include,class Base,char str20;,public:,Base(char,*s=Base default),strcpy(str,s,);,cout,str,endl,;,;,class,Inh1:,public,virtual,Base,char str120;,public:,Inh1(char*s1,char*s2):Base(s1),strcpy(str1,s2);,cout,str1,endl,;,;,class Inh2:public,virtual,Base,char str220;,public:,Inh2(char*s1,char*s2):Base(s1),strcpy(str2,s2);,cout,s2,endl,;,;,class Inh3:public Inh1,public Inh2,char str320;,public:,Inh3(char*s1,char*s2,char*s3,char*s4):Inh1(s1,s2),Inh2(s1,s3),strcpy(str3,s4);,cout,str3,endl,;,;,void,main(void,),Inh3,a(class,Base,class,Inh1,class Inh2,class Inh3);,2,、以下程序定义了一个类,numb,,通过成员函数重载运算符“”,函数返回对象值,以便继续参加运算。,以下程序含有错误,请改正!,#include,class numb,int,num;,public:,numb(int,n=0)num=n;,void show(),cout,numnext;,while(p&p,-datanext;,while(p&p,-datanext;,q-next=p;,return L;,二、编程题,1,11,121,1331,14641,1510,10,51,1615201561,请生成如下三角形,此三角形称为扬辉三角形,void main(void),int,ynn,s=0;,for(,int,i=0;i,n;i+,),for(,int,j=0;j,=i;j+,),if(j=0|j=i)yij=1;,else yij=yi-1j+yi-1j-1;,for(i=0;i,n;i+,),for(,int,j=0;j,=i;j+,),cout,yijt;,cout,n;,
展开阅读全文