当前位置:文档之家› C#学生信息管理系统源代码

C#学生信息管理系统源代码

using System;
using System.IO;


namespace Student_Information
{
class Student
{
struct stu_Information
{
public int Number;
public string Name;
public string Course;
public int Score;
};
private stu_Information Teststu;
static FileStream F;

StreamWriter W;
StreamReader R;

public void Add()
{
Console.Write("Please enter the student's number:");
Teststu.Number = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the student's name:");
https://www.doczj.com/doc/738309455.html, = Console.ReadLine();
Console.Write("Please enter the student's course:");
Teststu.Course = Console.ReadLine();
Console.Write("Please enter the student's score:");
Teststu.Score = Convert.ToInt32(Console.ReadLine());

F = new FileStream("MyFile.txt", FileMode.Append, FileAccess.Write);
W = new StreamWriter(F);

W.Write("Number:");
W.Write(Teststu.Number);
W.Write("*");
W.Write("Name:");
W.Write(https://www.doczj.com/doc/738309455.html,);
W.Write("*");
W.Write("Course:");
W.Write(Teststu.Course);
W.Write("*");
W.Write("Score:");
W.Write(Teststu.Score);
W.Write("*");

W.Flush();
W.Close();
}

public void View()
{
int MM = 0;
F = new FileStream("MyFile.txt", FileMode.Open, FileAccess.Read);
R = new StreamReader(F);
Console.Clear();
string str;
while ((str = R.ReadLine()) != null)
{
while (true)
{
MM = str.IndexOf("*");
if (MM == -1)
break;
Console.WriteLine(str.Substring(0, MM));
str = str.Substring(MM + 1);
}
MM = 0;
}

R.Close();
F.Close();
Console.ReadLine();
}

public void Search()
{
string LL, GG;
int MM, NN = 0;
F = new FileStream("MyFile.txt", FileMode.Open, FileAccess.Read);
R = new StreamReader(F);
Console.WriteLine("Please enter the course's name:");
string Cour = Convert.ToString(Console.ReadLine());

string str, S;

while ((str = S = R.ReadLine()) != null)
{
GG = "Course:" + Cour.ToString();
MM = NN = str.IndexOf("*");
LL = str.Substring(0, MM);
for (int i = 0; i < 3; i++)
{
NN = S.IndexOf("*");
LL = S.Substring(0, NN);

S = S.Substring(NN + 1);
}
if ((https://www.doczj.com/doc/738309455.html,pareTo(LL)) == 0)
{
while (true)
{
MM = str.IndexOf("*");
if (MM == -1)
break;
Console.WriteLine(str.Substring(0, MM));
str = str.Substring(MM + 1);
}
MM = 0;
}
}
Console.ReadLine();
R.Close();


}


static void Main(string[] args)
{
Student S = new Student();
int a = 0;
Console.Clear();


while (a != 4)
{
Console.WriteLine("--------------------------------------------------------------------------------");
Console.WriteLine(" The Students' Information Management System\n");
Console.WriteLine("--------------------------------------------------------------------------------");
Console.WriteLine("------------- 1. Add information -------------");
Console.WriteLine("------------- 2. Display all the scores -------------");
Console.WriteLine("------------- 3. Search the score -------------");
Console.WriteLine("------------- 4. Exit -------------");
Console.WriteLine(" \n\nEnter the number you want:");
Console.WriteLine("--------------------------------------------------------------------------------");
Console.WriteLine("--------------------------------------------------------------------------------");

a = Convert.ToInt32(Console.ReadLine());
switch (a)
{
case 1:
Console.Clear(); S.Add(); Console.Clear();
break;
case 2:
Console.Clear(); S.View(); Console.Clear();
break;
case 3:
Console.Clear(); S.Search(); Console.Clear();
break;
case 4:

break;
}
}

}
}
}



相关主题
文本预览
相关文档 最新文档