using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace 学生信息管理系统
{
class Program
{
static void Addstudent() //新建学生信息
{
string ssudent;
Console.WriteLine("请输入学生的信息(学号、姓名、语文成绩、数学成绩、英语成绩):");
FileStream fs = new FileStream("C:\\mystudent.txt", FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, Encoding.Default);
ssudent = Console.ReadLine();
sw.WriteLine(ssudent);
sw.Close();
}
static void Searchstudent() { //查询学生信息
StreamReader sw = new StreamReader("C:\\mystudent.txt");
string[] array = new string[] { }; //保存学生的各天信息
string stu;
string number;
Console.WriteLine("请输入需要查询的学生的学号:");
number = Console.ReadLine();
double allscore, avgscore,alls;
allscore = avgscore = alls = Convert.ToDouble(0);
stu = sw.ReadLine();
while (stu != null)
{
array = stu.Split(' ');
allscore = Convert.ToDouble(array[2]) + Convert.ToDouble(array[3]) + Convert.ToDouble(array[4]);
alls += allscore;
if (array[0] == number||array[1]==number)
{
avgscore = allscore / 3;
Console.WriteLine("学生的学号 姓名 语文成绩 数学成绩 英语成绩各是:");
Console.WriteLine("{0} {1} {2} {3} {4}", array[0], array[1], array[2], array[3], array[4]);
Console.WriteLine("总成绩是:{0}\n平均成绩是:{1}\n", allscore, avgscore);
}
stu = sw.ReadLine();
}
Console.WriteLine("\n全部同学的总成绩是:{0}\n", alls);
sw.Close();
}
static void Main(string[] args)
{
do
{
Console.WriteLine("1、新建学生信息\n2、查询学生信息\n3、退出系统\n");
int choice;
Console.WriteLine("请输入你的选择:");
choice = Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 1:
Addstudent();
break;
case 2:
Searchstudent();
break;
case 3:
Environment.Exit(0);
break;
}
} while (true);
}
}
}