求高手解答一个班级选票系统,万分感激!!!

蓝图H 2015-01-07 08:36:18
C程序设计课程设计题目

一、选票系统
某班从全班20人(学号1~20)中投票选举6位班委委员,每张选票内容包括:所选班委的学号,投票人学号。(要求不用文件做,要用链表)
基本要求用菜单选择并完成下述系统功能:
1:输入全班的名单(姓名与学号),并可显示。
2:选票输入:输入每张选票的投票人学号及所选班委的学号(可选6个,没有则键入空白)。
3:输出得票前6位的当选班委名单(如第6位有多位得票数相等,则从中任选一位输出)及其得票率(得票数/总选票数)
4:可以输出6位班委名单全部选择与投票结果完全相符的投票人姓名。
5:退出程序
...全文
233 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
蓝图H 2015-01-10
  • 打赏
  • 举报
回复
谢了,不过这不是c语言吧
baidu_25185765 2015-01-09
  • 打赏
  • 举报
回复
#include <stdio.h> #include <stdlib.h> typedef struct node { // 候选人结构 char name[8]; int num; int score; int tax; }Node; void shellSort( Node **, int ); int main(void) { int n = 0; Node * pArray[9]={};//指针数组,长度9 int count = 0; //int status = 1; int vote = -1; printf("Input the number of the candidates(1-9):\n"); scanf("%d", &n); while(getchar()!='\n') {; } while (n>9 || n<1) {if (n>9) {printf("No, there cannot be so many candidates. Retry.\n"); } else{ printf("No candidates? It cannot be! Retry!\n");} scanf("%d", &n); while(getchar()!='\n') { ;} } for (count=0; count<n; count++) { pArray[count] = (Node *)malloc(sizeof(Node)); pArray[count]->num = count+1; pArray[count]->tax = 0; pArray[count]->score = 0; printf("Input No.%d candidate's name:\n", count+1); gets(pArray[count]->name); } while (vote) { printf("Now, let us vote:\n*************\n"); for (count=0; count<n; count++) { printf("%d. %s\n", count+1, pArray[count]->name); } printf("0.quit\n*************\n"); scanf("%d", &vote); while(getchar()!='\n') { ; } while (vote<0 || vote>n) { printf("No joke, thank you. Revote.\n"); scanf("%d", &vote); while(getchar()!='\n') { ; } } if (vote>0&&vote<=n) { pArray[vote-1]->score++; } } printf("Finish voting. Let's find the winner......\n\n"); shellSort( pArray, n ); for (count=0; count<n; count++) { pArray[count]->tax=count+1; printf("%d. %s %d votes.\n", count+1, pArray[count]->name, pArray[count]->score); } for(count=0; count<n; count++) { free(pArray[count]); pArray[count] = NULL; } return 0; } void shellSort( Node *p[], int len ) { const int Length = len; int i = 0; int j = 0; int gap = 0; Node *temp = NULL; gap = Length/2; while (gap>0) { for (i=gap; i<Length; i++) { j = i - gap; temp = *(p+i); while ( (j>=0) && (p[j]->score < temp->score) ) { *(p+j+gap) = *(p+j); j = j - gap; } *(p+j+gap) = temp; } gap /= 2; } }

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧