【水汐のC#】计一个Windows应用程序,在该程序中定义一个学生类和班级类,以处理学生的学号,姓名,语文,数学和英语3门课程的期末考试成绩。实现如下要求的功能:

设计一个Windows应用程序,在该程序中定义一个学生类和班级类,以处理学生的学号,姓名,语文,数学和英语3门课程的期末考试成绩。实现如下要求的功能:

  1. 根据姓名查询该学生的总成绩;
  2. 统计全班学生总分的平均成绩;
  3. 统计全班单科成绩最高分;
  4. 统计全班总分前三名的名单;
  5. 学生总容量不超过1000

设计提示:

  1. 定义一个Student学生类,包含字段(学号、姓名、语文成绩、数学成绩、英语成绩)和属性(总成绩)等。
  2. 定义一个Grade班级类,包含一个Student类数组(用来保存全班学生信息),一个表示学生人数的字段,以及若干个实现上述要求的方法等。
  3. 设计用户操作界面,分为三个区域。第一个区域为添加学生区域:让用户能输入一个学生的信息,单击“添加”按钮将该生信息添加到班级对象的学生数组中。第二个区域为查询区域:用户输入学生姓名,点击“查询”按钮,显示该生的总成绩,若不存在该生,则显示“该生不存在”。第三个区域为统计区域:点击“统计”按钮,显示全班平均成绩,单科最高分以及总分前三名的名单。
namespace 水汐窗体
{

	public partial class hiwari : Form
	{
		grade baga = new grade();
		static int studentsum = 0;
		public hiwari()
		{
			InitializeComponent();
		
		}

		public class Student
		{
			public string no;
			public string name;
			public double gradeofchinese;
			public double gradeofmath;
			public double gradeofenglish;
			public double gradeofsum;
			public Student(string a, string b,double c,double d, double e)
			{
				no = a;
				name = b;
				gradeofchinese = c;
				gradeofmath = d;
				gradeofenglish = e;
				gradeofsum = c + d + e;
				
			}
			public double returnsumgrade()
			{
				return gradeofsum;
			}
		}
		class grade
		{
			public Student[] a = new Student[1000];
			public void addstudent(string a, string b, double c, double d, double e)
			{
				//this.a[studentsum].
				//studentsum++;
			}
			public double returnallavegrade()
			{
				double ave = 0;
				for (int i = 0; i < studentsum; i++)
					ave += a[i].returnsumgrade();
				ave = ave / studentsum;
				return ave;
			}
			public double returnchinesebestgrade()
			{
				double  best = 0;
				for (int i = 0; i < studentsum; i++)
					if (a[i].gradeofchinese > best) best= a[i].gradeofchinese;
				return best;
			}
			public double returnmathbestgrade()
			{
				double best = 0;
				for (int i = 0; i < studentsum; i++)
					if (a[i].gradeofmath > best) best = a[i].gradeofmath;
				return best;
			}
			public double returnenglishbestgrade()
			{
				double best = 0;
				for (int i = 0; i < studentsum; i++)
					if (a[i].gradeofenglish > best) best = a[i].gradeofenglish;
				return best;
			}
			public string returnbestgrade3student()
			{
				string beststudent;
				double best = 0;
				int no1 = 0;
				int no2 = 0;
				int no3 = 0;
				for (int i = 0; i < studentsum; i++)
					if (a[i].returnsumgrade() > best) { best = a[i].returnsumgrade(); no1 = i; }
				beststudent= "first : "+a[no1].name;
				best = 0;
				for (int i = 0; i < studentsum; i++)
				 if (a[i].returnsumgrade() > best && i != no1) { best = a[i].returnsumgrade(); no2 = i; } 
				beststudent += "\nsecond : " + a[no2].name;
				best = 0;
				for (int i = 0; i < studentsum; i++)
				 if (a[i].returnsumgrade() > best && i != no1&&i!=no2) { best = a[i].returnsumgrade(); no3 = i; } 
				beststudent += "\nsecond : " + a[no3].name;
				return beststudent;
			}
		
		public string findstudent(string b)
		{			
			for (int i = 0; i < studentsum; i++)
				if (a[i].name ==b) return "np: "+a[i].no+"\nname: "+a[i].name+"\nchinese: "+a[i].gradeofchinese+"\nmath: "+a[i].gradeofmath+"\nenglish: "+a[i].gradeofenglish+"\nsum: "+a[i].gradeofsum;
				return "can't find it";
		}
	}
		private void button1_Click(object sender, EventArgs e)//phone
		{
			richTextBox1.Text ="ave: "+ baga.returnallavegrade();
			richTextBox1.Text+="\nchinese best: " + baga.returnchinesebestgrade();
			richTextBox1.Text += "\nmath best: " + baga.returnmathbestgrade();
			richTextBox1.Text += "\nenglish best: " + baga.returnenglishbestgrade();
			richTextBox1.Text += "\n  best3:\n " + baga.returnbestgrade3student();
		}

		private void button2_Click_1(object sender, EventArgs e)
		{
			baga.a[studentsum] = new Student(textBox1.Text,textBox2.Text,Convert.ToDouble(textBox3.Text),Convert.ToDouble(textBox4.Text),Convert.ToDouble(textBox5.Text));
			studentsum++;
			label7.Text = studentsum+" students had been enter";
		}

		private void button3_Click(object sender, EventArgs e)
		{
			richTextBox2.Text=baga.findstudent(textBox6.Text);
		}
	}
}

你可能感兴趣的:(C#)