安徽省池州市技术学院信息技术系计算机省四级考试c语言上机考试试题及参考答案内容摘要:

要定义其他变量或数组。 (34分 ) include define N 8 typedef struct {char num[10]。 float score[N]。 float ave。 }STREC。 PRINT(float a) {FILE *out。 池州职业技术学院信息技术系 计算机省四级上机全真试题 邹汪平 11 if((out=fopen(C:\\40202001\\,w+))!=NULL) fprintf(out,ave=%,a)。 fclose(out)。 } main() {int i。 STREC st={J1003,76,89,98,99}。 void fun(STREC *p)。 fun(amp。 st)。 printf(The %s39。 s student scores:\n,)。 for(i=0。 iN。 i++)printf(%,[i])。 printf(\nave=%\n,)。 PRINT()。 } void fun(STREC *p) {int i。 float av。 av=0。 for(i=0。 i8。 i++) av+=pscore[i]。 pave=av/8。 } 模拟试题 8(完成 100 分 ): 改错 :下面程序的功能是输出字符串。 main() { char *a[]={English,Chinese,American,French}。 char *p。 /*$ERROR1$*/ char **p int j=0。 p=a。 for(。 j=4。 j++) /*$ERROR2$*/ for(。 j=3。 j++) printf(%s\n,*p )。 /*$ERROR3$*/ printf(%s\n,*p++ )。 } 程序填空 :下面的程序把从键盘输入的字符存放到一个文件中 ,以字符 ‟‟结束输入 ,文件名用字符数组输入 ,请填空。 include main() {char ch,fname[10]。 ________。 /*$BLANK1$*/ FILE *fp。 printf(Input the name of file\n)。 gets(fname)。 池州职业技术学院信息技术系 计算机省四级上机全真试题 邹汪平 12 if((fp=fopen(________))==NULL) /*$BLANK2$*/ fname, w {printf(Cannot open this file!\n)。 exit(0)。 } while((ch=getchar())!=39。 39。 ) fputc(_______)。 /*$BLANK3$*/ ch,fp fclose(fp)。 } 程序填空 :删除字符串 ”***A*BC*DEF*G***”中前面的全部 ‟*‟字符 ,然后输出。 尾部和中间的 ‟*‟字符不删除。 include PRINT(char s[]) { FILE *out。 if((out=fopen(C:\\40202001\\,w+))!=NULL) fputs(s,out)。 fclose(out)。 } char s[]=***A*BC*DEF*G***。 main() {int i,j。 i=0。 while(s[i++]==39。 *39。 )。 for(j=i1,i=0。 s[j]!=39。 \039。 i++,j++)s[i]=s[j]。 s[i]=39。 \039。 printf(%s\n,s)。 PRINT(s)。 } 模拟试题 9(完成 100 分) : 改错 :下面程序是将指定的源文件 (yuan)中的内容复制到指定的目标文件 (mubiao)中 ,请改错。 (30 分 ) include include main() { FILE *fp1,*fp2。 char c。 fp1=fopen(yuan,r)。 fp2=fopen(mubiao,r)。 /*$ERROR1$*/ fp2=fopen(mubiao,w)。 c=fgetc(fp1)。 while(!feof(fp2)) /*$ERROR2$*/ while(!feof(fp1)) { putchar(c)。 putc(fp2)。 /*$ERROR3$*/ fputc(c,fp2)。 c=fgetc(fp1)。 池州职业技术学院信息技术系 计算机省四级上机全真试题 邹汪平 13 } fclose(fp1)。 fclose(fp2)。 } 程序填空 :以下函数 acopy 的功能是 ,将整型数组 a 的内容按逆序复制到整型数组 b 之中 (999 为数组的结束标志 ),请填空。 (30分 ) include void acopy(_______) /*$BLANK1$*/ int a[ ] , int b[ ] { int i=0,j=0。 while(*(a+j)!=999) j++。 b[j]=a[j]。 j。 while(a[i]!=999) { ________。 /*$BLANK2$*/ b[j]=a[i]。 i++。 j。 } } main() { static int a[]={1,3,5,7,9,2,4,6,8,10,999}。 int b[80],i=0。 acopy(a,b)。 while(b[i]!=999) printf(%3d,_____)。 /*$BLANK3$*/ b[i++] } 程序设计 :编写程序中求两个复数和的函数 fun。 请不要定义其它变量或数组。 (40 分 ) include struct p {int x, y。 }。 void PRINT(struct p n) {FILE *out。 if((out=fopen(C:\\40202001\\,w+))!=NULL) fprintf(out,=%d,=%d,)。 fclose(out)。 } main( ) { struct p fun(struct p,struct p)。 struct p a,b,c。 =1。 =2。 =3。 =4。 c=fun(a,b)。 printf(=%d,=%d\n,)。 PRINT(c)。 } 池州职业技术学院信息技术系 计算机省四级上机全真试题 邹汪平 14 struct p fun(struct p u, struct p v) { struct p w。 =+。 =+。 return (w)。 } 模拟试题 10(完成 77 分) : 改错 :下列程序中函数 month_name的功能是 :输入 1~12 之间的整数 ,输出对应的月份名 ,请改错。 ( 30 分) include char *month_name(char *name[],int n) { char *p1,*p2。 p1=name。 /*$ERROR1$*/ p1=*name。 p2=name+n。 /*$ERROR2$*/ p2=*(name+n) return((n1||n12)?p1:p2)。 } main() { char *name[] ={Illegalmonth,January,February,March, April,May,June, July,August,September, October,November,December}。 char *ps。 int i。 printf(Input Month No:\n)。 scanf(%d,amp。 i)。 if(i0)exit(1)。 ps=month_name(*name[],i)。 /*$ERROR3$*/ ps=month_name(name,i) printf(Month No:%2d%s\n,i,ps)。 } 程序填空 :以下程序实现将键盘输入的一些字符 (以 ‟‟结束 )追加到以文本文件。 ( 30分) include main() {char c。 _________。 /*$BLANK1$*/ FILE *fp。 if ((fp=fopen(,____))==NULL) /*$BLANK2$*/ a {printf(can not open file !)。 exit(1)。 } while((c=getchar())!=39。 39。 ) fputc(_________)。 /*$BLANK3$*/ c,fp fclose(fp)。 } 程序设计: 用指针方法 统计字符串 ”this is a beg we are student”中单词的个数。 规定单词由小写字母组成 ,单词之间由池州职业技术学院信息技术系 计算机省四级上机全真试题 邹汪平 15 空格分隔 ,字符串开始和结束没有空格。 (17 分 ) include PRINT(int n) { FILE *out。 if((out=fopen(C:\\40202001\\,w+))!=NULL) fprintf(out,n=%d,n)。 fclose(out)。 } main() {char s[]=this is a beg we are students。 int n。 int i=0。 char *p p=s。 n=1。 while(*p!=39。 \039。 ) {if(*p==39。 39。 )n++。 p++。 } printf(%d\n,n)。 PRINT(n)。 } 模拟试题 11: 改错:将键盘输入的数据存入整型数组a中,然后输出到文件 中,请改错。 include main() {FILE *fp。 int a[10],i。 if((fp=fopen(, wb))==NULL) {printf(Can39。 t open file.\n)。 exit(0)。 } for(i=0。 i10。 i++) scanf(%d,a[i])。 /*$ERROR1$*/ scanf(%d,& a[i]) fwrite(fp,a,2,10)。 /*$ERROR2$*/ fwrite(a,2,10,fp) fclose()。 /*$ERROR3$*/ } fclose(fp) 程序填空:从键盘输入 字符 串 ,以回车结束.通过指针操作,将所有大写字母转换为小写字母,其它字符不变,请填空. include main() {int i=0。 char s[80],*p。 printf(INPUT STRING:\n)。 池州职业技术学院信息技术系 计算机省四级上机全真试题 邹汪平 16 while((s[i]=getchar())___39。 \n39。 ) /*$BLANK1$*/ != i++。 p=s。 while(___!=39。 \n39。 ) /*$BLANK2$*/ *p {if(*p=39。 A39。 amp。 am。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。