有没有哪位大哥能帮我把这个程序完善了(C#学生成绩管理系统)

Just小布 2011-05-04 05:19:51
using System;
using System.IO;
public class StudentInfo
{
private int id;
private string name;
private float english;
private float math;
public int ID
{
get
{
return this.id;
}
set
{
this.id = value;
}
}

public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}



public float English
{
get
{
return this.english;
}
set
{
this.english = value;
}
}
public float Math
{
get
{
return this.math;
}
set
{
this.math = value;
}
}
public float PJ()
{

return (english + math)/2;
}
}


public class StudentDAL // 学生数据管理类
{
const int MAX = 30;

int count = 0;

StudentInfo[] students = new StudentInfo[MAX];


public StudentInfo[] Students
{
get
{
return students;
}
}


public int Count
{
get
{
return this.count;
}
}


public bool Insert(StudentInfo stu)// 添加一个学生
{
if (Count < MAX)
{
students[this.count] = stu;//插入学生信息
this.count++;
return true;
}
return false;
}



public StudentInfo[] FindID(int id) //通过学号找
{
StudentInfo[] stu = new StudentInfo[MAX];
int count = 0;
for (int i = 0; i < Count; i++)
{
if (students[i].ID == id)
{
stu[count] = students[i];
count++;

}

}
if (count > 0) //找到了
{
StudentInfo[] temp = new StudentInfo[count];
for (int i = 0; i < count; i++)
{
temp[i] = stu[i];
}
return temp;
}

return null;
}

public StudentInfo[] FindByName(string name) //通过姓名找
{
StudentInfo[] stu = new StudentInfo[MAX];
int count = 0;
for (int i = 0; i < Count; i++)
{
if (students[i].Name == name)
{
stu[count] = students[i];
count++;
}
}
if (count > 0)
{
StudentInfo[] temp = new StudentInfo[count]; //有几个相同就把几个加入数组
for (int i = 0; i < count; i++)
{
temp[i] = stu[i];
}
return temp;
}
return null;
}

public class StudentBLL //操作
{
StudentDAL stuDAL = new StudentDAL();

public bool Insert(StudentInfo stu)
{
while (this.FindID(stu.ID) != null)
{
Console.Write("对不起,该学号已存在,请输入一个新的学号:");
stu.ID = int.Parse (Console .ReadLine ());
}
return stuDAL.Insert(stu);
}


public StudentInfo[] FindID(int id)
{
return stuDAL.FindID(id);
}


public StudentInfo[] FindByName(string name)
{
return stuDAL.FindByName(name);
}

public void PrintHead()
{
Console.WriteLine("学号\t姓名\t英语成绩\t数学成绩\t平均成绩");
}

public void Print(StudentInfo stu)
{
Console.WriteLine("{0}\t{1}\t{2}\t\t{3}\t\t{4}", stu.ID, stu.Name, stu.English, stu.Math, stu.PJ());
}


public void Print(StudentInfo[] stus)
{
foreach (StudentInfo stu in stus)
{
this.Print(stu);
}
}


public void Print()
{
if (stuDAL.Count > 0)
{
this.PrintHead();
for (int i = 0; i < stuDAL.Count; i++)
{
this.Print(stuDAL.Students[i]);
}
Console.WriteLine("当前共有{0}名学生。", stuDAL.Count);
}
else
{
Console.WriteLine("对不起,当前还没有学生信息。。。");
}
}

public StudentInfo GenStudentInfo(bool needID)
{
StudentInfo info = new StudentInfo();
if (needID)
{
Console.Write("请输入学生的学号:");
info.ID = int.Parse(Console.ReadLine());
}
Console.Write("请输入学生的姓名:");
info.Name = Console.ReadLine();
Console.Write("请输入学生的英语成绩:");
info.English = float.Parse(Console.ReadLine());
Console.Write("请输入学生的数学成绩");
info.Math = float.Parse(Console.ReadLine());
return info;
}
public StudentInfo GenStudentInfo()
{
return this.GenStudentInfo(true);
}

}

class Program
{
static void Main(string[] args)
{
StudentBLL stuBLL = new StudentBLL();

StudentInfo[] infos;
Console.WriteLine("-------------------学生成绩管理系统-------------------");
while (true)
{
Console.WriteLine("请按键选择您要进行的操作:");
Console.WriteLine("1.添加一个学生 2.查看所有学生信息");
Console.WriteLine("3.通过姓名查找学生 4.通过学号查找学生");
Console.WriteLine("5.英语平均分 6.数学平均分");
Console.WriteLine("7.英语最高分 8.数学最高分");
Console.WriteLine("q.退出程序");
switch (Console.ReadLine())
{
case "1":
if (stuBLL.Insert(stuBLL.GenStudentInfo()))
{
Console.WriteLine("添加成功。");
}
else
{
Console.WriteLine("添加失败,学生信息表已满。");
}
break;
case "2":
stuBLL.Print();
break;
case "3":
Console.Write("请输入要查找的学生的姓名:");
infos = stuBLL.FindByName(Console.ReadLine());
if (infos == null)
{
Console.WriteLine("对不起,您查找的学生不存在。");
}
else
{
stuBLL.PrintHead();
stuBLL.Print(infos);
}
break;

case "4":
Console.Write("请输入要查找的学生的学号:");
infos = stuBLL.FindID(int.Parse(Console.ReadLine()));
if (infos == null)
{
Console.WriteLine("对不起,您查找的学生不存在。");
}
else
{
stuBLL.PrintHead();
stuBLL.Print(infos);
}
break;
case "5":
{ }
break;
case "6":
{ }
break;
case "7":
{ }
break;
case "8":
{ }
break;

case "q":
return;
default:
Console.WriteLine("输入有误,请重新输入。");
break;
}
Console.WriteLine("按任意键继续(q键退出)...");
Console.ReadKey();
}
}
}
}

...全文
79 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
TNight 2011-05-04
  • 打赏
  • 举报
回复

using System;
using System.IO;
public class StudentInfo
{
private int id;
private string name;
private float english;
private float math;
public int ID
{
get
{
return this.id;
}
set
{
this.id = value;
}
}

public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}



public float English
{
get
{
return this.english;
}
set
{
this.english = value;
}
}
public float Math
{
get
{
return this.math;
}
set
{
this.math = value;
}
}
public float PJ()
{

return (english + math)/2;
}
}


public class StudentDAL // 学生数据管理类
{
const int MAX = 30;

int count = 0;

StudentInfo[] students = new StudentInfo[MAX];


public StudentInfo[] Students
{
get
{
return students;
}
}


public int Count
{
get
{
return this.count;
}
}


public bool Insert(StudentInfo stu)// 添加一个学生
{
if (Count < MAX)
{
students[this.count] = stu;//插入学生信息
this.count++;
return true;
}
return false;
}



public StudentInfo[] FindID(int id) //通过学号找
{
StudentInfo[] stu = new StudentInfo[MAX];
int count = 0;
for (int i = 0; i < Count; i++)
{
if (students[i].ID == id)
{
stu[count] = students[i];
count++;

}

}
if (count > 0) //找到了
{
StudentInfo[] temp = new StudentInfo[count];
for (int i = 0; i < count; i++)
{
temp[i] = stu[i];
}
return temp;
}

return null;
}

public StudentInfo[] FindByName(string name) //通过姓名找
{
StudentInfo[] stu = new StudentInfo[MAX];
int count = 0;
for (int i = 0; i < Count; i++)
{
if (students[i].Name == name)
{
stu[count] = students[i];
count++;
}
}
if (count > 0)
{
StudentInfo[] temp = new StudentInfo[count]; //有几个相同就把几个加入数组
for (int i = 0; i < count; i++)
{
temp[i] = stu[i];
}
return temp;
}
return null;
}

public class StudentBLL //操作
{
StudentDAL stuDAL = new StudentDAL();

public bool Insert(StudentInfo stu)
{
while (this.FindID(stu.ID) != null)
{
Console.Write("对不起,该学号已存在,请输入一个新的学号:");
stu.ID = int.Parse (Console .ReadLine ());
}
return stuDAL.Insert(stu);
}


public StudentInfo[] FindID(int id)
{
return stuDAL.FindID(id);
}


public StudentInfo[] FindByName(string name)
{
return stuDAL.FindByName(name);
}

public void PrintHead()
{
Console.WriteLine("学号\t姓名\t英语成绩\t数学成绩\t平均成绩");
}

public void Print(StudentInfo stu)
{
Console.WriteLine("{0}\t{1}\t{2}\t\t{3}\t\t{4}", stu.ID, stu.Name, stu.English, stu.Math, stu.PJ());
}


public void Print(StudentInfo[] stus)
{
foreach (StudentInfo stu in stus)
{
this.Print(stu);
}
}


public void Print()
{
if (stuDAL.Count > 0)
{
this.PrintHead();
for (int i = 0; i < stuDAL.Count; i++)
{
this.Print(stuDAL.Students[i]);
}
Console.WriteLine("当前共有{0}名学生。", stuDAL.Count);
}
else
{
Console.WriteLine("对不起,当前还没有学生信息。。。");
}
}

public StudentInfo GenStudentInfo(bool needID)
{
StudentInfo info = new StudentInfo();
if (needID)
{
Console.Write("请输入学生的学号:");
info.ID = int.Parse(Console.ReadLine());
}
Console.Write("请输入学生的姓名:");
info.Name = Console.ReadLine();
Console.Write("请输入学生的英语成绩:");
info.English = float.Parse(Console.ReadLine());
Console.Write("请输入学生的数学成绩");
info.Math = float.Parse(Console.ReadLine());
return info;
}
public StudentInfo GenStudentInfo()
{
return this.GenStudentInfo(true);
}

}

class Program
{
static void Main(string[] args)
{
StudentBLL stuBLL = new StudentBLL();

StudentInfo[] infos;
Console.WriteLine("-------------------学生成绩管理系统-------------------");
while (true)
{
Console.WriteLine("请按键选择您要进行的操作:");
Console.WriteLine("1.添加一个学生 2.查看所有学生信息");
Console.WriteLine("3.通过姓名查找学生 4.通过学号查找学生");
Console.WriteLine("5.英语平均分 6.数学平均分");
Console.WriteLine("7.英语最高分 8.数学最高分");
Console.WriteLine("q.退出程序");
switch (Console.ReadLine())
{
case "1":
if (stuBLL.Insert(stuBLL.GenStudentInfo()))
{
Console.WriteLine("添加成功。");
}
else
{
Console.WriteLine("添加失败,学生信息表已满。");
}
break;
case "2":
stuBLL.Print();
break;
case "3":
Console.Write("请输入要查找的学生的姓名:");
infos = stuBLL.FindByName(Console.ReadLine());
if (infos == null)
{
Console.WriteLine("对不起,您查找的学生不存在。");
}
else
{
stuBLL.PrintHead();
stuBLL.Print(infos);
}
break;

case "4":
Console.Write("请输入要查找的学生的学号:");
infos = stuBLL.FindID(int.Parse(Console.ReadLine()));
if (infos == null)
{
Console.WriteLine("对不起,您查找的学生不存在。");
}
else
{
stuBLL.PrintHead();
stuBLL.Print(infos);
}
break;
case "5":
{ }
break;
case "6":
{ }
break;
case "7":
{ }
break;
case "8":
{ }
break;

case "q":
return;
default:
Console.WriteLine("输入有误,请重新输入。");
break;
}
Console.WriteLine("按任意键继续(q键退出)...");
Console.ReadKey();
}
}
}
}



要下班了,先看下

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧