using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace @string
{
class Program
{
static void Main(string[] args)
{
Stu_Manage myuser = new Stu_Manage();
myuser.Chech();
}
}
public class Student
{
public int no;
public double math, english;
public double csharp, network;
public double avg, all;
public string name;
//显示学生信息
public void ShowStuInfo()
{
Console.WriteLine("\n学生信息:");
Console.WriteLine("\n学号:{0}", no);
Console.WriteLine("\t姓名:{1}:", name);
Console.WriteLine("\t数学:{2}", math);
Console.WriteLine("\t英语:{3}", english);
Console.WriteLine("\t c#:{4}", csharp);
Console.WriteLine("\t计算机网络:{5}", network);
Console.WriteLine("\t平均成绩:{6}", avg);
Console.WriteLine("\t总成绩:{7}", all);
Console.WriteLine();
}
}
//定义学生信息管理类
class Stu_Manage
{
int x = 0;
//声明一个结构体类数组,数组名stud
Student[] stud = new Student[10];
//Add()方法添加学生信息
public void Add()
{
Console.WriteLine("请输入要添加的学生的信息:");
Console.WriteLine("请输入学号:");
stud[x].no = int.Parse(Console.ReadLine());
Console.WriteLine("\n请输入姓名:");
stud[x].name = Console.ReadLine();
Console.WriteLine("\n数学成绩:");
stud[x].math = double.Parse(Console.ReadLine());
Console.WriteLine("\n英语成绩:");
stud[x].english = double.Parse(Console.ReadLine());
Console.WriteLine("\nC#成绩:");
stud[x].csharp = double.Parse(Console.ReadLine());
Console.WriteLine("\n计算机网络成绩:");
stud[x].network = double.Parse(Console.ReadLine());
//定义一个数组将输入的成绩存储
double[] inform = new double[] { stud[x].math, stud[x].english, stud[x].csharp, stud[x].network };
for (int i = 0; i < inform.Length; i++)
{
stud[x].all += inform[i];
stud[x].avg = stud[x].all / 4;
stud[x].ShowStuInfo();
x = x + 1;
}
}
public void Delete()
{
int n = -1;
int no = int.Parse(Console.ReadLine());
for (int i = 0; i < x; i++)
{
if (no == stud[i].no)
{
n = i;
for (int c = n + 1; c < x; c++)
{
//交换数组索引值,对指定元素进行删除
stud[c - 1] = stud[c];
}
x = x - 1;
break;
}
}
}
public void Search_no()
{
int n = -1;
int no = int.Parse(Console.ReadLine());
for (int i = 0; i < x; i++)
{
if (no == stud[i].no)
{
n = i;
stud[i].ShowStuInfo();
break;
}
}
if (n == -1)
{
Console.WriteLine();
}
}
public void Search_name()
{
int n = -1;
string name = Console.ReadLine();
for (int i = 0; i < x; i++)
{
if (name == stud[i].name)
{
n = i;
stud[i].ShowStuInfo();
break;
}
}
if (n == -1)
{
Console.WriteLine();
}
}
public void Search_score()
{
for (int i = x - 1; i >= 0; i--)
{
for (int j = 0; j <= i; j++)
{
if (stud[j].all > stud[j + 1].all)
{
stud[x] = stud[j];
stud[j] = stud[j + 1];
stud[j + 1] = stud[x];
}
}
}
int[] mc = new int[x];
for (int i = 0; i < x; i++)
{
mc[i] = i + 1;
Console.WriteLine(stud[i].no + "\t");
Console.WriteLine(stud[i].name + "\t");
Console.WriteLine(stud[i].math + "\t");
Console.WriteLine(stud[i].english + "\t");
Console.WriteLine(stud[i].csharp + "\t");
Console.WriteLine(stud[i].network + "\t");
Console.WriteLine(stud[i].avg + "\t");
Console.WriteLine(stud[i].all + "\t");
Console.WriteLine();
}
}
public void Chech()
{
do
{
Console.WriteLine("请选择:\n 1、添加学生信息\n 2、删除学生信息\n 3、查询按学号\n 4、查询按姓名\n 5、查询成绩单\n 6、退出系统");
int number = int.Parse(Console.ReadLine());
if (number > 6 || number < 1)
{
Console.WriteLine("输入有误请重新输入");
}
switch (number)
{
case 1:
Add();
break;
case 2:
Console.WriteLine("请输入要删除学生的学号:");
Delete();
break;
case 3:
Console.WriteLine("请输入学号:");
Search_no();
break;
case 4:
Console.WriteLine("请输入姓名:");
Search_name();
break;
case 5:
Console.WriteLine("成绩单:");
Console.WriteLine("名次\t学号\t姓名\t数学\t英语\tC#\t计算机网络\t平均\t总成绩");
Search_score();
break;
case 6:
Environment.Exit(0);
break;
}
Console.WriteLine("\n是否要继续!");
} while (true);
}
}
}
学生成绩管理系统
最新推荐文章于 2022-04-28 11:49:11 发布