您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 工程监理 > VC二级考试--面向对象部分真题(2000年秋-----2011年春)
江苏省计算机二级考试VC++面向对象部分真题(2000年秋---2011年春)zjunqiang@126.com2011春第10题.#includeiostream.hclassA{intx,y;public:A(inta,intb){x=a;y=b;}virtualvoidfun1(){coutx+y=x+y\n;}};classB:publicA{intm,n;public:B(inta,intb,intc,intd):A(c,d){m=a;n=b;}voidfun1(){coutm*n=m*n\n;}};voidprint(A&ra){ra.fun1();}voidmain(){Aa(10,20),*pa;B*p;p=newB(20,30,40,50);p-fun1();pa=&a;pa-fun1();pa=p;pa-fun1();print(a);deletep;}2010秋第11题#includeiostream.hclassA{public:A(char*s){coutsendl;}A(){};};classB:publicA{public:B(char*s1,char*s2):A(s1){couts2endl;}};classC:publicA{public:C(char*s1,char*s2):A(s1){couts2endl;}};classD:publicB,publicC{public:D(char*s1,char*s2,char*s3,char*s4):B(s1,s2),C(s1,s3){couts4endl;}};voidmain(){D*ptr=newD(students,study,C++,hard);deleteptr;}2010春9.#includeiostream.h#includestring.hclassB{public:B(char*s){name=newchar[strlen(s)+1];strcpy(name,s);}virtualvoidprint(){cout姓名:name\n;}protected:char*name;};classP1:publicB{public:P1(char*s,floatg):B(s){x=g;}voidprint(inti){cout姓名:name,年薪:x万元。\n;}private:floatx;};classP2:publicB{public:P2(char*s,intn):B(s){num=n;}voidprint(){cout姓名:name,月工资num元。\n;}private:intnum;};voidmain(){B*p;Bx(张朋);P1y(王虎,4.2);P2z(李建国,5000);p=&x;p-print();p=&y;p-print();y.print(1);p=&z;p-print();}2009年秋//9.[程序](2分)#includeiostream.hclassB{public:voidf1(){coutB类中的函数f1\n;}virtualvoidf2(){coutB类中的函数f2\n;}};classD:publicB{voidf1(){coutD类中的函数f1\n;}voidf2(){coutD类中的函数f2\n;}};voidmain(void){Ba,*p;Db1;p=&a;p-f2();p=&b1;p-f1();p-f2();}//运行程序后输出的第二行是(17),第三行是(18)。2009年春10.#includeiostream.hclassA{intx;public:A(inta){x=a;}virtualvoidprint(){coutx=x'\n';}voidfun(){print();}};classB:publicA{inty;public:B(inta,intb):A(a){y=b;}voidprint(){couty=y'\n';}voidfun(){print();}};classC:publicB{intz;public:C(inta,intb,intc):B(a,b){z=c;}voidprint(){coutz=z'\n';}voidfun(){print();}};voidmain(){Aa1(5),*p1;Bb1(10,15);Cc1(20,30,40);a1.fun();b1.fun();c1.fun();p1=&b1;p1-fun();p1=&c1;p1-fun();}11.#includeiostream.hvoidinsert(intp[],intc,intx){for(inti=0;ic;i++)if(p[i]x)break;if(i==c)p[i]=x;else{for(intj=c;ji;j--)p[j]=p[j-1];p[j]=x;}}intsort(ints[],intn){inttem[200];intlen,j,k;tem[0]=s[0];len=1;for(j=1;jn;j++){for(k=0;klen;k++){if(s[j]==tem[k])break;}if(k=len){insert(tem,len,s[j]);len=len+1;}}for(j=0;jlen;j++)s[j]=tem[j];returnlen;}voidmain(){ints1[200]={34,22,11,55,66,30,22,100,66};intn;n=sort(s1,9);for(inti=0;in;i++)couts1[i]'\t';cout'\n';}12.#includeiostream.hclassSet{floatx[20];intsize;public:intIn(floate,intn){intflag=0;for(inti=0;in;i++)if(x[i]==e){flag=1;break;}returnflag;}Set(floata[],intn){x[0]=a[0];size=1;for(inti=1;in;i++)if(In(a[i],size)==0){x[size]=a[i];size++;}}Set(){size=0;}Setoperator+(Set);Setoperator*(Set);Set&operator=(Set&);intGetSet(floaty[]){for(inti=0;isize;i++)y[i]=x[i];returnsize;}voidprint(){for(inti=0;isize;i++)coutx[i]'\t';cout'\n'size=size'\n';}};SetSet::operator+(Seta){Settem;for(inti=0;isize;i++)tem.x[i]=x[i];tem.size=size;for(i=0;ia.size;i++){if(tem.In(a.x[i],tem.size)==0)tem.x[tem.size++]=a.x[i];}returntem;}SetSet::operator*(Seta){Settem;tem.size=0;for(inti=0;isize;i++)if(a.In(x[i],a.size)==1)tem.x[tem.size++]=x[i];returntem;}Set&Set::operator=(Set&a){for(inti=0;ia.size;i++)x[i]=a.x[i];size=a.size;return*this;}voidmain(){floatb1[6]={1,2,3,4,5,6};floatb2[6]={3,5,7,9,11},b3[6];Seta1(b1,6),a2(b2,5),a3,a4,a5;a3=a1+a2;a3.print();a5=a1*a2;a5.print();intn=a1.GetSet(b3);for(inti=0;in;i++)coutb3[i]'\t';cout'\n'n'\n';}2008年秋10.#includeiostream.hclassA{intx;public:A(inta){x=++a;}~A(){coutx'\n';}intget(){returnx;}};classB:publicA{inty;public:B(intb):A(b){y=get()+b;}B():A(5){y=6;}~B(){couty'\n';}};voidmain(){Bb(5);}11.#includeiostream.hclassA{intx;public:A(intx=0){this-x=x;}virtualvoidf(){coutxendl;}};classB:publicA{inty;public:B(intx,inty=1):A(x){this-y=y;}voidf(inta){coutyendl;}};voidmain(){Aa1(10),*pa;Bb1(20,30);a1.f();pa=&a1;pa-f();pa=&b1;pa-f();}2008年春10.#includeiostream.hclassBase{public:voidvirtualf(){coutBase::f()endl;}voidvirtualg(){coutBase::g()endl;}};classA:publicBase{public:voidf(inta=0){coutA::f()endl;}};classB:publicA{voidf(){coutB::f()endl;}voidg(){coutB::g()endl;}};voidmain(){Bb;Base*p=&b;A*q=&b;p-f();p-g();q-f();q-g();}2007年秋10.#includeiostream.hclassA{inta;public:voidseta(intaa){a=aa;}virtualvoidprint(){couta'\t';}};classB:publicA{intb;public:voidsetb(intbb){b=bb;}voidprint(){coutb'\t';}};voidmain(){Aa,*p;Bb;a.seta(5);b.seta(10);b.setb(20);p=&a;p-print();p=&b;p-print();}2007年春10.#includeiostream.h#includestring.hclassBase{charstr[20];public:Base(char*s=BaseDefault){strcpy(str,s);coutstrendl;}};classInh1:publicvirtualBase{charstr1[20];public:Inh1(char*s1,char*s2):Base(s1){strcpy(str1,s2);coutstr1endl;}};classInh2:publicvirtualBase{charstr2[20];public:Inh2(char*s1,char*s2):Base(s1){strcpy(str2,s2);couts2endl;}};classInh3:publicInh1,publicInh2{charstr3[20];public:Inh3(char*s1
本文标题:VC二级考试--面向对象部分真题(2000年秋-----2011年春)
链接地址:https://www.777doc.com/doc-1515067 .html