网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)
阅读以下说明和C程序,将应填入 (n) 处的字句写在对应栏内。 2、【说明】下面的程序按照以下规则输出给定名词的复数形式。 a.若名词以“y”结尾,则删除y并添加“ies”; b.若名词以“s”、“ch”或“sh”结尾,则添加“es”; c.其他所有情况,直接添加“s”。【C程序】 #include <stdio.h> #include <string.h> char*plural(char *word) { int n; char *pstr; n=strlen(word); /*求给定单词的长度*/ pstr=(char*)malloc(n+3);/*申请给定单词的复数形式存储空间*/ if (!pstr||n<2) return NULL; strcpy(pstr,word); /*复制给定单词*/ if ( (1) ) { pstr[n-1]='i';pstr[n] ='e';pstr[n+1]='s'; (2) ; } else if(pstr[n-1]=='s'| |pstr[n-1]=='h'&&( (3) )) { pstr[n]='e';pstr[n+1]='s';pstr[n+2]='\0'; } else { pstr[n]='s';pstr[n+1]='\0';) (4) ; } main() { int i; char *ps; char wc[9][10]= {"chair","dairy","boss","circus","fly","dog","church","clue","dish"); for(i = 0;i<9; i++) { ps= (5) ; printf("%s: %s\n",wc[i],ps); /*输出单词及其复数形式*/ free(ps); /*释放空间*/ } system("pause"); }


参考答案

参考解析
解析:(1)pstr[n-1]='y',或*(pstr+n-1)=='y',或其等价表示 (2)pstr[n+2]='\0',或*(pstr+n+2)='\0',或其等价表示 (3)pstr[n-2]='c'||pstr[n-2]='s',或其等价表示 (4)return pstr (5)plural(wc[i]),或其等价表示
【解析】

本题考查C程序设计基本能力和字符串处理基本操作。 C程序中字符串存储在字符数组中,串的结尾需要设置结束标志符号'\0'。若已知串 pstr的长度为n(不包括结束标志),则串中的字符依次存储在pstr[0],pstr[1],...,pstr[n-1]中。因此,名词的最后一个字符pstr[n-1]若等于字符“y”,则按照规则a求其复数形式。下面的if语句处理的是以“y”结尾的名词,因此,空(1)处应填入“pstr[n-1]='y'”或其等价形式。由于串pstr的长度发生了变化,所以需要设置新的结束标志,空(2)处应填入“pstr[n+2]='\0'”’或其等价形式。 if( (1) ) { pstr[n-1]= 'I'; pstr[n]= 'e'; pstr[n+1] = 's'; (2) ; } 显然,下面的if语句处理规则b所示的情况,即串的末尾为“s”、“ch”或“sh”的情形,空(3)处应填入“pstr[n-2]='c'||pstr[n-2]='s”或其等价形式。 if(pstr[n-1]=='s'||pstr[n-1]=='h' && ( (3) )) { pstr[n] = 'e'; pstr[n+1] ='s'; pstr[n+2]='\0'; } 根据函数“char *plural(char *word)”的定义,最后应将求得的给定名词的复数形式返回给主调函数mae,对于串,应返回串空间的首地址,即返回指针pstr,因此空(4)处应填入“return pstr”。 根据以下代码,空(5)处应调用函数plural(char*word)对指定名词求复数,数组 WC初始化时已设置了名词序列,因此,空(5)处应填入“plural(wc[i])”。 for(i = 0; i < 9; i++) { ps= (5) ; printf("%s: %s\n",wc[i],ps); /*输出单词及其复数形式*/ free(ps); /*释放空间*/ }
更多 “阅读以下说明和C程序,将应填入 (n) 处的字句写在对应栏内。 2、【说明】下面的程序按照以下规则输出给定名词的复数形式。 a.若名词以“y”结尾,则删除y并添加“ies”; b.若名词以“s”、“ch”或“sh”结尾,则添加“es”; c.其他所有情况,直接添加“s”。【C程序】 #include <stdio.h> #include <string.h> char*plural(char *word) { int n; char *pstr; n=strlen(word); /*求给定单词的长度*/ pstr=(char*)malloc(n+3);/*申请给定单词的复数形式存储空间*/ if (!pstr||n<2) return NULL; strcpy(pstr,word); /*复制给定单词*/ if ( (1) ) { pstr[n-1]='i';pstr[n] ='e';pstr[n+1]='s'; (2) ; } else if(pstr[n-1]=='s'| |pstr[n-1]=='h'&&( (3) )) { pstr[n]='e';pstr[n+1]='s';pstr[n+2]='\0'; } else { pstr[n]='s';pstr[n+1]='\0';) (4) ; } main() { int i; char *ps; char wc[9][10]= {"chair","dairy","boss","circus","fly","dog","church","clue","dish"); for(i = 0;i<9; i++) { ps= (5) ; printf("%s: %s\n",wc[i],ps); /*输出单词及其复数形式*/ free(ps); /*释放空间*/ } system("pause"); }” 相关考题
考题 ●试题二阅读下列程序或函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【函数2.1说明】函数strcmp()是比较两个字符串s和t的大小。若s<t函数返回负数;若s=t函数返回0;若s>t,函数返回正数。【函数2.1】int strcmp(char *s,char *t){ while(*s *t (1) ){s++;t++;}return (2) ;}【程序2.2说明】在n行n列的矩阵中,每行都有最大的数,本程序求这n个最大数中的最小一个。【程序2.2】#includestdio.h#define N 100int a[N][N];void main(){ int row ,col,max,min,n;/*输入合法n(<100),和输入n×n个整数到数组a的代码略*/for (row=0;row<n;row++){for(max=a[row][0],col=1;col<n;col++)if( (3) )max=a[row][col];if( (4) )min=max;else if( (5) )min=max;}printf ("The min of max numbers is %d\n",min);}

考题 阅读下列程序段,则程序的输出结果为 #include"stdio.h" #defineM(X,Y)(X)*(Y) #defineN(X,Y)(X)/(Y) main() {f int a=5,b=6,c=8,k; k=N(M(a,b),c); printf("%d\n",k);}A.3B.5C.6D.8

考题 阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include include 阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include < stdio. h >include < string. h >define Max 1000class Bank{int index;char date [Max] [10]; // 记录交易日iht amount[Max]; // 记录每次交易金额,以符号区分存钱和取钱int rest[ Max]; // 记录每次交易后余额static iht sum; // 账户累计余额public:Bank( ) {index =0;}void deposit( char d[ ] , int m) //存入交易{strcpy ( date [ index ], d);amount[ index] = m;(1);rest[ index] = sum;index++;}void withdraw (char d[ ], int m) //取出交易{strcpy( date[ index] ,d);(2);(3);rest[ index] = sum;index++;}void display( );};int Bank:: sum = 0;void Bank:: display ( ) //输出流水{int i;printf("日期 存入 取出 余额\n");for (4){printf(" %8s" ,date[i] );if (5)printf(" %6d" , -amount[i] );elseprintf( "%6d ",amount[i] );printf( "% 6d\n" ,rest[i] );} }void main( ){Bank object;object. deposit ( "2006.2.5", 1 00 );object. deposit( "2006.3.2" , 200);object. withdraw( "2006.4.1", 50);object. withdraw( "2006.4.5", 80);object. display ( );}本程序的执行结果如下:日期 存入 取出 余额 2006.2.5 100 1002006.3.2 200 3002006.4.1 50 2502006.4.5 80 170

考题 若执行下列的程序时,从键盘上输入1和2,则输出结果是()。includemain(){int a,b,s; scan 若执行下列的程序时,从键盘上输入1和2,则输出结果是( )。 #include<stdio.h> main() { int a,b,s; scanf("%d%d",a,b); s=a; if(a<b)s=b; s=s*s; printf("%d\n",s); }A.1B.4C.2D.9

考题 试题二(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。[说明]下面的程序按照以下规则输出给定名词的复数形式:a. 若名词以“y”结尾,则删除 y 并添加“ies” ;b. 若名词以“s” 、 “ch”或“sh”结尾,则添加“es” ;c. 其他所有情况,直接添加“s” 。[C 程序]#include stdio.h#include string.hchar *plural(char *word){int n;char *pstr;n = strlen(word); /*求给定单词的长度*/pstr = (char *)malloc(n+3); /*申请给定单词的复数形式存储空间*/if (!pstr || n 2)return NULL;strcpy(pstr,word); /*复制给定单词*/if ( (1) ){pstr[n-1] = 'i'; pstr[n] = 'e'; pstr[n+1] = 's'; (2) ;}elseif(pstr[n-1]=='s'||pstr[n-1]== 'h' ( (3) )){pstr[n] = 'e'; pstr[n+1] = 's'; pstr[n+2] = '\0';}else{ pstr[n] = 's'; pstr[n+1] = '\0'; }(4) ;}main( ){ int i; char *ps;char wc[9][10] ={"chair","dairy","boss","circus","fly","dog","church","clue","dish"}for(i = 0; i 9; i++) {ps = (5) ;printf("%s: %s\n",wc[i],ps); /*输出单词及其复数形式*/free(ps); /*释放空间*/}system("pause");}

考题 有以下程序:includeincludeincludevoid f(char*s,char*t){char k;k=*s; * 有以下程序: #include<stdio.h> #include<string.h> #include void f(char*s,char*t) { char k; k=*s; *s=*t; *t=k; s++;t--; if(*s)f(s,t): } main() {char str[10]="abcdefg",*P; P=str+strlen(str)/2+1: f(p,p-2); printf("%s\n",str); } 程序运行后的输出结果是( )。A.abcdefgB.gfedcbaC.gbcdefaD.abedcfg

考题 以下程序的输出结果是【】。 include include void main 0 { char s[50]; st 以下程序的输出结果是【 】。include<iostream.h>include <string.h>void main 0 {char s[50];strcpy(s[O], "No" );strcpy(s[1], "123" );strcpy (s[2], "23456" );cout<<s;}

考题 阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。【说明】编写程序,生成一个新文本文件,它由一个已知文本文件的所有偶数行组成。要求已知文本文件名和新文本文件名均从键盘输入。请填空完善程序。【C语言程序】include<stdio.h>main(){FILE *oldf,*newf;char ch,fname[20];int i;do{printf("Enter name of existed text file to be read:");scanf("%s",fname);if((oldf=fopen(fname,"r"))==NULL)printf("File %s can't open!\n",fname);}while(oldf==NULL);do{printf("Enter mane of new text file to be written:");scanf("%s",fname);if(((1)==NULL)printf("File %s can't open!\n",fname);}while((2));i=1;while(!feof(oldf)){while((ch=fgetc(oldf))!=(3)){if(i%2==(4))fputc(ch,newf);}fputc('\n',newf);(5);}fclose(oldf);fclose(newf);}

考题 当执行下面的程序时,如果输入ABC,则输出结果是 ( ) include include 当执行下面的程序时,如果输入ABC,则输出结果是 ( ) # include<stdio.h> # include<string.h> main( ) { char ss [10] ="12345"; gets(ss);strcat(ss"6789");printf("%s\n",ss); }A.ABC6789B.ABC67C.12345ABC6D.ABC456789

考题 以下程序的输出结果是()includeincludemain(){char str[12]={'s','t','r', 以下程序的输出结果是( ) #include<stdio.h> #include<string.h> main() {char str[12]={'s','t','r','i','n','g'}; printf("%d\n",strlen(str)); }A.6B.7C.11D.12

考题 阅读以下说明和C程序,将应填入(n)处的字句写在对应栏内。【说明】下面的程序按照以下规则输出给定名词的复数形式。a.若名词以“y”结尾,则删除y并添加“ies”;b.若名词以“s”、“ch”或“sh”结尾,则添加“es”;c.其他所有情况,直接添加“s”。【C程序】include <stdio.h>include <string.h>char*plural(char *word){int n;char *pstr;n=strlen(word); /*求给定单词的长度*/pstr=(char*)malloc(n+3);/*申请给定单词的复数形式存储空间*/if (!pstr||n<2)return NULL;strcpy(pstr,word); /*复制给定单词*/if ((1)){pstr[n-1]='i';pstr[n] ='e';pstr[n+1]='s';(2);}elseif(pstr[n-1]=='s'| |pstr[n-1]=='h'((3))){pstr[n]='e';pstr[n+1]='s';pstr[n+2]='\0';}else{ pstr[n]='s';pstr[n+1]='\0';)(4);}main(){ int i; char *ps;char wc[9][10]={"chair","dairy","boss","circus","fly","dog","church","clue","dish");for(i = 0;i<9; i++) {ps= (5) ;printf("%s: %s\n",wc[i],ps); /*输出单词及其复数形式*/free(ps); /*释放空间*/}system("pause");}

考题 阅读以下说明、Java代码,将应填入(n)处的字句写在对应栏内。【说明】本程序输出10000之内的所有完全数。完全数是指等于其所有因子和(包括1,但不包括这个数本身)的数。例如:6=1×2×3,6=1+2+3,则6是一个完全数。【程序】public class PerfectNum{Public static void main(String args[]){int count=1;for(int i=1; i<10000; i++){int y=0;for(int j=1; j<i; j++)if((1))y=(2)if((3)){System.out.print( (4) +String.valueOf('\t'));(5)If(count%3==0)System.out.printin();}}}

考题 以下程序includeincludemain(){ char*pl="abc",*p2="ABC",str[50]="xyz";s 以下程序 #include<stdio.h> #include<string.h> main() { char*pl="abc",*p2="ABC",str[50]="xyz"; strcpy(str+2.strcat(p1,p2)); printf("%s\n,str); } 的输出是______。A.xyzabcABCB.zabcABCC.yzabcABCD.xyabcABC

考题 以下程序的输出结果是______。 include define FUDGE(y)2.84+y define PR(a)printf(" 以下程序的输出结果是______。 #include<stdio.h> #define FUDGE(y) 2.84+y #define PR(a) printf("%d",(int)(a)) #define PRINT() PR(s) ;putchar('\n') main() { intx=2; PRINT1 (FUDGE(5)*x); }A.11B.12C.13D.15

考题 设有下列程序: include include main() { int i; char si 10],ti 10]; gets( 设有下列程序:include<stdio.h>include<string.h>main(){ int i;char si 10],ti 10];gets(t);for(i=0;i<2;i++){ gets(s);if(strcmp(t,s)<0)strcpy(t,s);}printf("%s\n",t);}程序运行后,从键盘上输入(<CR>代表回车符):CDEF<CR>BADEF<CR>QTHRG<CR>,则程序的输出结果是______。

考题 以下程序的功能是:将输入的正整数按逆序输出。例如:若输入135则输出531。请填空。include <stdio.h>main(){ int n, s;printf("Enter a number:"); scanf("%d",n);printf("Output: ");do{ s=n%10; printf("%d",s); [ ]; }while (n!=0);printf("\n');}

考题 若执行下列的程序时,从键盘上输入1和2,则输出结果是( )。 include main(){ int a,b,s;s 若执行下列的程序时,从键盘上输入1和2,则输出结果是( )。 #include<stdio.h> main() { int a,b,s; scanf("%d%d",a,b); s=a; if(a<b) s=b; s=s*s; printf("%d\n",s); }A.1B.4C.2D.9

考题 以下程序的输出结果是_______。includemain(){char*a="abcdefghi";int k;fun(a) ;puts 以下程序的输出结果是_______。 #include<string.h> main() {char*a="abcdefghi";int k; fun(a) ;puts(a) ; } fun(char *s) { int x,y; char c; for(x=0,y=strlen(s)-1; x<y; x++,y--) { c=s[y]; s[y]=s[x];s[x]=c;} }A.ihgfedcbaB.abcdefghiC.abcdedcbaD.ihgfefghi

考题 阅读下列程序说明和C程序,将应填入(n)处的字句写在对应栏内。[函数2.1说明]下面程序的功能是计算x和y的最小公倍数。[函数2.1]main(){ int m,n,d,r;seanf("%d %d",m,n);if(m<n) {r=m;m=n;n=r;}(1);while (d%n! =0) (2);printf("%d\n",d);}[函数2.2说明]下述程序接收键盘输入,直到句点“.”时结束。输入的字符被原样输出,但连续的空格输入将转换成一个空格。[函数2.2]include <stdio.h>main(){ char c,preChar='\0';c = getchar();while(c! = '.'){if((3)) putchar(c);else if(preChar! =' ') putchar(c);(4);c=(5);}}

考题 阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】设计一个评选优秀教师和学生的程序,其类结构如图6所示。当输入一系列教师或学生的记录后,将优秀学生及教师的姓名列出来。【程序】include<iostream.h>include<stdio.h>enum boolean {False,True}class base{protected:char name[8];public:void getname() {cout<<"姓名:" ;cin>>name; }void printname() {cout<<"姓名:"<<name<<endU3virtual boolean isgood() =0;}class student:(1){int num;public:void getnum()cout<<"考试成绩:" cin>>num;boolean isgood() {return (2);{};class teacher:(3) public baseint num;public:void getnum()cout<<"每年发表论文数:" ;cin>>num;boolean isgood() {return (4);}};void main()base* p[50];student * pstud;teacher * ptech;char ch;int count =0;docout<<"输入教师(t)或学生(s):"cin>>ch;if(ch =='s'){pstud = new student;pstud ->getname();pstud ->getnum();p[count ++ ] = pstud;}else if(ch == 't'){ptech = newteacher;ptech - >getname( )ptech ->getnum();p[count++]=ptech;}elsecout<<"输入错误<<endl;cout<<"继续输入码(Y/n)";cin>>ch;} while(ch == 'y')for(int i=0;i<count;i++){if((5)) //若为优秀,则输出p[i]->printname();}}

考题 若执行下列的程序时,从键盘上输入1和2,则输出结果是()。 include main() { int a,b,s; 若执行下列的程序时,从键盘上输入1和2,则输出结果是( )。#include<stdio.h>main(){ int a,b,s;scanf("%d%d",a,B) ;S=a;if(a<B) s=b;s=s*s;printtf("%d\n",s);}A.1B.4C.2D.9

考题 有以下程序: include include void f(char * s,char*t){char k; k=*s;*s=* 有以下程序: #include <stdio.h>#include <string.h>void f(char * s,char*t){ char k; k=*s; *s=*t; *t=k; s++; t--; if( * s) f(s,t);}main( ){ char str[10] :"abedefg", * p; p = str + strlen(str)/2+1; f(p,p -2); printf( "% s \n" ,str);程序运行后的输出结果是( )。A.abcdefgB.gfedcbaC.gbcdefaD.abedcfg

考题 有以下程序:include void swap(char * x,ehar * y){ char t;t= *x; *x: *y; *y=t;main 有以下程序:#include <stdio.h>void swap(char * x,ehar * y){ char t; t= *x; *x: *y; *y=t;main ( ){ char *s1 ="abc", * s2 ="123"; swap(s1 ,s2); printf("%s,%s \n" ,s1 ,s2);}程序执行后的输出结果是( )。A.123,abeB.abe,123C.1bc,a23D.321,cba

考题 阅读下列程序段,则程序的输出结果为 #include"stdio.h" #define M(X,Y)(X)*(Y) #define N(X,Y)(X)/(Y) main() { int a=5,b=6,c=8,k; k=N(M(a,b),c); printf("%d\n",k);}A.3B.5C.6D.8

考题 以下程序的输出结果是______。 include main() { char*a="abcdefghi";int k fun(a);p 以下程序的输出结果是______。 #include <string.h> main() { char*a="abcdefghi";int k fun(a);puts(a); } fun(char*s) { int x,y; char c for(x=0,y=strlen(s)-1;x<y:x++,y--) {c=s[y];s[y]=s[x];s[x]=c;} }A.ihgfedcbaB.abcdefghiC.abcdedebaD.ihgfefghi

考题 以下程序 include include main() { char*p1="abc",*p2="ABC",str[50]="xy 以下程序 #include<stdio.h> #include<string.h> main() { char*p1="abc",*p2="ABC",str[50]="xyz"; strcpy(ar+2,strcat(p1,p2)); printf("%s\n",str); } 的输出是______。A.xyzabcABCB.zabeABCC.yzabcABCD.xyabcABC

考题 试题三(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。