logo资料库

C# 学生管理系统.docx

第1页 / 共17页
第2页 / 共17页
第3页 / 共17页
第4页 / 共17页
第5页 / 共17页
第6页 / 共17页
第7页 / 共17页
第8页 / 共17页
资料共17页,剩余部分请下载后查看
实验二 设计一个学生成绩管理系统 ⑴有学号,姓名,班级,成绩字段; ⑵初始化一个班级(35 人)的基本信息; ⑶统计 60 分以下,60~70,70~80,80~90,90 分以上学生信息;按四个 字段查询并列出学生信息; ⑷按学生成绩高到低,低到高进行排序. 源代码: 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 StudentSystem { public partial class Form1 : Form { private int i = 35; Student[] ss = new Student[500]; public Form1() { } InitializeComponent(); private void label1_Click(object sender, EventArgs e) { }
private void label5_Click(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { for (int k = i; k < 500; k++)//最多可容纳500个学生 { } ss[k] = null; ss[0]=new Student(20092901,"Pear","0903",99);//最初初始化的35个学生相关信息 ss[1]=new Student(20092902,"Mars","0904",100); ss[2]=new Student(20092903,"Tomy","0902",51); ss[3]=new Student(20092904,"Hap", "0903",67); ss[4]=new Student(20092305,"Hil","0904",78.8 ); ss[5]=new Student(20092906 ,"Lil","0902",84); ss[6] = new Student(20092907,"Lucy","0903" ,66); ss[7] = new Student(20092908,"Man","0904",78.4); ss[8] = new Student(20092909,"John","0903",86); ss[9]=new Student(20092910,"Crds","0903",93); ss[10]=new Student(20092911,"Amy","0903",99); ss[11]=new Student(20092912,"Mary","0904",100); ss[12] = new Student(20092913,"Tom","0902", 54); ss[13]=new Student(20092914,"Hax","0903",62); ss[14]=new Student(20092315,"Hill","0904",79); ss[15]=new Student(20092916,"Lily","0902",86); ss[16]=new Student(20092917,"Lucy","0903",64); ss[17]=new Student(20092918, "Mee","0904", 78.4); ss[18]=new Student(20092919,"John","0903",86); ss[19]=new Student(20092920,"Che","0903",93); ss[20]=new Student(20092921,"Apd","0902",95); ss[21]=new Student(20092922,"Mary","0904",100); ss[22]=new Student(20092923,"Tom","0902",58); ss[23]=new Student(20092924,"Hapy","0903", 68); ss[24]=new Student(20092325,"Hill","0904",78.8); ss[25]=new Student(20093426,"Lily","0902", 88.5); ss[26]=new Student(20092927,"Lucy","0903",66.5); ss[27]=new Student(20092928,"Mano","0904", 78.4); ss[28]=new Student(20092929,"John","0903",86.5); ss[29]=new Student(20092930,"Cer","0903",93.5); ss[30]=new Student(20092931,"Ale","0902",92.5);
ss[31]=new Student(20092932 ,"Mgo","0904", 78.5); ss[32]=new Student(20092933,"John","0903", 86.7); ss[33]=new Student(20092934,"Cer","0903",93.0); ss[34]=new Student(20092935,"Aple","0902",91.5); comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; comboBox1.Items.Add("六十分以下"); comboBox1.Items.Add("六十到七十"); comboBox1.Items.Add("七十到八十"); comboBox1.Items.Add("八十到九十"); comboBox1.Items.Add("九十到一百"); comboBox2.DropDownStyle = ComboBoxStyle.DropDownList; comboBox2.Items.Add("递增排序"); comboBox2.Items.Add("递减排序"); comboBox3.DropDownStyle = ComboBoxStyle.DropDownList; comboBox3.Items.Add("班级"); comboBox3.Items.Add("姓名"); comboBox3.Items.Add("学号"); } private void label2_Click(object sender, EventArgs e) { } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox2.SelectedIndex == 0) { //冒泡 Student temp = new Student(); temp=null; for (int j = i; j >1; j--) for (int k = 0; k < j-1; k++) { if (ss[k].getGrade() > ss[k + 1].getGrade()) {
temp = ss[k]; ss[k] = ss[k + 1]; ss[k + 1] = temp; } } listBox1.Items.Clear(); listBox1.Items.Insert(0, "增序排列"); listBox1.Items.Insert(1, "ID Name Class Grade"); for (int j = 0; j < i; j++) { listBox1.Items.Insert(j + 2, ss[j].getNum() + " " + ss[j].getName() + '\t' + ss[j].getBj() + '\t' + ss[j].getGrade()); } } if (comboBox2.SelectedIndex == 1) {//冒泡 Student temp = new Student(); for (int j = i; j > 1; j--) for (int k = 0; k < j-1; k++) { } if (ss[k].getGrade() < ss[k + 1].getGrade()) { } temp = ss[k]; ss[k] = ss[k + 1]; ss[k + 1] = temp; listBox1.Items.Clear(); listBox1.Items.Insert(0, "降序排列"); listBox1.Items.Insert(1, "ID Name Class Grade"); for (int j = 0; j < i; j++) { listBox1.Items.Insert(j+2, ss[j].getNum() +" " + ss[j].getName() + '\t'+ ss[j].getBj() + '\t' + ss[j].getGrade()); } } } private void button1_Click(object sender, EventArgs e) {
String id_s = textBox1.Text; int id = Convert.ToInt32(id_s); String n = textBox2.Text; String b = textBox3.Text; String gr = textBox4.Text; double g = Convert.ToDouble(gr); ss[i] = new Student(id, n, b, g); listBox1.Items.Insert(++i, textBox1.Text + '\t' + textBox2.Text + '\t' + textBox3.Text + '\t' + textBox4.Text); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBox1.SelectedIndex) { case 0: listBox1.Items.Clear(); listBox1.Items.Insert(0, "60以下:"); listBox1.Items.Insert(1, "ID Name Class Grade"); int f = 2; for (int j = 0; j < i; j++) { double g1 = ss[j].getGrade() / 10; int floor = (int)System.Math.Floor(g1); if (floor < 6) { + ss[j].getName() + '\t' + ss[j].getBj() + '\t' + Convert.ToString(ss[j].getGrade())); listBox1.Items.Insert(f,Convert.ToString(ss[j].getNum()) + " " f++; } } break; case 1: listBox1.Items.Clear(); listBox1.Items.Insert(0, "60-70:"); listBox1.Items.Insert(1, "ID Name Class Grade"); int a = 2; for (int j = 0; j < i; j++) { double g1 = ss[j].getGrade() / 10;
int floor = (int)System.Math.Floor(g1); if (floor >=6&&floor<7) { + '\t' + ss[j].getBj() + '\t' + ss[j].getGrade()); listBox1.Items.Insert(a++,ss[j].getNum() + " " + ss[j].getName() } } break; case 2: listBox1.Items.Clear(); listBox1.Items.Insert(0, "70-80:"); listBox1.Items.Insert(1, "ID Name Class Grade"); int b = 2; for (int j = 0; j < i; j++) { double g1 = ss[j].getGrade() / 10; int floor = (int)System.Math.Floor(g1); if (floor >=7&&floor<8) { ss[j].getName() + '\t' + ss[j].getBj() + '\t' + ss[j].getGrade()); listBox1.Items.Insert(b++,ss[j].getNum() + " " + } } break; case 3: listBox1.Items.Clear(); listBox1.Items.Insert(0, "80-90:"); listBox1.Items.Insert(1, "ID Name Class Grade"); int c = 2; for (int j = 0; j < i; j++) { double g1 = ss[j].getGrade() / 10; int floor = (int)System.Math.Floor(g1); if (floor >=8&&floor<9) { + '\t' + ss[j].getBj() + '\t' + ss[j].getGrade()); listBox1.Items.Insert(c++, ss[j].getNum() + " " + ss[j].getName() } } break; case 4:
listBox1.Items.Clear(); listBox1.Items.Insert(0, "90-100:"); listBox1.Items.Insert(1, "ID Name Class Grade"); int d = 2; for (int j = 0; j < i; j++) { double g1 = ss[j].getGrade() / 10; int floor = (int)System.Math.Floor(g1); if (floor >= 9) { + '\t' + ss[j].getBj() + '\t' + ss[j].getGrade()); listBox1.Items.Insert(d++,ss[j].getNum() + " "+ ss[j].getName() } } break; } } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { listBox1.Items.Clear(); listBox1.Items.Insert(0, "全部学生成绩"); listBox1.Items.Insert(1, "ID Name Class Grade"); for (int j = 0; j < i; j++) { listBox1.Items.Insert(j+2, ss[j].getNum() + " " + ss[j].getName() + '\t' + ss[j].getBj() + '\t' + ss[j].getGrade()); } } private void button3_Click(object sender, EventArgs e) { if(comboBox3.SelectedIndex==0) { listBox1.Items.Clear();
listBox1.Items.Insert(0, "按班级查询"); listBox1.Items.Insert(1, "ID Name Class Grade"); int h=2; for (int j = 0; j < i; j++) { if(textBox5.Text.Equals(ss[j].getBj())) { + '\t' + ss[j].getBj() + '\t' + ss[j].getGrade()); listBox1.Items.Insert(h, ss[j].getNum() + " " + ss[j].getName() h++; } } } if(comboBox3.SelectedIndex==1) { listBox1.Items.Clear(); listBox1.Items.Insert(0, "按姓名查询"); listBox1.Items.Insert(1, "ID Name Class Grade"); int l=2; for (int j = 0; j < i; j++) { if(textBox5.Text.Equals(ss[j].getName())) { + '\t' + ss[j].getBj() + '\t' + ss[j].getGrade()); listBox1.Items.Insert(l, ss[j].getNum() + " " + ss[j].getName() l++; } } } if (comboBox3.SelectedIndex == 2) { listBox1.Items.Clear(); listBox1.Items.Insert(0, "按学号查询"); listBox1.Items.Insert(1, "ID Name Class Grade"); int m=2; for (int j = 0; j < i; j++) { if(Convert.ToDouble(textBox5.Text)==ss[j].getNum()) { listBox1.Items.Insert(m, ss[j].getNum() + " " + ss[j].getName() + '\t' + ss[j].getBj() + '\t' + ss[j].getGrade());
分享到:
收藏