选举系统c语言,求助:班委选举系统(C语言)

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include#include

#include

#define N 40 /*班级人数*/

#define M 6 /*每人的投票数*/

struct std

{

int num, num_vote, tou[M]; /*自己的学号,获得的投票数,投的谁的票 */

char name[20];

}std[N], temp;

/*班级信息输入*/

void input_all_std (){

int i;

printf ("输入全班信息\n\n");

for (i = 0; i

{printf ("学生%d的姓名和学号:", i + 1);

scanf ("%s %d", std[i].name,&std[i].num);

std[i].num_vote = 0;

}

system ("cls");

printf ("姓名: 学号:\n");

for (i = 0; i

printf ("%-20s%d\n",std[i].name, std[i].num);

}/*根据学生的学号查找到结构体编号*/

int find_std (int num){int n;

for (n = 0; n

{if (std[n].num == num)

{return n;};}return -1;}void vote ()

{int i = N, j, t, temp;

system ("cls");

loop:while (i)

{printf ("输入你的学号:");

scanf ("%d",&temp);

t = find_std (temp);

if (t == -1){printf ("学号错误!");

goto loop;

}

for (j = 0; j

{printf ("第%d票投给:", j + 1);

scanf ("%d",&std[t].tou[j]);

temp = find_std (std[t].tou[j]);

if (temp == -1)

{printf ("\n投票无效!\n");

j--;

continue;

}

std[temp].num_vote++;

}

system ("cls");

i = i - 1;}}

void sort ()

{int i, j, k, n, t;

for (i = 0; i

{k = i;

for (j = i + 1; j

if (std[j].num_vote>std[k].num_vote)

k = j;

if (k != i)

{temp = std[i];

std[i] = std[j];

std[j] = temp;}}

for (i = 0; i

{for (j = 0; j

{k = j;for (n = j + 1; n

if (std[i].tou[j]>std[i].tou[k])

k = j;

if (k != j)

{t = std[i].tou[j];

std[i].tou[j] = std[i].tou[k];

std[i].tou[k] = t;}}}}

/*输出选举结果*/

void output_list ()

{int i;system ("cls");

printf ("最终的选举结果为:\n姓名: 得票数:\n");

for (i = 0; i

printf ("%-20s%d\n", std[i].name, std[i].num_vote);}

/*与结果完全相符的投票人姓名*/void all_right (){int i,j,flag=0;

system ("cls");

printf ("与结果完全相符的投票人姓名:\n");

for (i = 0; i

{for(j = 0; j

{if (std[i].tou[j] == std[j].num)

{flag=1; continue;}

else {flag=0;break;}}

if(flag==1)printf ("%-s\n", std[i].name);}}/*输出班委名单*/void out_lead_list (){int i;float temp;system ("cls");printf ("班委名单: 得票率:\n");for (i = 0; i<6; i++){temp = (float) std[i].num_vote;printf ("%-10s%2.4f\n", std[i].name, temp / N * 1.0);}}

/*查找特定人员投票信息*/void find_info (){int a;system ("cls");loop:printf ("输入所要查找的学号:");scanf ("%d",&a);a = find_std (a);if (a == -1){printf ("此学号不存在!");system ("cls");goto loop;}system ("cls");printf ("姓名:%s\n得票数:%d\n投票情况:\n%d\n%d\n%d\n%d\n%d\n%d\n\n",std[a].name, std[a].num_vote, std[a].tou[0], std[a].tou[1],std[a].tou[2], std[a].tou[3], std[a].tou[04], std[a].tou[5]);}void main (){int flag=-1;

input_all_std ();loop:while(flag){printf ("--------------------------------\n");printf ("1.开始投票\n");printf ("2.当选班委的名单\n");printf ("3.查看投票信息\n");printf ("4.与投票结果完全相符的投票人\n");printf ("0.退出\n");printf ("--------------------------------\n");printf ("选择:");scanf ("%d",&flag);system ("cls");switch (flag){case 1:{vote ();sort ();break;}case 2:{out_lead_list ();break;}case 3:{find_info ();break;}case 4:{all_right ();break;}case 0:{printf ("Byebye! ^_^");getch ();exit (0);}default:{printf ("输入错误!请重新输入。\n");}goto loop;}}}

还有哪些要改的 ????

优秀班委选举系统 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace 优秀班委选举 { public partial class Form1 : Form { private ListBox listBox; public Form1() { InitializeComponent(); } public Form1(ListBox listBox) { InitializeComponent(); this.listBox = listBox; } private void button1_Click(object sender, EventArgs e) { if (listBox1.Items.Count > 0) { if (listBox1.SelectedItem == null) { MessageBox.Show("请先选择一个对象!"); } else { //获取左边listBox1中选中的内容 string cont = listBox1.SelectedItem.ToString(); //左边listBox1中删除选中的内容 listBox1.Items.Remove(cont); //把获得的内容加入到右边的listBox2中 listBox2.Items.Add(cont); } } } private void button2_Click(object sender, EventArgs e) { if (listBox2.Items.Count > 0) { if (listBox2.SelectedItem == null) { MessageBox.Show("请先选择一个对象!"); } else { //获取右边listBox2中选中的内容 string cont = listBox2.SelectedItem.ToString(); //右边listBox2中删除选中的内容 listBox2.Items.Remove(cont); //把获得的内容加入到左边的listBox1中 listBox1.Items.Add(cont); } } } //退出 private void button5_Click(object sender, EventArgs e) { Application.Exit(); } //显示结果 private void button4_Click(object sender, EventArgs e) { //传递listBox2到Form2窗口中 Form2 form2 = new Form2(listBox2); form2.Show(); } //修改名单 private void button3_Click(object sender, EventArgs e) { if (listBox2.SelectedItem == null) { MessageBox.Show("请先选择一个对象!"); } else { string cont = listBox2.SelectedItem.ToString(); int index = listBox2.SelectedIndex; Form3 form3 = new Form3(cont, index, listBox2); form3.Show(); this.Hide(); } } //加载窗口 private void Form1_Load(object sender, EventArgs e) { if (listBox != null) { foreach (string str in listBox.Items) { listBox2.Items.Add(str); } } } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值