using System; using System.Collections.Generic; using System.ComponentModel;
using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System.Threading.Tasks; using System.Windows.Forms; namespace
WindowsFormsApp10{ public partial class Form1 : Form { public Form1() {
InitializeComponent(); } public class Student { public string sno; public string
name; public double chinese; public double math; public double english; public
Student(string sno, string name, double chinese, double math, double english) {
this.sno = sno; this.name = name; this.chinese = chinese; this.math = math; this
.english = english; } public double Sum { get { return chinese + math + english;
} } } public class Grade { Student[] stu = new Student[100]; double[] sum2 = new
double[100]; int i = 0; public Grade() { } //添加学生 public void Add(Student s) {
stu[i] = s; sum2[i] = stu[i].Sum; i++; } //查询指定学生的总成绩 int x = 0; int k = 0; bool
flag= false; //查询总成绩 public double getSum(string s) { for (x = 0; x < i; x++) {
if (stu[x].name == s) { k = x; flag = true; } } if (flag == true) { return sum2[
k]; } else { return -1; } } //全班同学的平均成绩 double avg = 0; public double getAverage
() { for (int aa = 0; aa < i; aa++) { avg += sum2[aa]; } return avg / i; }
//语文成绩最高分 double maxChinese = 0; public double getChineseMax() { for (int z = 0;
z< i; z++) { if (stu[z].chinese > maxChinese) { maxChinese = stu[z].chinese; }
} return maxChinese; } // 英语最高分 double maxMath = 0; public double getMathMax() {
for (int z = 0; z < i; z++) { if (stu[z].math > maxMath) { maxMath = stu[z].math
; } } return maxMath; } //英语成绩最高分 double maxEnglish = 0; public double
getEnglishMax() { for (int z = 0; z < i; z++) { if (stu[z].english > maxEnglish)
{ maxEnglish = stu[z].english; } } return maxEnglish; } //统计全班前3名的名单 public
string getNames() { Student[] t = new Student[1]; //中间变量 t[0] = new Student("",
"", 0, 0, 0); double t2 = 0; for (int xx = 0; xx < i - 1; xx++) { for (int yy =
xx+ 1; yy < i; yy++) { if (sum2[yy] > sum2[xx]) { t2 = sum2[yy]; sum2[yy] = sum2
[xx]; sum2[xx] = t2; t[0] = stu[yy]; stu[yy] = stu[xx]; stu[xx] = t[0]; } } }
return " " + stu[0].name + " " + stu[1].name + " " + stu[2].name; } //不及格的学生
string md = ""; public string getStudentMenu(string s) { if (s == "语文") { for (
int x = 0; x < i; x++) { if (stu[x].chinese < 60) { md += " " + stu[x].name; } }
return " " + md; } else if (s == "数学") { for (int x = 0; x < i; x++) { if (stu[x
].math < 60) { md += " " + stu[x].name; } } return " " + md; } else if (s ==
"英语") { for (int x = 0; x < i; x++) { if (stu[x].english < 60) { md += " " + stu
[x].name; } } return " " + md; } else { return "不存在(您输入的课程名称不正确)"; } }
//可不同分数段的学生人数百分比 public string getStudentBFB(string s) { if (s == "语文") { double
yw1= 0; double yw2 = 0; double yw3 = 0; double yw4 = 0; double yw5 = 0; for (
int z = 0; z < i; z++) { if (stu[z].chinese <= 100 && stu[z].chinese >= 90) {
yw1++; } else if (stu[z].chinese < 90 && stu[z].chinese >= 80) { yw2++; } else
if (stu[z].chinese < 80 && stu[z].chinese >= 70) { yw3++; } else if (stu[z].
chinese< 70 && stu[z].chinese >= 60) { yw4++; } else { yw5++; } } return
"\n90-100:" + (yw1 / i) * 100.0 + "%\n80-90:" + (yw2 / i) * 100.0 + "%\n70-80:"
+ (yw3 / i) * 100.0 + "%\n60-70:" + (yw4 / i) * 100.0 + "%\n60以下:" + (yw5 / i) *
100.0 + "%"; } else if (s == "数学") { double yw1 = 0; double yw2 = 0; double yw3
= 0; double yw4 = 0; double yw5 = 0; for (int z = 0; z < i; z++) { if (stu[z].
chinese<= 100 && stu[z].chinese >= 90) { yw1++; } else if (stu[z].chinese < 90
&& stu[z].chinese >= 80) { yw2++; } else if (stu[z].chinese < 80 && stu[z].
chinese>= 70) { yw3++; } else if (stu[z].chinese < 70 && stu[z].chinese >= 60) {
yw4++; } else { yw5++; } } return "\n90-100:" + (yw1 / i) * 100.0 + "%\n80-90:"
+ (yw2 / i) * 100.0 + "%\n70-80:" + (yw3 / i) * 100.0 + "%\n60-70:" + (yw4 / i)
* 100.0 + "%\n60以下:" + (yw5 / i) * 100.0 + "%"; } else if (s == "英语") { double
yw1= 0; double yw2 = 0; double yw3 = 0; double yw4 = 0; double yw5 = 0; for (int
z= 0; z < i; z++) { if (stu[z].chinese <= 100 && stu[z].chinese >= 90) { yw1++;
} else if (stu[z].chinese < 90 && stu[z].chinese >= 80) { yw2++; } else if (stu[
z].chinese < 80 && stu[z].chinese >= 70) { yw3++; } else if (stu[z].chinese < 70
&& stu[z].chinese >= 60) { yw4++; } else { yw5++; } } return "\n90-100:" + (yw1
/ i) * 100.0 + "%\n80-90:" + (yw2 / i) * 100.0 + "%\n70-80:" + (yw3 / i) * 100.0
+ "%\n60-70:" + (yw4 / i) * 100.0 + "%\n60以下:" + (yw5 / i) * 100.0 + "%"; } else
{ return "不存在(您输入的课程名称不正确)"; } } } Student[] st1 = new Student[100]; Grade gr =
new Grade(); int i = 0; private void label8_Click(object sender, EventArgs e) {
} private void Form1_Load(object sender, EventArgs e) { label7.Text = ""; }
private void button1_Click(object sender, EventArgs e) { try { st1[i] = new
Student(textBox1.Text, textBox2.Text, Convert.ToInt32(textBox3.Text), Convert.
ToInt32(textBox4.Text), Convert.ToInt32(textBox5.Text)); gr.Add(st1[i]); i++;
label7.Text = "成功添加" + i + "个学生的信息"; textBox1.Text = ""; textBox2.Text = "";
textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = "";
} catch { MessageBox.Show("输入完善的学生信息进行添加"); } } private void button2_Click(
object sender, EventArgs e) { label7.Text = ""; if (textBox6.Text.Trim() != "")
{ //统计全班学生的平均成绩 label7.Text += "\n\n全班同学的平均成绩为: " + Convert.ToString(gr.
getAverage()); //统计单科成绩的最高分 label7.Text += "\n\n语文成绩最高分为:" + Convert.ToString(gr
.getChineseMax()); label7.Text += "\n\n数学成绩最高分为:" + Convert.ToString(gr.
getMathMax()); label7.Text += "\n\n英语成绩最高分为:" + Convert.ToString(gr.
getEnglishMax()); //统计全班前3名的名单 label7.Text += "\n\n全班前三名的名单为:" + gr.getNames();
//指定课程不及格的学生名单 label7.Text += "\n\n指定科目“ " + textBox6.Text + " ” 不及格的名单:" + gr.
getStudentMenu(textBox6.Text); //指定课程在不同分数段的学生人数百分比 label7.Text += "\n\n指定科目“ "
+ textBox6.Text + " ” 不同分数段的百分比如下:" + gr.getStudentBFB(textBox6.Text); textBox6.
Text= ""; } else { MessageBox.Show("请输入您要查询的课程名称:"); } } private void
button3_Click(object sender, EventArgs e) { label7.Text = ""; if (textBox7.Text.
Trim() != "") { double result = gr.getSum(textBox7.Text); if (result == -1) {
MessageBox.Show("该学生不存在!"); } else { label7.Text = "学生:" + textBox7.Text + "
的总成绩为:" + Convert.ToString(result); textBox7.Text = ""; } } else { MessageBox.
Show("请输入您要查询的学生姓名"); } } private void textBox2_TextChanged(object sender,
EventArgs e) { } private void label8_Click_1(object sender, EventArgs e) { }
private void label9_Click(object sender, EventArgs e) { } } }

技术
©2019-2020 Toolsou All rights reserved,
Vue.js入门(五)---在vue中使用echarts词云Pandas统计分析基础_数据处理(DataFrame常用操作)element UI dialog点击dialog区域外会关闭dialog应届毕业生看过来!Java面试经典77问,看完离工作就不远了关于蓝桥杯大赛,你应该了解的那些事!mysql 分区-key分区(五)海康威视-嵌入式软件笔试题PHP Redis 监听过期的 key 事件C语言循环语句笔记详解以及练习-折半查找算法、猜数字游戏JVM概述