下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一:Linux系统基 常用的linux命令,并说明其功 二:C语言基 C选择题- C简答题- C编程题- C++选择题- C++填空题- C++简答题- C++编程题- 五:UC环境编 UC选择题- UC简答题- 六:VC环境编 VC选择题- VC简答题- 七:数据 一:Linux系统基linux -apwd查看当 datecatshutdown/init0init6/rebootcdls查看 mkdirrm删 mvln创建软连接(ln–stouch find/-namefile1从 o.which显示一个二进制文件的完整路径p.groupadd创建一个新用户组q.useradd创建一个新用户r.tar包操作命令s.zip压缩命令t.unzip解压命令u.rpm安装/rpm二:C语言基C选择题-一个C程序的执行是 mainmainC.main函数开始,到本程序文件的最后一个函数结束D.main函数结束C程序中,mainCCC程序进行编译的过程中,可发现注释中的拼写错误C一个可编译为可执行程序的CmainCC程序中,注释说明只能位于一条语句的后面int7A.(x=y=6,x+y,x+1)B.(x=6,++x,x)C.(x=6,D.(y=6,y+1,x=y,正确答案设有说明:charwintxfloaty;doublez;w*x+z-y正确答案 正确答案x、y、zintx=(y=(z=10)+5)-5x、y、z正确答案intmainvoidinta=printf("%d",a+++++a);return0;}正确答案intmainvoidintx;floatprintf("Enterxandy:return0;}Enterxandy:2scanf("%d%f",x,y);printf("x+y=%4.2f",scanf("%d%f",x,y);printf("x+y=%3.2f",scanf("%d%3.1f",&x,&y);printf("x+y=%4.2f",scanf("%d%f",&x,&y);printf("x+y=%4.2f",正确答案 正确答案00正确答案intmainvoidinta,b,a=b=c=++a||--b&&printf("%d,%d,%d",a,b,c);return0;正确答案分段函数y=f(x)的值表如下所示: < x–= > x+A.y=x+if(x>=if(x==
y=y=x-B.y=x-if(x!=if(x>y=x+y=C.if(x<=if(x<y=x-1;y=y=x+D.y=if(x<=if(x<y=x-y=x+正确答案intmainvoidinta=10,b=9,c=(--a==b++)?--a:printf("%d,%d,%d",a,b,c);return0;}正确答案intmainvoidinti,for(i=1;i<=100;{x=if(++x%2==if(++x%3==if(++x%7==printf("%d",}return} 正确答案for(i=100;i<=200;i++){if(!(i%printf("%d\n",i);}for(i=100;(i%3)&&i<=200;i++)printf("%d\n",i);for(i=100;(i%3)||i<=200;i++)printf("%d\n",i);for(i=100;i<=200;if(i%printf("%d\n",i);D.for(i=100;i<=200;i++)if(i%printf("%d\n",正确答案
intmain(void)inta,b,c,d;scanf("%d",&a);for(b=3;b<=a/2;b+=2){for(c=2;c<=sqrt(b);c++)if(b%c==0)if(c<=sqrt(b)) d= for(c=2;c<=sqrt(d);c++)if(d%c==0)if(c<=sqrt(d))printf("%d=%d+%d\n",a,b,}return}A.a+ B.a– C.a* D.a/正确答案intmainvoidintk=0;charc='A';do{switch(c++)case'A':k++;casecasek+=casek%=casek*=k/=}while(c<printf("k=%d\n",k);return0;}第一次循环后:C=‘BK=2C=‘C第三次循环后:C=‘D’K=1;第四次循环后:C='E',10;第五次循环后:C='F'K=4A.k= B.k= C.k= D.k=正确答案正确答案inta[2][3]=inta[][3]=inta[2][3]=inta[][3]=正确答案intmainvoidinta[6][6],i,for(i=1;i<6;for(j=1;j<6;a[i][j]=(i/j)*(j/i);for(i=1;i<6;i++){for(j=1;j<6;printf("%d",a[i][j]);printf("\n");}return}1111111111111111111111100000100000100000100000C.00001000100010001000100000010101000100010101000正确答案C语言函数参数的说法中正确的是B.实参和与其对应的形参共享同一个单元正确答案voidhanoiintncharfromcharbychartoif(n)hanoi(n-1,from,to,by);printf("%c->%c\n",from,to);hanoi(n-1,by,from,}}intmain(void)hanoi(3,'A','B',return}mainhanoiA.A->CA->BC->B->C->BA->CA->B.A->CA->BC->A->B->CA->CA->C.A->CA->BC->A->B->AB->CA->D.A->CA->BC->A->B->AB->CA->正确答案正确答案 #defineXa%4#defineYX+3#defineZY*X/2intmainvoidinta=printf("%d",++Z);return0;} 正确答案#defineSQUARE(x)#defineSQUARE(x)正确答案char*s="abcde";s+=printf("%d",s);C.字符cintmainvoidinta[]={10,20,30,40,printf("%d\n",*((int*)(&a+1)-1));return0;} A.a+B.a+C.*(a+正确答案qsortintcompare_cstr(constvoid*pv1,constvoid*pv2){return① }intmain(void)constchar*cities[]={qsort size_tfor(i=0;i<sizeof(cities)/sizeof(cities[0]);i++)printf("%s\n",cities[i]);return}strcmp(*(constchar**)pv1,*(conststrcmp(*(constchar*)pv1,*(conststrcmp(*pv1,strcmp(pv1,正确答案B.cities,sizeof(cities)/sizeof(cities[0]),C.cities,sizeof(cities)/sizeof(cities[0]),sizeof(cities[0]),compare_cstrD.cities,sizeof(cities)/sizeof(cities[0]),sizeof(cities[0])正确答案typedefvoid*(*square_t)(int*x);void*square(int*x)*x*=return}intmain(void){intx=2;((square_t)((square_t)((square_t)square(&x))(&x))(&x))(&x);printf("%d",x);return} 正确答案intmain(void){intna=1;intnb=swap(&na,&nb,sizeof(na));printf("%d,%d\n",na,nb);doublefa=0.1;doublefb=swap(&fa,&fb,sizeof(fa));printf("%g,%g\n",fa,fb);char*sa="o";char*sb=swap(&sa,&sb,sizeof(sa));printf("%s,%s\n",sa,sb);return0;}2,0.2,world,swap函数应定义 voidswap(int*a,int*b,size_tsize){intc=*a;*a=*b=}voidswap(double*a,double*b,size_tsize){doublec=*a;*a=*b=}voidswap(char**a,char**b,size_tsize){char*c=*a;*a=*b=}voidswap(void*a,void*b,size_tsize){void*c=malloc(size);memcpy(c,a,size);memcpy(a,b,size);memcpy(b,c,size);free(c);}正确答案 charsz[5]={'a','b',0,'c','\0'};printf("%s",sz);D.abc正确答案abchara[]=charb[]={'A','B','C','D','E',A.abB.abC.abD.ab数组长 chara[]="abcdef";charb[]="ABC";memcpy(a,b,strlen(b)*sizeof(b[0]));printf("%s\n",a);strcpy(a,b);printf("%s\n",a);正确答案chara[3bTARENAab;printfsa);正确答案下面的代码意在实现一个将字符串转换成浮点数的函数(Catof函数。doublemy_atof(constchar*a){doublef=0;if )for(;isdigit(*a);a++)f=f*10+(*a-'0');if(*a=='.'){size_tdec=0;for ;isdigit(*a);a++)f=f*10+(*a-'0');}for(;dec; f/=}}return}A.strlen B.strlen(a)&& C.a&&strlen D.a||strlen正确答案 D.a=正确答案 D.dec>正确答案structStudent{charname[20];boolsex;intage;structintyear;intmonth;intday;}structStudentA.year=month=day=student.month=student.day=C.birth.year=birth.month=birth.day=student.birth.month=student.birth.day=正确答案正确答案32IBM-PCCstructAchar shortint}则变量a所占用的字节数和成员布局 正确答案intmainvoidunionchars[5];intn;}sprintf(u.s,printf("%#x",u.n);return0;} 正确答案inta=10,b=20;a^=b^=a;a^=ab 正确答案fopen函数打开一个新的二进制文件,该文件要既能读也能写,则文件打开方式 正确答案返回实际的字节数,出错返回返回实际的字节数,若出错或遇到文件尾,该值将小于所期望的字节数fseekfp20L2)20个字节intmain(intargc,char*argv[]){if(argc<3)printf("Usage:%s<source_file><dest_file>\n",argv[0]);return-1;}FILE*src=① if(!src){printf("Unabletoopensourcefile\n");return-1;}FILE*dst=② if(!dst){printf("Unabletoopendestfile\n");return-1;}intunsignedcharbuf[1024];while(③ if )printf("Unabletowritedestfile\n");return-1;}if )printf("Unabletoreadsourcefile\n");return-1;}fclose(dst);fclose(src);return0;}fopen(argv[0],fopen(argv[1],fopen(argv[2],fopen(argv[1],正确答案fopen(argv[0],fopen(argv[1],fopen(argv[2],fopen(argv[2],正确答案A.bytesfreadbuf1sizeofbufsrc)B.(bytes=fread(buf,1,sizeof(buf),src))==sizeofC.bytes=fread(buf,sizeof(buf),1,D.fread(buf,1,sizeof(buf),正确答案fwrite(buf,1,sizeof(buf),dst)!=sizeoffwrite(buf,1,bytes,dst)<=fwrite(buf,1,bytes,dst)!=fwrite(buf,bytes,1,dst)!=正确答案feoffeof正确答案my_printf(Cprintf的简化版本itoa用于将整数按十进制转换为字符串。请将其中缺失的部分补全。char*itoa(inti,char*a){if(a){size_tfor(n=0;i;i/= if(!a[n++]=a[n]=size_tlen=strlenfor(n=0;n< ;n++)charc=a[n];a[n]=a[len-1-n];a[len-1-n]=}}return}intmy_printf(constchar*format,...){intcn=0;va_list charfor(c=*format;c;c=*(++format))if(c=='%')switch(c=*(++format)){case'd':{intn=va_arg(ap,int);charsz[128];itoa(n,fputs(sz,stdout);cn+=strlen(sz);}case'c':charc=va_arg(ap,int);putchar(c);}case's':char*psz=④ fputs(psz,stdout);cn+=strlen(psz);}}elseputchar(c);} return}intmain(void)my_printf("Integer:%d,Char:%c,String:%s\n", 2012,'C',"oworld");return0;}A.a[++n]=i%10B.a[n++]=i%10C.a[++n]=i%10+'0'D.a[n++]=i%10+正确答案A.len/ C.len/2– D.len-正确答案va_start(ap,正确答案va_arg(ap,va_arg(ap,va_arg(ap,va_arg(ap,正确答案va_endva_end(ap,va_end正确答案C简答题-intptr=(int*ptr=Amoreobscureapproach*(int*const)(0x67a9)=#includestdio.h"#defineSQR(X)intmain(intargc,char*{inta=10;intk=2;intm=1;a/=SQR(k+m)/SQR(k+m);return}defineX*Xa/==>a/==>a==>a=constconstcharcharconstchar*constconstconstconst位于星号的右侧,const就是修饰指针本身,即指针本身是常量。constcharcharconst对象指针,p不是常量,pconstchar*p;charc1='a';charc2='b';char*const此时*ppconstchar*constvoidDoSomeThing(char*p){charstr[16];intn;assert(NULL!=p);判断sscanf(ps%dstrn);if(0==strcmp(str,{}}答案 sscanf(ps%dstrVoidtest1(){charchar*str1=" strcpy(string,str1);}Voidtest2(){charstring[10],str1[10];for(i=0;i<10;i++){str1[i]}}数组越界,strcpy要判断’\0’才结束Voidtest3(char*str1){char{}}====strcpy拷贝的结束标志是查找字符串中的\0因此如果字符串中没有遇到\0制,直到遇到\0,建议使用strncpy和memcpy{//charstr[]="world";cout<<sizeof(str)<<":";char*p =str; cout<<sizeof(p)<<":";chari =10; cout<<sizeof(i)<<":";void*p =malloc(10);cout<<sizeof(p)<<endl;}{//unionV{structX{unsignedchars1:2;unsignedchars2:3;unsignedchar}unsignedchar}v.c=} #include<stdio.h>inta[int*p[]={a,a+1,a+2,a+3,a+4};voidmain(){}9584structA{chart:4;charunsignedshorti:8;unsignedlongm;}sizeof(A)=7(不考虑边界对齐)--m放在结构体最开始,那么=16struct //DeclareCELLbit{unsignedcharacter:8;// unsignedforeground:3;//00000???unsignedintensity:1;//unsignedbackground:3;//0???0000unsignedblink :1;//?} //Arrayofbitintadd_n(intn){staticinti=100100return}答:因为statici的值会保留上次的值。去掉static#defineswap(x,y)\(x)=(x)+(y)=(x)–(x)=(x)–14.i最后等于多少?inti=1;intj=if((i>j++)&&(i++==j))答:i5unsignedshortinti=*(array+i)=答(试编写函数判断计算机是大端还是小端大端是低地址存,小端是低地(答bool{unsignedshortusData=unsignedchar*pucData=(unsignedchar*)&usData;return(*pucData==0x22);}voidGetMemory(char*p){p=(char*)malloc(100);}voidTest(void){char*str=NULL;} oworld");将使程序:charchar*p=(char*)malloc(100);returnp;}voidTest(void){char*str=NULL;}方法二:voidGetMemory2(char**p)变为二级指针.voidGetMemory2(char**p,intnum){*p=(char*)malloc(sizeof(char)*}static变量和static函数各有什么特点?static变量:在程序运行期内一直有效,如果定义在函数外,则在编译单元内可见,如果在函数内,在定义的函数块内可见;static函数:在编译单元内可见;voidFunc(char{}答:4分析:#include<stdio.h>{inti;charx[2];void{a.x[0]=a.x[1]=}答案:266(低位低地址,高地址,内存占用情况是Ox010A){union*定义一个联合*/inti;struct*在联合中定义一个结构*/charfirst;charnumber.half.first='a';/*联合中结构成员赋值*/}答案:AB(0x41对应'A',是低位;Ox42对应'B',是unsignedlongval;chara=0x96;charb=0x81;val=b<<8|a;问val= char默认为无符号还是有符号。unsignedchar22..hifndef/define/endif的作用?答:防止该头文件被重复(。#include<file.h>includefile.h"答:前者是从StandardLibrary的路径寻找和file.h,而后者是先从当前工作路径搜寻并file.h(。const与#define相比,有何优点?const常量有数据类型,而宏常量没有数据类型。编译器可以对前者进行类型安全constx2inti=cout<<boolalpha<<((i&(i-1))?false:true)<<,chara[]=“a[0]=char*p=“world”;//pp[0]=‘X’;//sizeof可以计算出数组的容量(字节数。sizeof(p),p为指针得到的是一个指针pC++/C语言没有办法知道指针所指的内存容量,chara[]="oworld";char*p=a;coutsizeof(a)endl12字节cout<<sizeof(p)<<endl;//4字节voidFunc(char{coutsizeof(a)endl4100}cout<<FILE cout<<LINE FILE和LINE是系统预定义宏,这种宏并不是在某个文件中定义的,而是由编译器定main答案:可以,可以用_onexit一个函数,它会在main之后执行intfn1(void),fn2(void),fn3(void),fn4(void);voidmain(void{String_onexit(fn1_onexit(fn2_onexit(fn3_onexit(fn4printf("Thisisexecutedfirst.\n"}int{printf("next.\n");return0;}int{printf("executed");return0;}int{printf("is");return0;}int{printf("This");return0;}The_onexitfunctionispassedtheaddressofafunction(func)tobecalledwhentheprogramterminatesnormally.Successivecallsto_onexitcreatearegisteroffunctionsthatareexecutedinLIFO(last-in-first-out)order.Thefunctionspassedto_onexitcannottake结构和联合都是由多个不同的数据类型成员组成,但在任何同一时刻,联合中只存放了一个被选中的成员(所有成员共用一块地址空间)而结构的所有成员都存在(不同成对于联合的不同成员赋值,将会对其它成员重写,原来成员的值就不存在了,而对Newdeletemallocfree的联系与区别且不能初始化对象,new会自动调用对象的构造函数。deletedestructor,而freedestructor.#defineDOUBLE(x)i5*DOUBLE(5)i是多少?答案:i30。BOOL,int,float,a与“零”的比较语句BOOL: if(!a)orif(a)int: if(a==0)float: constEXPRESSIONEXP=0.000001if(a<EXP&&a>-EXP)pointer:if(a!=NULL)orif(a==C编译程序还是由C++编译程序编译的?#ifdefcplusplus用预处理指令#define一个常数,用以表明1年中有多少秒(忽略闰年问题#defineSECONDS_PER_YEAR(60*60*24*MIN,这个宏输入两个参数并返回较小的一个。#defineMIN(A,B)((A)<=(B)?(A):(B))a一个整型数(An一个指向整型数的指针(Apointertoan一个指向指针的的指针,它指向的指针是指向一个整型数(Apointertoapointertoan10个整型数的数组(Anarrayof1010(Anarrayof10pointersto10个整型数数组的指针(Apointertoanarrayof10一个指向函数的指针,该函数有一个整型参数并返回一个整型数(Apointertoafunctionthattakesanintegerasanargumentandreturnsaninteger)10个指针的数组,该指针指向一个函数,该函数有一个整型参数并返回一个整型数(Anarrayoftenpointerstofunctionsthattakeanintegerargumentandreturnaninteger)inta;//Anint*a;//Apointertoanint**a;//Apointertoapointertoaninta[10];//Anarrayof10int*a[10];//Anarrayof10pointerstoint(*a)[10];//Apointertoanarrayof10int(*a)(int);//Apointertoafunctionathattakesanintegerargumentandreturnsanint(*a[10])(int);//Anarrayof10pointerstofunctionsthattakeanintegerargumentandreturnanintegerC编写死循环呢?while(1){for(;;){在模块内(但在函数体外,一个被为静态的变量可以被模块内所用函数,但 函数被限制在它的模块的本地范围内使用。大多数应试者能正确回答第一部分,一部constconstDanSaksconstESP(译者:EmbeddedSystemsProgramming)const能做什么和不能做什么.如果你从没有读到那篇文章,只要能说出const意味着“只读”就可以了。尽管这个答案不constinta;intconsta;constint*a;int*constintconst*a就是,整型数是不可修改的,但指针可以a是一个指向整型数的常指针(也就是说,指针指向的整型数是可以修改的,但指针是不可修改的a是一什么还要如此看重关键字const呢?我也如下的几下理由:关键字const的作用是为给读你代码的人传达非常有用的信息,实际上,一个参数你就会很快学会感谢这点多余的信息(当然,懂得用const的程序员很少会留下的让const可以使编译器很自然地保护那些不希望被改变的参数,防止其bug的出现。inta=5,b=7,c;c=a+++b;c=a+++因此,a6b7c12{char*p1=“name”;char*p2;memset(p2,0,20);while(*p2++=*p1++);}答案::empty{intx=20,y=35;x=y+++x++;y=++y+++x;}答案:{int}答案#defineswap(a,b)a=a+b;b=a-b;a=a-b;Intswap2(inta,intb);void{intx=5,y=10;swap(x,y);}intswap2(inta,int{inttemp;return}答案1010,{char*ptr=”Cisco}答案:iscoSystemsscosystems{chars1[]=“Cisco”;chars2[]=“systems”;}Answer:{char*p1;charp1=(char*)malloc(25);p2=(char*)malloc(25);}答案intx;int{}intchangevalue(int{}void{intx=10;printf("Firstoutput:%dn",x);printf("Secondoutput:%dn",x);}答案:1213{intx=10,y=15;x=x++;y=}Answer:11,{inta=0;printf(“CiscoSystems\n”);printf(“Cisco}答案TwolineswithCiscoSystemswillbecharstr1[]="abc";charstr2[]=constcharstr3[]="abc";constcharstr4[]="abc";constchar*str5="abc";constchar*str6="abc";coutboolalphastr1==str2endl;//输出什么?coutboolalphastr3==str4endl;//输出什么?coutboolalphastr5==str6endl;//voidUpperCase(charstr[])//str{for(size_ti=0;i<sizeof(str)/sizeof(str[0]);++i)if('a'<=str[i]&&str[i]<='z')str[i]-=('a'-'A'}charstr[]=coutstr字符长度为sizeof(str)/sizeof(str[0endl;UpperCase(str);cout<<str<<voidchar2Hexcharc)//16{charch=c/0x10+'0';if(ch>'9')ch+=('A'-'9'-charcl=c%0x10+'0';if(cl>'9')cl+=('A'-'9'-1);cout<<ch<<cl<<'';}charstrIlove中国for(size_ti=0;i<strlen(str);++i)char2Hex(str[i]);cout<<void*mymemcpy(void*dest,constvoid*src,size_tcount{char*pdest=static_cast<char*>(destconstchar*psrc=static_cast<constchar*>(srcifpdest>psrc&&pdest<psrc+count){for(size_ti=count-1;i!=-1;--i)pdest[i]=psrc[i];}{for(size_ti=0;i<count;++i)pdest[i]=psrc[i];}return}intmain(void{charstr[]=" mymemcpy(str+1,str+0,9);cout<<str<<endl;system("Pause");return0;}求下面函数的返回值(int{intcountx=0;{countx++;x=x&(x-1);}return}C编程题-C写一个输入的整数,倒着输出整数的函数,答voidfun(inta{printf("%d",a%10);a/=10;if(a<=0)return;fun(a);}strcpy的函数原型:char*strcpy(char*strDestconstchar*strSrc)strDest是目的字符串,strSrcC++/C的字符串库函数,请编写函数strcpy。char*strcpy(char*strDest,constchar{if(strDest==NULL||strSrc==NULL)returnNULL;if(strDest==strSrc)returnstrDest;char*tempptr=strDestwhile((*strDest++=*strSrc++)!=;returntempptr},第一大的数为constintMINNUMBER=-32767intfind_sec_max(intdata[],int{intmaxnumber=data[0];intsec_max=MINNUMBER;for(inti=1;i<count;i++){if(data[i]>maxnumber{sec_max=maxnumber;maxnumber=data[i];}{if(data[i]>sec_max)sec_max=data[i];}}returnsec_max}nodecharval;node*next;}boolcheck(constnode*headreturnfalse:无环;true:有环,一种O(n)的办法就是(搞两个指针,一个每次递增一步,一个每次递增两步,如果有环:boolcheck(constnode*{ returnnode*low=head,*fast=head->next;while(fast!=NULL&&fast->next!=NULL){}return}一个学生的信息是:,学号,,等信息,用一个链表,把这些学生信息连在一起,给出一个age,在些链表中删除学生等于age的学生信息。#include#include"conio.h"structstu{charname[20];charsex;intno;intstructstu*structstu*creatlist(int{int//h为头结点,p为前一结点,sstructstuh=(structstu*)malloc(sizeof(structstu));h->next=NULL;{s=(structstu*)malloc(sizeof(structstu));p->next=s;printf("Pleaseinputtheinformationofthestudent:namesexnoage\n");scanf("%s%c%d%d",s->name,&s->sex,&s->no,&s->age);s->next=NULL;p=s;}}voiddeleist(structstu*s,int{structstu*p;{p=s=s-printf("Therecordisnotexist.");{p->next=s->next;printf("Deletesuccessful!");}}voiddisplay(structstu{s=s->next;{printf("%s%c%d%d\n",s->name,s->sex,s->no,s->age);s=s->next;}}int{structstu*s;intn,age;printf("Pleaseinputthelengthofseqlist:\n");s=creatlist(n);printf("Pleaseinputtheage:\n");return0;}#include#includevoiduppers(char*s,char{{*us=*s-32;*us=}*us=}int{char*s,*us;charprintf("Pleaseinputastring:\n");s=ss;printf("Theresultis:\n%s\n",us);}#include<stdio.h>voidmain(){inti=60;intj=50;}//a=a+b-unsignedintintvert(unsignedintx,intp,intn)x的进行转换,p为起始转化位,nunsignedintintvert(unsignedintx,intp,intn){unsignedint_t=0;unsignedint_a=1;for(inti=0;i<n;++i){_t|=_a=_a<<}_t=_t<<p;x^=_t;returnx;}字.o(N)函数原型:intdo_dup(inta[],int三:C++基usingnamespacestd;classB{virtualvoidclassD:publicB{voidfun1(B*ptr){ptr->show();}voidfun2(B&ref){ref.show();}voidfun3(Db){b.show();}intBb,*p=newDfun1(p);//Dfun2(b);fun3(d);//B—虽然实参是子类对象,但是fun3的参数是基类对象, return} usingnamespacestd;classC1{classC2:publicC1{intC2cb2;C1*cb1;return} B. C. D. usingnamespacestd;intmain(){char*a[]={"o","the","word"};a+char**p=a;return0;} B. C. D.usingnamespacestd;classP{
charP(char*name="未知名称"){}"classB:publicP{B(char*"voidshowP(P}intBbook("人生");return0;}运行时的输出结果是书:人 usingnamespacestd;classBASE{char
BASE(charn):c(n){}virtual~BASE(){cout<<c;}classDERIVED:publicBASE{charc;
DERIVED(charintDERIVEDreturn}XYusingnamespacestd;classXCF{
int1:XCF(intaa=0):a(aa){cout<<"1";}2:XCF(XCF&x){a=x.a;cout<<"2";}intGeta(){returna;}intXCF*pd=newXCF(8);1deletepd;return0;}运行时的输出结果是Aab同时为正或同时为负的逻辑表达式是(D。D、class{virtualvoidfunc1();voidfunc2();}ClassB:class{voidfunc1(){cout<<"fun1inclassB"<<endl;}virtualvoidfunc2(){cout<<"fun2inclassB"<<endl;}}A,Afunc1Bfunc2都是虚函数.BAfunc1Bfunc2都不是虚函数.CAfunc2是虚函数.,Bfunc1不是虚函数.D,Afunc2不是虚函数,Bfunc1是虚函数.(A,B,D三目运算符“以下有关C++C相对于C中整数类型的枚举,C++CC++可以,只要它们能构成重载且无歧CC++则是动态类型语言,但它们都属于强类型语言namespacens1{voidfoo(intn){cout<<"ns1:"<<n<<}}namespacens2voidfoo(doubled)cout<<"ns2:"<<d<<}}intmain(void){intn=10;doubled=1.23;usingnamespacens1;usingnamespacens2;foo(n);foousingns1::foo;foo(n);foousingns2::foo;foo(n);foo(d);return0;}ns1:ns2:ns1:ns2:ns1:ns2:ns1:ns2:ns1:ns1:ns1:ns2:ns1:ns2:ns1:ns1:ns2:ns2:ns2:ns2:ns1:ns1:ns2:ns2:正确答案intfoo(intn=10)return doublefoo(intn,doubled=1.23)return intmain(void)intdoublen=foon=food=food=foo(10,return15 行 正确答案以下有关指针和两种数据类型的比较,不正确的说法与指针的指针和指针数组不同,的和数组,甚至的指针都是不合与空指针和void型指针一样,也可以空和void型与向数组指针一,也可指数组的,但后保留了组的尺信息与指向函数的指针一样,也可以指向函数的,但对后者的解将导致其被隐正确答案在以下有关C++classUser{User(void):m_age(0),m_sex(true){}User(conststring&name,intage=0)m_name(name),m_age(age),m_sex(true){}User(conststring&name,intage,boolsex):m_name(name),m_age(age),m_sex(sex){}User(constUser&user)stringm_name;intm_age;boolm_sex 可以成功创建user对象UseruserUseruserUseruser=User("zhangtao",Useruser("liufei",28,正确答案下面的代码意在实现一个字符串类String,其内部需要动态一个内存缓冲区,以容classString{String(constchar*psz=NULL):m_psz ①)~String(void) String(constString&that):m_psz( ③)){}String&operator=(constString&rhs){ char*m_psz;};strcpy(newchar[strlen(psz?psz:"")+1],psz?psz:newchar[strlen(psz?psz:"")+strcpy(m_psz,psz?psz:psz?psz:正确答案A.m_psz=B.deleteC.deletem_psz正确答案A.that.m_pszthat.m_pszB.strcpy(m_psz,that.m_psz?that.m_psz:C.newchar[strlen(that.m_psz?that.m_psz:"")+D.strcpy(newchar[strlen(that.m_psz?that.m_psz:"")+1],that.m_psz?that.m_psz:"")正确答案A.m_pszrhs.m_psz;return*this;B.if(&rhs!=this)char*psz=newchar[strlen(rhs.m_psz)+1];delete[]m_psz;m_psz=strcpy(psz,}returnC.strcpy(m_psz,rhs.m_psz);returnD.char*psz=newchar[strlen(rhs.m_psz)+1];delete[]m_psz;m_psz=strcpy(psz,rhs.m_psz);return*this;正确答案下面的代码意在模拟一个银行的过程。Account类(代表账户)内部一个指向Bank类(代表银行)m_bank。AccountBank类的alloc接口,获取并初始化账号m_num。Bank类内部一个账户计数器m_accs,并alloc执行期间对该计数器累加,以确保账号唯一。classBankBank(void):m_accs(1000)intalloc(void)return}int classAccountAccount(void):m_num(m_bank->alloc())voidprint(void)cout<<m_num<< intstaticBank* AccountBank*Account::m_bank=newintmain(void)Accountacc_1,acc_2,acc_1.printacc_2.printacc_3.printg_acc.printreturn} 行,应按②修改,修改后运行,输出为③ 正确答案2112行修改为:Accountvoidm_banknewBankm_numm_bankalloc()){}2118行修改为:staticBank*m_banknew17182021行的顺序正确答案classclassNotify{Notify(Target*target,bool(Target::*callback)(int)):m_target(target),m_callback(callback){}boolrelease(intevent)①}②classTarget{Target(void):m_notify(newNotify ③ ④))~Target(void){deletem_notify;}Notify*getNotify(void){returnm_notify;}boolonNotify(intevent){cout<<event<<endl;…return}Notify*m_notify;};classSource{public:Source(void):m_notify(NULL){}voidsetNotify(Notify*notify){m_notify=notify;}voidrun(void)…m_notify->release…m_notify->release…}Notify*m_notify;};intmain(void){Targettarget;Sourcesource.setNotify(target.getNotify());source.run();return}returnm_callbackreturn(m_target->*m_callback)return(m_target->m_callback)正确答案bool(*m_callback)正确答案A.newTarget正确答案正确答案以下运算符 classInteger{Integer(intdata=0):m_data(data){}Integeroperator+(constInteger&i)const{returnInteger(m_data+}Integeroperator-(void)const{returnInteger(-m_data);}Integer&operator+=(constInteger&i){m_data+=i.m_data;return}Integer&operator++(int){return}int… 正确答案下面的代码意在实现一个可某种类型数据元素的数组容器。请将其中缺失的部分补typedef…TYPE;#defineSIZE256classArray{ operator[](size_ti){returnm_data[i];} operator[](size_ti)const{returnm_data[i];}TYPE…B.constTYPE正确答案B.constTYPE正确答案RGBm_r、m_g、m_b三个0~255范围内的整COLORREFColorRGB类型之间提供隐式转换的方法,以方便使用。请将typedefunsignedintCOLORREF;classColorRGB{ColorRGB(unsignedcharr,unsignedcharg,unsignedcharb):m_r(r),m_g(g),m_b(b){}ColorRGB(COLORREFcr) ②}unsignedcharm_r,m_g,…m_b(cr),m_g(cr>>8),m_r(cr>>m_r(cr),m_g(cr>>8),m_b(cr>>m_b(cr),m_g(cr<<8),m_r(cr<<m_r(cr),m_g(cr<<8),m_b(cr<<正确答案return(((((COLORREF)m_b)<<8)+m_g)<<8)+return(((((COLORREF)m_r)<<8)+m_g)<<8)+return(((((COLORREF)m_b)>>8)+m_g)>>8)+return(((((COLORREF)m_r)>>8)+m_g)>>8)+正确答案typedef…classSmartPointer{explicitSmartPointer(TYPE*p=NULL):m_p(p)~SmartPointer(void){if(m_p)}SmartPointer(SmartPointer&that):m_p(that.release()){}SmartPointer&operator=(SmartPointer&rhs){if(&rhs!=reset(rhs.release());return*this;} ②} ④}TYPE*release(void){TYPE*p=m_p;m_p=NULL;returnp;}voidreset(TYPE*p){if(p!=m_p){deletem_p;m_p=p;}}TYPE*正确答案returnreturnreturnreturn正确答案正确答案returnreturnreturnreturn正确答案在一个子类对象的实例化过程中,构造函数的执行顺序是DclassVisitor{virtualboolvisit(int //virtualboolvisit(double //classValidVisitor:publicVisitor{boolvisit(int //classMyValidVisitor:publicValidVisitor{boolvisit(double //4个版本的visit 关系正确答案 关系 关系 关 关系classDog{Dog(intage=0):m_age(age){}virtual~Dog(void){}friendostream&operator<<(ostream&os,constDog&dog){returnos<<dog.m_age; intclassChihuahua:publicDog{Chihuahua(intage=0,constchar*name=NULL) ①m_name(strcpy(newchar[strlen(name?name:"")+1],name?name:""))~Chihuahua(void){}Chihuahua(constChihuahua&chh) ②m_name(strcpy(newchar[strlen(chh.m_name?chh.m_name:"")+1],chh.m_name?chh.m_name:"")){}Chihuahua&operator=(constChihuahua&chh){if(&chh!=this){③char*name=strcpy(newchar[strlen(chh.m_name?chh.m_name:"")+1],chh.m_name?chh.m_name:"");delete[]m_name;m_name=}return}friendostream&operator<<(ostream&os,constChihuahua&chh){returnos<< <<","<<chh.m_name;}char*m_ageDogDog正确答案 空m_ageDogDog正确答案 B.m_age=chh.m_ageC.Dog::operator=(chh)D.static_cast<Dog>(*this)=chh 空static_cast<constDog&>(chh)C.((Dog*)&chh)->m_age正确答案classBase{Base(void):m_buf(newchar[1024])~Base(void){release();}virtualvoidrelease(void){if(m_buf){delete[]m_buf;m_buf=NULL;}}char*classDerived:publicBase{Derived(void):m_data(newint[256])~Derived(void){release();}voidrelease(void){if(m_data){delete[]m_data;m_data=NULL;}}int*intmain(void)Base*base=newDerived;deletebase;return}在上面的代码中,deletebaseBase类的析构函数被调用,该析构函数会调用虚函数m_datam_buf,成述论点是否正确?正确答案StackUnderflowex("whenpop");throwthrownewStackUnderflow("whenthrowStackUnderflow("when正确答案classException{virtualvoidupdate(void)throw();//Updatethestatusofexception…classOutofMemory:publicException{voidupdate(void)throw…以及可能异常的函数voidprocess(void)…throwOutofMemory…}try{process();}catch(Exceptionex)ex.update();}try{process();catch(OutofMemoryex)…ex.update();}try{process();catch(Exception&ex)…}try{process();catch(Exception&ex){…}catchOutofMemory&ex设有intx=123,语 “”cout<<setw(8)<<showpos<<x<<cout<<setw(8)<<showpos<<internal<<x<<cout<<setw(8)<<showpos<<left<<x<<cout<<showpos<<internal<<x<<正确答案//密钥:单字节伪随机整数[0//加密:密文字节=明文字节^//:明文字节=密文字节^密constsize_tBUFSIZE=intXor(constchar*pszSrc,constchar*pszDst,unsignedcharucKey){ifstreamifs( ①);if(!ifs)cout<<"Unabletoopen"<<pszSrc<<endl;return-1;}ofstreamofs( ②);if(!ofs){cout<<"Unabletoopen"<<pszDst<<endl;ifs.close();return-}char*pcBuf=NULL;try{pcBuf=new}catch(bad_alloc&ex)cout<<ex.what()<<endl;ofs.close();ifs.close();return-1;}while(ifs.read ③))for(inti=0;i<BUFSIZE;i++)pcBuf[i]^=ucKey; ④}if(!ifs.eof cout<<"Unabletoread"<<pszSrc<<endl;delete[]pcBuf;ifs.close();return-1;}for(size_ti=0;i<ifs.gcount();i++)pcBuf[i]^=ucKey;ofs.write( ⑤);delete[]pcBuf;ofs.close();ifs.close();return0;}intEncrypt(constchar*pszPlain,constchar*pszCipher){srand(time(NULL));unsignedcharucKey=rand()%256;if(Xor( ⑥)<0)return-cout<<"Key:"<<(unsignedint)ucKey<<endl;return0;}intDecrypt(constchar*pszCipher,constchar*pszPlain,unsignedcharucKey){returnXor( ⑦);}intmain(intargc,char*argv[]){if(argc<3){cout<<"Usage:"<<argv[0]<<"<plain_file><cipher_file>"<<endl;cout<<"Usage:"<<argv[0]<<"<cipher_file><plain_file><key>"<<endl;return-1;}if(argc<returnEncrypt(argv[1],argv[2]);returnDecrypt(argv[1],argv[2],atoi(argv[3]));return0;}B.pszDst,ios::binary正确答案B.pszDst,ios::binary正确答案A.pcBuf,BUFSIZEB.pcBuf,sizeof(pcBuf)正确答案A.pcBuf,BUFSIZEB.pcBuf,sizeof(pcBuf)C.pcBuf,strlen(pcBuf)正确答案A.pcBuf,BUFSIZEB.pcBufsizeofpcBuf)C.pcBuf,strlen(pcBuf)D.pcBuf,ifs.gcount()A.pszSrc,pszDst,ucKeyB.pszCipher,pszPlain,ucKeyC.pszDst,pszSrc,ucKeyD.pszPlain,pszCipher,ucKeyA.pszSrc,pszDst,ucKeyB.pszCipher,pszPlain,ucKeyC.pszDst,pszSrc,ucKeyD.pszPlain,pszCipher,ucKeyC++I/O流:I/O流顶级类是I/O输出类是I/OI/OI/O在队列第i个元后插入一个元p所指向的结点后面插入指针qp=q;p-B.p->next=q;q->next=p;正确答案structnode{intdata;structnode*structnode*func_1(structnode*head,intdata){if(!head)if(head=(structnode*)calloc(1,sizeof(structnode)))head->data=data;elsestructnode*for(p=head;p->next;p=p->if(p->next=(structnode*)calloc(1,sizeof(structnode)))p->next->data=data;}return}structnode*func_2(structnode*head){if(head&&head->next){structnode*this=structnode*next=this->next;head=func_2(next);next->next=this;this-
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年山东省安丘市高三数学下册期末考试模拟检测卷附参考答案(精练)
- 2026年江西省德兴市高三数学下册期末考试模拟考试卷附答案(满分必刷)
- 2025-2026学年对韵歌说课稿博客
- 2025-2026学年50米公开课说课稿
- 2025-2026学年七年级的数学说课稿
- 2025-2026学年初中历史北宋的政治说课稿
- 2025-2026学年中学生法制教育说课稿
- 2025-2026学年5以内分解与组成说课稿
- 2025-2026学年2013译林牛津英语8aunit7说课稿
- 2025-2026学年大蒜延伸课程说课稿
- 1.2数据的计算课件-高中信息技术必修一
- 数字音频处理器培训课件
- 云南劳动合同续签协议书
- 《钢结构设计原理》课件 第6章 拉弯和压弯构件
- 《宫颈癌的早期诊断》课件
- 气道管理及呼吸支持
- 借款担保人协议书
- 人教版中考物理复习第三章物态变化教学课件
- DBJ52T 088-2018 贵州省建筑桩基设计与施工技术规程
- 看图猜词游戏规则模板
- 发票开具协议书范本
评论
0/150
提交评论