天天看點

C語言十佳運動員有獎評選系統,投票評選十佳運動員.doc

投票評選十佳運動員

十佳運動員評選活動一、功能要求某市體委與電視台聯合舉辦十佳運動員有獎評選活動,具體說明如下(1)體委組織有關人士評出了如表1所示的20個候選人名單運動員編号 運動員姓名 運動員編号 運動員姓名(2)電視台在網上設立了投票站供市民投票,以便用計算機進行統計和核對。選票格式如表2所示選票編号 0000001 投票人姓名 投票人位址 拟選運動員編号 選票号為7位數字,有效的運動員編号是01~20(3)計算機統計的具體任務是 統計出各候選人的得票數,并根據得票數排定名次,選出十佳人員 根據命中率選出10個獲獎的參選者,并排定名次命中率=命中分+次序分命中分:選中十佳中的一個即得10分,選中n個得n10分(不考慮次序)次序分:選票中的第一個運動員與十佳中的第一名相符(簡稱選中第一名)得9分選中第二名得8分,……,選中第十名的0分(4)編寫出完成以上統計任務的程式具體要求如下1 候選人資料和選票資料應以文本檔案的方式分别存放在兩個檔案中,選票中參選的位址可以不考慮2程式中,對選票資料要求采用結構體作資料結構3 程式除能完成統計功能外,應具有核對選票資料的功能,并且每一功能的實作要用選擇菜單的方式進行(使用簡單的文本菜單),菜單包含以下幾項a. 統計b. 核對選票c. 退出4 各個功能以及相對獨立的任務要求編寫成獨立的函數,主函數隻用于管理菜單和織調用個功能函數5統計結果除在螢幕顯示外,還要求輸出到檔案中最好用上連結清單

#include #include #include #include #include #include #define DATA1 "data1.txt" #define DATA2 "data2.txt" typedef struct sportsman{ int number; char name[21]; int tickets; struct sportsman *next;} sportsman;typedef struct ticket{ char ticknum[8]; char votername[21]; char voteraddr[51]; int sportsman; int scores; struct ticket *next;} ticket;int SIZE1, SIZE2;sportsman *head1, *tail1;ticket *head2, *tail2;void init();void cleanup();void create();void process();sportsman *sortlist1();ticket *sortlist2();void showdetail();void showtop10();void clearlist();void init(){ SIZE1 = sizeof(sportsman); SIZE2 = sizeof(ticket); head1 = tail1 = (sportsman *)malloc(SIZE1); head2 = tail2 = (ticket *)malloc(SIZE2); memset(head1, 0, SIZE1); memset(head2, 0, SIZE2);}void create(){ FILE *infile = fopen(DATA1, "r"); if (infile == NULL) { printf("無法打開檔案1\n"); cleanup(); exit(1); } while (1) { char nm[21]; int num; memset(nm, 0, 21); num = 0; fscanf(infile, "%d", &num); if (num == 0) break; sportsman *node = (sportsman *)malloc(SIZE1); node->number = num; node->tickets = 0; fscanf(infile, "%s", node->name); tail1->next = node; tail1 = node;