全国计算机等级考试三级网络技术机试真题2006年4月
(总分100, 做题时间90分钟)
上机题

1. 
函数ReadDat()用于实现从文件ENG.IN中读取一篇英文文章,并将其存入字符串数组xx中。请编制函数encryptChar0(),按给定的替代关系对数组xx中所有的字符进行替代,结果仍存入字符串数组xx的对应位置上,最后调用函数WriteDat()把结果艇输出到文件PS3.DAT中。
   替代关系:f(p)=p*17 mod 256(p是数组中某一个字符的ASCⅡ值,f(p)是计算后新字符的ASCⅡ值)。如果计算后f(p)的值小于32或其ASCⅡ值是奇数,则该字符不变,否则将f(p)所对应的字符进行替代。
   原始数据文件的格式是:每行的宽度均小于80个字符。
   注意:部分源程序给出如下。
   请勿改动主函数main()、读数据函数ReadDat()和输出数据函数WriteDat()的内容。
   [试题源程序]
   #include<stdio.h>
   #include<string.h>
   #include<conio.h>
   #include<ctype.h>
   unsigned char xx[50][80];
   int maxline=0;/*文章的总行数*/
   int ReadDat(void);
   void WriteDat(void);
   void encryptChar()
   
   void msin()
   system("cls");
   if(ReadDat())
   
   printf("数据文件ENG.IN不能打开!\n\007");
   return;
   
   encryptChar();
   writeDat();
   
   int ReadDat(void)
   
   FILE *fp;
   int i=0;
   unsigned char *p;
   if((fp=fopen("eng.in","r"))==NULL) return 1;
   while(fgets(xx[i],80,fp)!=NULL)
   
   p=strchr(xx[i],'\n');
   if(p)*p=0;
   i++;
   
   maxline=i;
   fclose(fp);
   return 0;
   
   void WriteDat(void)
   
   FILE *fp;
   int i;
   fp=fopen("ps.dat","w");
   for(i=0;i<maxline;i++)
   
   printf("%s\n",xx[i]);
   fprintf(fp,"%s\n",xx[i]);
   
   fclose(fp);
   

答题卡