全國計算機等級考試三級C語言上機題36-40

字號:

★題目36
    函數ReadDat()實現(xiàn)從文件ENG.IN中讀取一篇英文文章,存入到字符串數組xx中;請編制函數encryptChar(),按給定的替代關系對數組xx中的所有字符進行替代,仍存入數組xx的對應的位置上,最后調用函數WriteDat()把結果xx輸出到文件pS6.DAT中。
    替代關系:f(p)=p*11 mod 256(p是數組中某一個字符的ASCII值,f(p)是計算后新字符的ASCII值),如果計算后f(p)值小于等于32或f(p)對應的字符是數字0至9,則該字符不變,否則將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[j]*11%256<=32||xx[j]*11%256>='0'&&xx[j]*11%256<='9') continue;
    else xx[j]=xx[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,80,fp)!=NULL){
    p=strchr(xx,'\n');
    if(p)*p=0;
    i++;
    }
    maxline=i;
    fclose(fp);
    return 0;
    }
    void WriteDat(void)
    {
    FILE *fp;
    int i;
    fp=fopen("ps6.dat","w");
    for(i=0;i    printf("%s\n",xx);
    fprintf(fp,"%s\n",xx);
    }
    fclose(fp);
    }
    題目37
    函數ReadDat()實現(xiàn)從文件ENG.IN中讀取一篇英文文章,存入到字符串數組xx中;請編制函數encryptChar(),按給定的替代關系對數組xx中的所有字符進行替代,仍存入數組xx的對應的位置上,最后調用函數WriteDat()把結果xx輸出到文件PS7.DAT中。
    替代關系:f(p)=p*11 mod 256(p是數組中某一個字符的ASCII值,f(p)是計算后新字符的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[j]*11%256<=32||xx[j]>='A'&&xx[j]<='Z') continue;
    else xx[j]=xx[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,80,fp)!=NULL){
    p=strchr(xx,'\n');
    if(p)*p=0;
    i++;
    }
    maxline=i;
    fclose(fp);
    return 0;
    }
    void WriteDat(void)
    {
    FILE *fp;
    int i;
    fp=fopen("ps7.dat","w");
    for(i=0;i    printf("%s\n",xx);
    fprintf(fp,"%s\n",xx);
    }
    fclose(fp);
    }