您现在的位置: 中国IT实验室 >> 计算机等级考试 >> 最新试题 >> 文章正文
全国计算机等级考试三级C语言上机题11-20

ChinaITLab收集整理  2006-3-11  保存本文  推荐给好友  QQ上看本站  收藏本站


int ReadDat(void) ;
void WriteDat(void) ;

void ChA(void)
{ int i,j;
 char ch;
 for(i=0;i { ch=xx[i][0];
 for(j=0;j xx[i][j]+=xx[i][j+1];
 xx[i][strlen(xx[i])-1]+=ch;
 strrev(xx[i]);
 }
}
void main()
{
 clrscr() ;
 if(ReadDat()) {
 printf("数据文件IN.DAT不能打开!\n\007") ;
 return ;
 }
 ChA() ;
 WriteDat() ;
}

int ReadDat(void)
{
 FILE *fp ;
 int i = 0 ;
 char *p ;

 if((fp = fopen("IN.DAT", "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 ;

 clrscr() ;
 fp = fopen("OUT9.DAT", "w") ;
 for(i = 0 ; i < maxline ; i++) {
 printf("%s\n", xx[i]) ;
 fprintf(fp, "%s\n", xx[i]) ;
 }
 fclose(fp) ;
}


☆题目18
函数ReadDat()实现从文件ENG.IN中读取一篇英文文章,存入到字符串数组xx中;请编制函数encryptChar(),按给定的替代关系对数组xx中的所有字符进行替代,仍存入数组xx的对应的位置上,最后调用函数WriteDat()把结果xx输出到文件PS10.DAT中。
 替代关系:f(p)=p*11 mod 256(p是数组中某一个字符的ASCII值,f(p)是计算后新字符的ASCII值),如果原字符的ASCII值是偶数或计算后f(p)值小于等于32,则该字符不变,否则将f(p)所对应的字符进行替代。
 部分源程序存在文件prog1.c中。原始数据文件存放的格式是:每行的宽度均小于80个字符。
 请勿改动主函数main()、读数据函数ReadDat()和输出数据函数WriteDat()的内容。
#include
#include
#include
#include

unsigned char xx[50][80];
int maxline=0;/*文章的总行数*/

int ReadDat(void);
void WriteDat(void);

void encryptChar()
{ int i,j;
 for(i=0;i for(j=0;j if(xx[i][j]*11%256<=32||xx[i][j]%2==0) continue;
 else xx[i][j]=xx[i][j]*11%256;
}

void main()
 {
 clrscr();
 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("ps10.dat","w");
 for(i=0;i printf("%s\n",xx[i]);
 fprintf(fp,"%s\n",xx[i]);
 }
 fclose(fp);
}

☆题目19
编写一个函数findStr(char *str,char *substr),该函数统计一个长度为2的子字符串在另一个字符串中出现的次数。例如,假定输入的字符串为"asd asasdfg asd as zx67 asd mklo",子字符串为"as",函数返回值是6。
 函数ReadWrite()实现从文件in.dat中读取两个字符串,并调用函数findStr(),最后把结果输出到文件out.dat中。
 注意:部分源程序存在文件prog1.c中。
 请勿改动主函数main()和其它函数中的任何内容,仅在函数findStr()的花括号中填入你编写的若干语句。
#include
#include
#include

int findStr(char *str,char *substr)
{ int i,j,len1,len2,cnt=0,flag;
 len1=strlen(str);
 len2=strlen(substr);
 for(i=0;i { for(j=0;j if(str[i+j]==substr[j]) flag=1;
 else {flag=0;break;}
 if(flag==1) cnt++;
 }
 return cnt;
}

main()
{
 char str[81], substr[3] ;
 int n ;

 clrscr() ;
 printf("输入原字符串:") ;

上一页  [1] [2] [3] [4] [5] 下一页  





 相关文章  热门文章
应付计算机等级二级考试新大纲:公共基础知识
计算机等级考试三,四级证书
计算机等级考试一,二级证书
2006年4月1日计算机等级考试公共基础知识考
2006年全国计算机等级考试四级考试大纲
2006年全国计算机等级考试三级信息管理技术
2006年全国计算机等级考试二级Access考试大
全国计算机等级考试详细的介绍
全国计算机等级考试四级通关攻略
全国计算机等级考试上机考试应试技巧

 文章评论


认证培训
热门专题       more
相关下载
论坛新帖
博 客