亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2016 | 回復(fù): 4
打印 上一主題 下一主題

[C] 改客觀題給分的程序有錯,請教! [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2009-03-31 23:43 |只看該作者 |倒序?yàn)g覽
10可用積分
我要改客觀題(ABCD單選那種),情況如下:
一共有五個大題,前三題都是十個小題(題號1-10),后兩題都是五小題(題號1-5),所有小題都是2分每個。
要求:
一次性輸入學(xué)生所有的答題結(jié)果,并記錄入文件,輸出結(jié)果是學(xué)生的每個大題的得分,其中哪幾個題錯誤,這些也都寫入前面的那個文件。

我做了一個程序,如下:

/* calc mark fileops*/

#include <stdio.h>
#include <stdlib.h>

#define LEN 41
#define SIZE_A 10
#define SIZE_B  5
#define STEP 2

int main(void){
   
    char keys[LEN] = "dadacbcbadfftftttftffttttfftttbdccdabbaa";   /*所有1-40題的正確答案*/
    char ans[LEN];
    int wrng_1[SIZE_A] = {0}, wrng_2[SIZE_A] = {0}, wrng_3[SIZE_A] = {0},
        wrng_4[SIZE_B] = {0}, wrng_5[SIZE_B] = {0};                /*記錄錯誤題號的數(shù)組及其初始化*/
    int cnt = 0, sum_1, sum_2, sum_3, sum_4, sum_5;              /*記錄已處理完學(xué)生資料數(shù)目cnt和為每一題算分?jǐn)?shù)的變量sum_1-5*/
    int j;
    FILE * fwrt;
   
    if((fwrt = fopen("output.txt","a")) == NULL){
        fprintf(stderr,"Error opening file!");
        getch();
        exit(EXIT_FAILURE);
    }
    puts("\nGet started!");
    fprintf(fwrt,"\nInput the students' answers (Press Enter at the beginning "
                 "of the next line to quit):\n");
    while(gets(ans) != NULL && ans[0] != '\0'){
        sum_1 = SIZE_A * STEP; sum_2 = SIZE_A * STEP; sum_3 = SIZE_A * STEP;
        sum_4 = SIZE_B * STEP; sum_5 = SIZE_B * STEP;                                          /*每一次都將sum_1-5的滿分還原以便之后扣減*/
        fprintf(fwrt, "\nAnswers of student %d: %s", cnt+1, ans); /*記錄下學(xué)生答題的輸入序號以及答題情況*/
        for(j = 0;  j < LEN-1; j++){                             /*將學(xué)生答題與答案一個個比較*/
            if(ans[j] != keys[j]){
                if((j+1) > 0 && (j+1) <= 10){               
                    sum_1 -= STEP;
                    wrng_1[j] = j+1;
                }
                if((j+1) > 10 && (j+1) <= 20){
                    sum_2 -= STEP;
                    wrng_2[j] = (j+1) - SIZE_A;     /*因?yàn)槊恳淮箢}的題號是1-10,所以做了這樣的處理,下同*/
                }
                if((j+1) > 20 && (j+1) <= 30){
                    sum_3 -= STEP;
                    wrng_3[j] = (j+1) - (SIZE_A * 2);
                }
                if((j+1) > 30 && (j+1) <= 35){
                    sum_4 -= STEP;
                    wrng_4[j] = (j+1) - (SIZE_A * 3);
                }
                if((j+1) > 35 && (j+1) <= 40){
                    sum_5 -= STEP;
                    wrng_5[j] = (j+1) - (SIZE_A * 3 + SIZE_B);
                }
            }
        }
        fprintf(fwrt, "\nResults of Student %d:\n",cnt + 1);                   /*從此開始寫結(jié)果入文件*/
        fprintf(fwrt, "\nItem One: Mark: %d, Wrong: ",sum_1);
        for(j = 0; j < SIZE_A; j++)
            if(wrng_1[j] != 0)
                fprintf(fwrt, "%4d", wrng_1[j]);
        fprintf(fwrt, "\nItem Two: Mark: %d, Wrong: ",sum_2);
        for(j = 0; j < SIZE_A; j++)
            if(wrng_2[j] != 0)
                fprintf(fwrt, "%4d", wrng_2[j]);
        fprintf(fwrt, "\nItem Three: Mark: %d, Wrong: ",sum_3);
        for(j = 0; j < SIZE_A; j++)
            if(wrng_3[j] != 0)
                fprintf(fwrt, "%4d", wrng_3[j]);
        fprintf(fwrt, "\nItem Four: Mark: %d, Wrong: ",sum_4);
        for(j = 0; j < SIZE_B; j++)
            if(wrng_4[j] != 0)
                fprintf(fwrt, "%4d", wrng_4[j]);
        fprintf(fwrt, "\nItem Five: Mark: %d, Wrong: ",sum_5);
        for(j = 0; j < SIZE_B; j++)
            if(wrng_5[j] != 0)
                fprintf(fwrt, "%4d", wrng_5[j]);
        fprintf(fwrt,"\nInput the students' answers (Press Enter at the beginning "
                 "of the next line to quit):\n");
        cnt++;
    }
     
    fprintf(fwrt, "\n%d students' data treated till now.",cnt);
    fclose(fwrt);
    puts("\nDone!);
    getch();
    return 0;
}

程序運(yùn)行情況如下:
輸入:
Get started!
cabaabccdaftttfttfftftftffftttbcbaacbada
cadbaabdadftttftfttffttttfftttadcaaddbbc

Done!

輸出到文件的結(jié)果:

Input the students' answers (Press Enter at the beginning of the next line to quit):

Answers of student 1: cabaabccdaftttfttfftftftffftttbcbaacbada
Results of Student 1:

Item One: Mark: 8, Wrong:    3   4   5   5   9  10   9  10                 /*這里有題號的重復(fù)*/
Item Two: Mark: 10, Wrong:    1   3
Item Three: Mark: 16, Wrong:                                                        /*這里有錯題和扣分卻無錯題題號記錄,下同*/
Item Four: Mark: 2, Wrong:
Item Five: Mark: 4, Wrong:
Input the students' answers (Press Enter at the beginning of the next line to quit):

Answers of student 2: cadbaabdadftttftfttffttttfftttadcaaddbbc
Results of Student 2:                             /*學(xué)生2的結(jié)果中也有同學(xué)生1一樣的錯誤出現(xiàn)*/

Item One: Mark: 8, Wrong:    1   4   5   4   7   8   7   8   9  10
Item Two: Mark: 10, Wrong:    1   2   3
Item Three: Mark: 20, Wrong:
Item Four: Mark: 4, Wrong:
Item Five: Mark: 2, Wrong:
Input the students' answers (Press Enter at the beginning of the next line to quit):
2 students' data treated till now.

結(jié)果中一看就知道有問題了,似乎給分和答錯的題目題號的記錄都不正確,我也看不出有什么地方出了問題,請各位指教,謝謝!

論壇徽章:
0
2 [報告]
發(fā)表于 2009-04-01 00:33 |只看該作者

回復(fù) #1 mcmay 的帖子

我經(jīng)過檢查發(fā)現(xiàn)了一個錯誤,更正如下:

/* calc mark fileops*/

#include <stdio.h>
#include <stdlib.h>

#define LEN 41
#define SIZE_A 10
#define SIZE_B  5
#define STEP 2

int main(void){
   
    char keys[LEN] = "dadacbcbadfftftttftffttttfftttbdccdabbaa";
    char ans[LEN];
    int wrng_1[SIZE_A] = {0}, wrng_2[SIZE_A] = {0}, wrng_3[SIZE_A] = {0},
        wrng_4[SIZE_B] = {0}, wrng_5[SIZE_B] = {0};
    int cnt = 0, sum_1, sum_2, sum_3, sum_4, sum_5;
    int i;
    FILE * fwrt;
   
    if((fwrt = fopen("output.txt","a")) == NULL){
        fprintf(stderr,"Error opening file!");
        getch();
        exit(EXIT_FAILURE);
    }
    puts("\nGet started!");
    fprintf(fwrt,"\nInput the students' answers (Press Enter at the beginning "
                 "of the next line to quit):\n");
    while(gets(ans) != NULL && ans[0] != '\0'){
        sum_1 = SIZE_A * STEP;
        sum_2 = SIZE_A * STEP;
        sum_3 = SIZE_A * STEP;
        sum_4 = SIZE_B * STEP;
        sum_5 = SIZE_B * STEP;
        fprintf(fwrt, "\nAnswers of student %d: %s", cnt+1, ans);
        for(i = 0; i < LEN-1; i++){
            if(ans != keys){
                if((i+1) > 0 && (i+1) <= 10){
                    sum_1 -= STEP;
                    wrng_1 = i+1;
                }
                if((i+1) > 10 && (i+1) <= 20){
                    sum_2 -= STEP;
                    wrng_2[i - SIZE_A] = (i+1) - SIZE_A; /*這里錯誤題號記錄數(shù)組wrng_2下標(biāo)應(yīng)保持在1-10之內(nèi),下同*/
                }
                if((i+1) > 20 && (i+1) <= 30){
                    sum_3 -= STEP;
                    wrng_3[i - (SIZE_A * 2)] = (i+1) - (SIZE_A * 2);
                }
                if((i+1) > 30 && (i+1) <= 35){
                    sum_4 -= STEP;
                    wrng_4[i - (SIZE_A * 3)] = (i+1) - (SIZE_A * 3);
                }
                if((i+1) > 35 && (i+1) <= 40){
                    sum_5 -= STEP;
                    wrng_5[i - (SIZE_A * 3 + SIZE_B)] =
                          (i+1) - (SIZE_A * 3 + SIZE_B);
                }
            }
        }
        fprintf(fwrt, "\nResults of Student %d:\n",cnt + 1);
        fprintf(fwrt, "\nItem One: Mark: %d, Wrong: ",sum_1);
        for(i = 0; i < SIZE_A; i++)
            if(wrng_1 != 0)
                fprintf(fwrt, "%4d", wrng_1);
        fprintf(fwrt, "\nItem Two: Mark: %d, Wrong: ",sum_2);
        for(i = 0; i < SIZE_A; i++)
            if(wrng_2 != 0)
                fprintf(fwrt, "%4d", wrng_2);
        fprintf(fwrt, "\nItem Three: Mark: %d, Wrong: ",sum_3);
        for(i = 0; i < SIZE_A; i++)
            if(wrng_3 != 0)
                fprintf(fwrt, "%4d", wrng_3);
        fprintf(fwrt, "\nItem Four: Mark: %d, Wrong: ",sum_4);
        for(i = 0; i < SIZE_B; i++)
            if(wrng_4 != 0)
                fprintf(fwrt, "%4d", wrng_4);
        fprintf(fwrt, "\nItem Five: Mark: %d, Wrong: ",sum_5);
        for(i = 0; i < SIZE_B; i++)
            if(wrng_5 != 0)
                fprintf(fwrt, "%4d", wrng_5);
        cnt++;
        fprintf(fwrt,"\nInput the students' answers (Press Enter at the beginning "
                 "of the next line to quit):\n");
    }
    fprintf(fwrt,"%d students' data treated till now.\n", cnt);
    fclose(fwrt);
    puts("\nDone!");
    getch();
    return 0;
}

不過,程序運(yùn)行結(jié)果卻還是有問題:

輸入:
Get Started!
cabaabccdaftttfttfftftftffftttbcbaacbada
cadbaabdadftttftfttffttttfftttadcaaddbbc

Done!

輸出到文件的結(jié)果:
Input the students' answers (Press Enter at the beginning of the next line to quit):

Answers of student 1: cabaabccdaftttfttfftftftffftttbcbaacbada
Results of Student 1:

Item One: Mark: 8, Wrong:    1   3   5   8   9  10
Item Two: Mark: 10, Wrong:    2   4   5   9  10
Item Three: Mark: 16, Wrong:    3   5
Item Four: Mark: 2, Wrong:    2   3   4   5
Item Five: Mark: 4, Wrong:    1   3   4
Input the students' answers (Press Enter at the beginning of the next line to quit):

Answers of student 2: cadbaabdadftttftfttffttttfftttadcaaddbbc
Results of Student 2:

Item One: Mark: 8, Wrong:    1   3   4   5   6   7   8   9  10     /*第二輪輸出結(jié)果很明顯錯誤重重,卻不知為何*/
Item Two: Mark: 10, Wrong:    2   4   5   7   8   9  10
Item Three: Mark: 20, Wrong:    3   5
Item Four: Mark: 4, Wrong:    1   2   3   4   5
Item Five: Mark: 2, Wrong:    1   2   3   4   5
Input the students' answers (Press Enter at the beginning of the next line to quit):
2 students' data treated till now.

請各位繼續(xù)不吝賜教!

論壇徽章:
0
3 [報告]
發(fā)表于 2009-04-01 01:14 |只看該作者

我又找出一些問題,已更正,程序運(yùn)行結(jié)果正常了。

下面是代碼更正:
/* calc mark fileops*/

#include <stdio.h>
#include <stdlib.h>

#define LEN 41
#define SIZE_A 10
#define SIZE_B  5
#define STEP 2

int main(void){
   
    char keys[LEN] = "dadacbcbadfftftttftffttttfftttbdccdabbaa";
    char ans[LEN];
    int wrng_1[SIZE_A] = {0}, wrng_2[SIZE_A] = {0}, wrng_3[SIZE_A] = {0},
        wrng_4[SIZE_B] = {0}, wrng_5[SIZE_B] = {0};
    int cnt = 0, sum_1, sum_2, sum_3, sum_4, sum_5;
    int i,j;
    FILE * fwrt;
   
    if((fwrt = fopen("output.txt","a")) == NULL){
        fprintf(stderr,"Error opening file!");
        getch();
        exit(EXIT_FAILURE);
    }
    puts("\nGet started!");
    fprintf(fwrt,"\nInput the students' answers (Press Enter at the beginning "
                 "of the next line to quit):\n");
    while(gets(ans) != NULL && ans[0] != '\0'){
        sum_1 = SIZE_A * STEP;
        sum_2 = SIZE_A * STEP;
        sum_3 = SIZE_A * STEP;
        sum_4 = SIZE_B * STEP;
        sum_5 = SIZE_B * STEP;
        for(i = 0; i < SIZE_A; i++){  /*這里wrng_1-3的數(shù)組內(nèi)容要?dú)w零才不會給下面的記錄行為留下上一個行為的殘留*/
            wrng_1 = 0;
            wrng_2 = 0;
            wrng_3 = 0;
        }
        for(j = 0; j < SIZE_B; j++){
            wrng_4[j] = 0;
            wrng_5[j] = 0;
        }
        fprintf(fwrt, "\nAnswers of student %d: %s", cnt+1, ans);
        for(i = 0; i < LEN-1; i++){
            if(ans != keys){
                if((i+1) > 0 && (i+1) <= 10){
                    sum_1 -= STEP;
                    wrng_1 = i+1;
                }
                if((i+1) > 10 && (i+1) <= 20){
                    sum_2 -= STEP;
                    wrng_2[i - SIZE_A] = (i+1) - SIZE_A;
                }
                if((i+1) > 20 && (i+1) <= 30){
                    sum_3 -= STEP;
                    wrng_3[i - (SIZE_A * 2)] = (i+1) - (SIZE_A * 2);
                }
                if((i+1) > 30 && (i+1) <= 35){
                    sum_4 -= STEP;
                    wrng_4[i - (SIZE_A * 3)] = (i+1) - (SIZE_A * 3);
                }
                if((i+1) > 35 && (i+1) <= 40){
                    sum_5 -= STEP;
                    wrng_5[i - (SIZE_A * 3 + SIZE_B)] =
                          (i+1) - (SIZE_A * 3 + SIZE_B);
                }
            }
        }
        fprintf(fwrt, "\nResults of Student %d:\n",cnt + 1);
        fprintf(fwrt, "\nItem One: Mark: %d, Wrong: ",sum_1);
        for(i = 0; i < SIZE_A; i++)
            if(wrng_1 != 0)
                fprintf(fwrt, "%4d", wrng_1);
        fprintf(fwrt, "\nItem Two: Mark: %d, Wrong: ",sum_2);
        for(i = 0; i < SIZE_A; i++)
            if(wrng_2 != 0)
                fprintf(fwrt, "%4d", wrng_2);
        fprintf(fwrt, "\nItem Three: Mark: %d, Wrong: ",sum_3);
        for(i = 0; i < SIZE_A; i++)
            if(wrng_3 != 0)
                fprintf(fwrt, "%4d", wrng_3);
        fprintf(fwrt, "\nItem Four: Mark: %d, Wrong: ",sum_4);
        for(i = 0; i < SIZE_B; i++)
            if(wrng_4 != 0)
                fprintf(fwrt, "%4d", wrng_4);
        fprintf(fwrt, "\nItem Five: Mark: %d, Wrong: ",sum_5);
        for(i = 0; i < SIZE_B; i++)
            if(wrng_5 != 0)
                fprintf(fwrt, "%4d", wrng_5);
        cnt++;
        fprintf(fwrt,"\nInput the students' answers (Press Enter at the beginning "
                 "of the next line to quit):\n");
    }
    fprintf(fwrt,"%d students' data treated till now.\n", cnt);
    fclose(fwrt);
    puts("\nDone!");
    getch();
    return 0;
}

更正后程序運(yùn)行情況:

輸入:
Get Started!
cabaabccdaftttfttfftftftffftttbcbaacbada
cadbaabdadftttftfttffttttfftttadcaaddbbc

Done!

輸出到文件的結(jié)果:

Input the students' answers (Press Enter at the beginning of the next line to quit):

Answers of student 1: cabaabccdaftttfttfftftftffftttbcbaacbada
Results of Student 1:

Item One: Mark: 8, Wrong:    1   3   5   8   9  10
Item Two: Mark: 10, Wrong:    2   4   5   9  10
Item Three: Mark: 16, Wrong:    3   5
Item Four: Mark: 2, Wrong:    2   3   4   5
Item Five: Mark: 4, Wrong:    1   3   4
Input the students' answers (Press Enter at the beginning of the next line to quit):

Answers of student 2: cadbaabdadftttftfttffttttfftttadcaaddbbc
Results of Student 2:

Item One: Mark: 8, Wrong:    1   4   5   6   7   8
Item Two: Mark: 10, Wrong:    2   4   5   7   8
Item Three: Mark: 20, Wrong:
Item Four: Mark: 4, Wrong:    1   4   5
Item Five: Mark: 2, Wrong:    1   2   4   5
Input the students' answers (Press Enter at the beginning of the next line to quit):
2 students' data treated till now.

如果還有任何需要更正或改進(jìn)的地方,扔請各位不吝指教,謝謝!

論壇徽章:
0
4 [報告]
發(fā)表于 2009-04-01 08:31 |只看該作者
貼代碼的時候請用代碼模式。
  1. test
復(fù)制代碼

論壇徽章:
1
射手座
日期:2013-08-21 13:11:46
5 [報告]
發(fā)表于 2009-04-01 10:34 |只看該作者
感覺是簡單的問題復(fù)雜化.
char keys[LEN]是正確答案,
char ans[LEN] 是做出來的答案,
bit state[LEN] 就是答案的狀態(tài),然后再統(tǒng)計(jì)一下不就行了
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP