目录
1 摘要
1.1 设计题目
1.2 设计内容
1.3 开发工具
1.4 应用平台
2 详细设计
2.1 程序结构
2.2 主要功能
2.3 函数实现
2.4 开发日志
3 程序调试及运行
3.1 程序运行结果
3.2 程序使用说明
3.3 程序开发总结
4 附件(源程序)
2
2
2
2
2
3
3
3
3
4
4
2
2
3
5
1 摘要
1.1 设计题目
评委评分程序
1.2 设计内容
本程序用来给选手评分并进行排名,依次输入各位裁判对各位选手的评分后,程序会按
照按照平均分进行排名。
1.3 开发工具
Visual studio2010
1.4 应用平台
Windows 2000/XP/Vista /7
32 位/64 位
2 详细设计
2.1 程序结构
程序设计了 4 个类,有 4 个不同的窗口,第一个窗口是主窗口,要求输入选手的人数和
裁判的人数,第二个窗口依次弹出要求输入每个选手的名字,第三个窗口依次弹出要求输入
裁判对每个选手的评分,等最后一位裁判对最后一位选手评分完之后,第四个窗口显示排名
结果。每个窗口都有 button,当点击 button 后实例化另一个窗口对象,然后调用 show 方法
显示另一个窗口。
2.2 主要功能
程序功能是实现对选手的排序,在窗口中输入选手的评分后,程序统计评分结果并放在
数组中,当这位选手评分完成之后,计算他的分数总和,然后除以裁判人数,计算出的平均
分存放在 average 数组中,下标与其名字对应。程序中用到了冒泡排序算法,对选手的平均
分按照从大到小进行排列,并且排序过程中保持名字与平均分的一致性。最后以字符串的形
式把结果显示在窗口中。
2.3 程序关键类的实现
程序设计了 4 个类,有 4 个不同的窗口,第一个窗口是主窗口,要求输入选手的人数和
裁判的人数,第二个窗口依次弹出要求输入每个选手的名字,第三个窗口依次弹出要求输入
裁判对每个选手的评分,等最后一位裁判对最后一位选手评分完之后,第四个窗口显示排名
结果。每个窗口都有 button,当点击 button 后实例化另一个窗口对象,然后调用 show 方法
显示另一个窗口。
2.4 开发日志
编写过程中在输入裁判分数的窗口显示次数时有时候会多显示一次或者少显示一次,
通过不断调试,用 c1,c2.两个变量计数,解决了这一问题。
3 程序调试及运行
3.1 程序运行结果
Form1 输入裁判和选手人数
依次输入每位选手的名字
依次对每位选手进行评分
3.2 程序使用说明
排名之后并对结果进行显示
首先输入选手跟裁判的人数,然后点击下一步输入每位选手的名字,依次输入名字后点击下
一步,输入每位裁判对选手的评分,输入完成后点击下一步显示结果。
3.3 程序开发总结
通过编写大作业,我掌握了如何从一个窗口通过点击 button 进入另一个窗口,然后通
过 show 方法让他循环显示来满足所需要的功能,程序难点在于如何控制每个窗口的出现次
数,以及窗口之间的转换。程序定义了多个 static 变量与数组来使 4 个类之间共享某些数据,
方便的解决了某些问题。另外名字数组与平均分数组必须一一对应,在排序的时候应该注意。
4 附件(源程序)
文件 1:Form1.cs
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 WindowsFormsApplication10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public static int n1, n2;
public static string[] name = new string[100];
public void button1_Click(object sender, EventArgs e)
{
if (textBox4.Text == "" || textBox3.Text == "") return;
n1 = int.Parse(textBox3.Text);
n2 = int.Parse(textBox4.Text);
this.Hide();
Form2 f2 = new Form2();
f2.Text = "请?输º?入¨?选?手º?姓?名?:êo";
f2.Show();
}
}
}
Form2.cs:
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 WindowsFormsApplication10
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
static int i = 1;
private void Form2_Load(object sender, EventArgs e)
{
label1.Text = "请?输º?入¨?第̨²" + i + "位?选?手º?的Ì?名?字Á?:êo";
}
public void button1_Click(object sender, EventArgs e)
{
Form1.name[i] = textBox1.Text;
i++;
this.Hide();
if (i <= Form1.n2)
{
Form2 f2 = new Form2();
f2.Text = "请?输º?入¨?选?手º?姓?名?:êo";
f2.Show();
}
else {
Form5 f = new Form5();
f.Text = "评¨¤分¤?进?行D中D..";
f.Show();
}
}
}
}
Form3.cs:
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 WindowsFormsApplication10
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
public static double[] average = new double[100];
double[] grade = new double[100];
static int cnt = 0;
static int p = 1;
static int c1 = 0;
static int c2 = 1;
private void button1_Click(object sender, EventArgs e)
{
grade[cnt++] = double.Parse(textBox1.Text);
this.Hide();
if (cnt == Form1.n1) {
double sum = 0;
while (cnt >= 0)
{
sum += grade[cnt--];
}
cnt = 0;
average[p++] = (double)(sum / Form1.n1);
}
if (c2 - 1 < Form1.n2)
{
Form5 f5 = new Form5();
f5.Text = "评¨¤分¤?进?行D中D..";
f5.Show();
}
else {
this.Hide();
Form3 f3 = new Form3();
f3.Text = "结¨¢果?:êo";
f3.Show();
}
}
private void Form5_Load(object sender, EventArgs e)
{
c1++;
show_label.Text = "请?输º?入¨?第̨²"+c1+"位?评¨¤委
¡¥对?"+Form1.name[c2]+"选?手º?的Ì?评¨¤分¤?:êo";
if ((c1 ) == Form1.n1 )
{
c2++;
c1 = 0;
}
}
}
}
Form4.cs:
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;