标签:c#
2.考试信息管理
(1)使用控制台程序做界面
(2)创建至少5个与考试有关的类
(3)完成考试成绩的录入、统计等功能
(4)测试要求:测试程序中用到的面向对象特性。
<span style="font-size:32px;color:#ff0000;">1.主函数</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestManage
{
public class Program
{
public static void Main(string[] args)
{
Menu me = new Menu();
me.caidan();
Console.ReadLine();
}
}
}
<span style="font-size:32px;color:#ff0000;">2.第一个类菜单类</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestManage
{
public class Menu
{
public void caidan()
{
Input pu = new Input();//成绩录入
MaxScore ms = new MaxScore();//每门课最高分
MinScore mi = new MinScore();//每门课最低分
EveryAvg av = new EveryAvg();//每门课平均分
Allavg al = new Allavg();//总课程的平均分
AllavgOrder ao = new AllavgOrder();//按总课程平均分排序
Show sh = new Show();//显示各科成绩
for (int m = 0; ; m++)
{
Console.WriteLine(" 学生成绩统计 ");
Console.WriteLine("=========================================");
Console.WriteLine(" 1.成绩录入");
Console.WriteLine(" 2.每门课最高分");
Console.WriteLine(" 3.每门课最低分");
Console.WriteLine(" 4.每门课平均分");
Console.WriteLine(" 5.总课程的平均分");
Console.WriteLine(" 6.按总课程平均分排序");
Console.WriteLine(" 7.显示各科成绩");
Console.WriteLine(" 8.退出");
Console.WriteLine("=========================================");
Console.WriteLine("请输入你要执行的项目序号:");
int k = int.Parse(Console.ReadLine());
if (k == 8) { break; }
else
{
switch (k)
{
case 1: pu.luru(); break;
case 2:
Console.Clear();
ms.max(); break;
case 3:
Console.Clear();
mi.min(); break;
case 4:
Console.Clear();
av.avg(); break;
case 5:
Console.Clear();
al.allavg(); break;
case 6:
Console.Clear();
ao.allavgpaixu(); break;
case 7:
Console.Clear();
sh.xianshi(); break;
}
}
}
}
}
}
<span style="font-size:32px;color:#ff0000;">3.成绩录入类</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestManage
{
public class Input
{
public static int N { get; set; }
public static int F { get; set; }
public static double[] allavg2 { get; set; }
public static double[,] score { get; set; }
public Input()
{
N = 2;//人数
F = 3;//课的数目
allavg2 = new double[N];
score = new double[N, F];
}
public void luru() //录入函数
{
for (int i = 0; i < N; i++)
{
Console.WriteLine("请输入第" + (i + 1) + "个学生的三门课的成绩");
for (int j = 0; j < F; j++)
{
score[i, j] = double.Parse(Console.ReadLine());
}
}
}
}
}
<span style="font-size:32px;color:#ff0000;">4.每门课最高分类</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestManage
{
public class MaxScore:Input
{
public void max()
{
for (int j = 0; j < F; j++)
{
int max = 0;
for (int k = 0; k < N - 1; k++)
{
if (score[max, j] < score[k + 1, j])
{
max = k + 1;
}
}
Console.WriteLine("课程" + (j + 1) + "的最高分为" + score[max, j]);
}
}
}
}
<span style="font-size:32px;color:#ff0000;">5.每门课最低分类</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestManage
{
public class MinScore:Input
{
public void min()
{
for (int j = 0; j < F; j++)
{
int min = 0;
for (int k = 0; k < N - 1; k++)
{
if (score[min, j] > score[k + 1, j])
{
min = k + 1;
}
}
Console.WriteLine("课程" + (j + 1) + "的最低分为" + score[min, j]);
}
}
}
}
<span style="font-size:32px;color:#ff0000;">6.每门课评价分类</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestManage
{
public class EveryAvg:Input
{
public void avg()
{
double sum = 0, avg;
for (int j = 0; j < F; j++)
{
for (int k = 0; k < N; k++)
{ sum = sum + score[k, j]; }
avg = sum / N;
sum = 0;
Console.WriteLine("课程" + (j + 1) + "的平均分为" + avg);
}
}
}
}
<span style="font-size:32px;color:#ff0000;">7.总课程平均分类</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestManage
{
public class Allavg:Input
{
public void allavg()
{
double sum = 0;
for (int j = 0; j < N; j++)
{
for (int k = 0; k < F; k++)
{ sum = sum + score[j, k]; }
allavg2[j] = sum / F;
sum = 0;
}
for (int k = 0; k < 10; k++)
{
try
{
Console.WriteLine("学号为 " + (k + 1) + "的平均成绩为" + allavg2[k]);
}
catch(Exception ex)
{ }
}
}
}
}
<span style="font-size:32px;color:#ff0000;">8.按总课程平均排序类</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestManage
{
public class AllavgOrder : Input
{
public void allavgpaixu()
{
for (int j = 0; j < 9; j++)
{
for (int k = 0; k < 9 - j; k++)
{
try
{
if (allavg2[k] < allavg2[k + 1])
{
double temp;
temp = allavg2[k];
allavg2[k] = allavg2[k + 1];
allavg2[k + 1] = temp;
}
}
catch (Exception ex)
{ }
}
} Console.WriteLine("对平均成绩排序为");
for (int j = 0; j < 10; j++)
{
try
{
Console.WriteLine(allavg2[j]);
}
catch (Exception ex) { }
}
}
}
}
<span style="font-size:32px;color:#ff0000;">9.显示各科成绩类</span>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestManage
{
public class Show:Input
{
public void xianshi()
{
Console.WriteLine("学号 课程1 课程2 课程3");
for (int j = 0; j < 10; j++)
{
try
{
Console.WriteLine(j + " " + score[j, 0] + " "
+ score[j, 1] + " " + score[j, 2]);
}
catch (Exception ex)
{ Console.WriteLine(ex.Message); }
}
}
}
}
标签:c#
原文地址:http://blog.csdn.net/qq_19434741/article/details/41044219