c 学生管理系统11

更新时间:2023-05-19 04:34:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.IO;//输入输出

namespace 道盟软件_学生管理系统

{

class Program

{

static void Main(string[] args)

{

//Console.Clear();//清屏

Interface();

Console.WriteLine();

Console.WriteLine();

Console.WriteLine();

Console.WriteLine(" 欢迎来到道盟软件!");

Console.WriteLine();

Console.WriteLine("按回车键继续.....");

Console.ReadLine();

int i = 0;

while (i <= 0)

{

Console.Clear();

Console.WriteLine("请选择以下操作1:增加2:查询3:删除4:修改q:退出");

string tmp = Console.ReadLine();

switch (tmp)

{

case "1": Increase(); break;

case "2": Inquiry(); break;

case "3": Delete(); break;

case "4": Revise(); break;

case "q": Console.WriteLine("欢迎下次再来!"); i = 1; break;

default: Console.WriteLine("没有此选项!请从新输入!"); break;

}

}

}

//主界面

static void Interface()

{

Console.WriteLine("************************************************************** **************");

Console.WriteLine("*

*");

Console.WriteLine("* 学生管理系统*");

Console.WriteLine("*

-道盟软件- *");

Console.WriteLine("************************************************************** **************");

}

//添加函数

static void Increase()

{

//定义一个字符串数组保存输入的数据

string[] element = new string[11];

Console.WriteLine("请输入学号");

element[0] = Console.ReadLine();

Console.WriteLine("请输入姓名");

element[1] = Console.ReadLine();

Console.WriteLine("请输入性别");

element[2] = Console.ReadLine();

while (true)

{

Console.WriteLine("请输入年龄");

element[3] = Console.ReadLine();

int tmp;

if (int.TryParse(element[3], out tmp))

{

break;

}

else

{

Console.WriteLine("输入错误!请重新输入");

}

}

Console.WriteLine("请输入联系方式");

element[4] = Console.ReadLine();

Console.WriteLine("请输入联系地址");

element[5] = Console.ReadLine();

Console.WriteLine("请输入班级名称");

element[6] = Console.ReadLine();

Console.WriteLine("请输入班主任");

element[7] = Console.ReadLine();

while (true)

{

Console.WriteLine("请输入语文成绩");

element[8] = Console.ReadLine();

double tmp;

if (double.TryParse(element[8], out tmp))

{

break;

}

else

{

Console.WriteLine("输入错误!请重新输入");

}

}

while (true)

{

Console.WriteLine("请输入数学成绩");

element[9] = Console.ReadLine();

double tmp;

if (double.TryParse(element[9], out tmp))

{

break;

}

else

{

Console.WriteLine("输入错误!请重新输入");

}

}

while (true)

{

Console.WriteLine("请输入英语成绩");

element[10] = Console.ReadLine();

double tmp;

if (double.TryParse(element[10], out tmp))

{

break;

}

else

{

Console.WriteLine("输入错误!请重新输入");

}

}

//即将修改文件

string[] lines = File.ReadAllLines(@".\学生管理系统文件.txt", Encoding.Default);

string temp = "";

for (int i = 0; i < lines.Length; i++)

{

temp += lines[i] + "";

}

string xin = "";

for (int i = 0; i < 11; i++)

{

if (i < 10)

xin += element[i] + "\t";

else

xin += element[i];

}

temp += xin + "";

File.WriteAllText(@".\学生管理系统文件.txt", temp, Encoding.Default);

Console.Clear();

while (true)

{

Console.WriteLine("输入:c继续q返回");

string tmp = Console.ReadLine();

if (tmp == "c")

{

Increase();

}

else if (tmp == "q")

{

return;

}

else

{

Console.WriteLine("输入错误!请重新输入");

}

}

}

//查询函数

static void Inquiry()

{

//读取文件的数据付给一个字符串数组

string[] lines = File.ReadAllLines(@".\学生管理系统文件.txt", Encoding.Default);

//定义一个字符串数组保存每一行的数据

string[] arr = new string[11];

string[] xh = new string[lines.Length - 1];

string[] xm = new string[lines.Length - 1];

string[] xb = new string[lines.Length - 1];

string[] nl = new string[lines.Length - 1];

string[] dh = new string[lines.Length - 1];

string[] dz = new string[lines.Length - 1];

string[] bj = new string[lines.Length - 1];

string[] bz = new string[lines.Length - 1];

string[] yw = new string[lines.Length - 1];

string[] sx = new string[lines.Length - 1];

string[] yy = new string[lines.Length - 1];

//切串赋值

for (int i = 1; i < lines.Length; i++)

{

string str = lines[i];

arr = str.Split('\t');

xh[i - 1] = arr[0];

xm[i - 1] = arr[1];

xb[i - 1] = arr[2];

nl[i - 1] = arr[3];

dh[i - 1] = arr[4];

dz[i - 1] = arr[5];

bj[i - 1] = arr[6];

bz[i - 1] = arr[7];

yw[i - 1] = arr[8];

sx[i - 1] = arr[9];

yy[i - 1] = arr[10];

}

int ii = 0;

while (ii <= 0)

{

Console.WriteLine("按回车键继续.....");

Console.ReadLine();

Console.Clear();

Console.WriteLine("请选择以下操作1:查询学号2:查询姓名3:查询

班级q:退出查询");

string tmp = Console.ReadLine();

Console.WriteLine("学号姓名性别年龄联系方式联系地址班级班主任语文数学英语");

switch (tmp)

{

case "1":

Console.WriteLine("请输入学号:");

string xuehao = Console.ReadLine();

int a = 1;

for (int i = 0; i < xh.Length; i++)

{

if (xuehao == xh[i])

{

Console.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10}", xh[i], xm[i], xb[i], nl[i], dh[i], dz[i], bj[i], bz[i], yw[i], sx[i], yy[i]);

Console.WriteLine();

a = i;

break;

}

}

if (a == 1)//判断进没进入上一个if 没有就执行

{

Console.WriteLine("你输入的学号不存在!");

Console.WriteLine();

}

break;

case "2":

Console.WriteLine("请输入姓名:");

string xingming = Console.ReadLine();

int b = 1;

for (int i = 0; i < xh.Length; i++)

{

if (xingming == xm[i])

{

Console.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10}", xh[i], xm[i], xb[i], nl[i], dh[i], dz[i], bj[i], bz[i], yw[i], sx[i], yy[i]);

Console.WriteLine();

b = i;

}

}

if (b == 1)

{

Console.WriteLine("你输入的姓名不存在!");

Console.WriteLine();

}

break;

case "3":

Console.WriteLine("请输入班级:");

string banji = Console.ReadLine();

int c = 1;

for (int i = 0; i < xh.Length; i++)

{

if (banji == bj[i])

{

Console.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10}", xh[i], xm[i], xb[i], nl[i], dh[i], dz[i], bj[i], bz[i], yw[i], sx[i], yy[i]);

Console.WriteLine();

c = i;

}

}

if (c == 1)

{

Console.WriteLine("你输入的班级不存在!");

Console.WriteLine();

}

break;

case "q":

ii = 1;//跳出循环

break;

default:

Console.WriteLine("输入有误!请重新输入!");

Console.WriteLine();

break;

}

}

}

//删除函数

static void Delete()

{

//File.Exists();检查文件是否存在

string[] lines = File.ReadAllLines(@".\学生管理系统文件.txt", Encoding.Default);

string[] arr = new string[11];

string[] xh = new string[lines.Length - 1];

string[] xm = new string[lines.Length - 1]; string[] xb = new string[lines.Length - 1]; string[] nl = new string[lines.Length - 1]; string[] dh = new string[lines.Length - 1]; string[] dz = new string[lines.Length - 1]; string[] bj = new string[lines.Length - 1]; string[] bz = new string[lines.Length - 1]; string[] yw = new string[lines.Length - 1]; string[] sx = new string[lines.Length - 1]; string[] yy = new string[lines.Length - 1]; for (int i = 1; i < lines.Length; i++)

{

string str = lines[i];

arr = str.Split('\t');

// Console.WriteLine(arr[2]);

xh[i - 1] = arr[0];

xm[i - 1] = arr[1];

xb[i - 1] = arr[2];

nl[i - 1] = arr[3];

dh[i - 1] = arr[4];

dz[i - 1] = arr[5];

bj[i - 1] = arr[6];

bz[i - 1] = arr[7];

yw[i - 1] = arr[8];

sx[i - 1] = arr[9];

yy[i - 1] = arr[10];

}

//删除文件

File.Delete(@".\学生管理系统文件.txt"); //定义一个字符串

string tmep = "";

int b = 0;

int a = 1;

while (b <= 0)

{

Console.WriteLine("请输入学号");

string tmp = Console.ReadLine();

for (int i = 0; i < xh.Length; i++)

{

if (tmp == xh[i])

{

a = i;//保存行的位置

b = 1;//跳出循环

break;

}

}

if (b == 0)

{

Console.WriteLine("查无此人,请确认是否输入正确");

Console.WriteLine("按回车键继续");

Console.ReadLine();

}

}

for (int i = 0; i < lines.Length; i++)

{

if (i != a + 1)

{

//将文件的数据付给字符串

tmep += lines[i] + "";

}

}

//创建文件并写入文件

File.WriteAllText(@".\学生管理系统文件.txt", tmep, Encoding.Default);//保存排除指定行的数据

}

//修改函数

static void Revise()

{

//File.Exists();检查文件是否存在

string[] lines = File.ReadAllLines(@".\学生管理系统文件.txt", Encoding.Default);

string[] arr = new string[11];

string[] xh = new string[lines.Length - 1];

string[] xm = new string[lines.Length - 1];

string[] xb = new string[lines.Length - 1];

string[] nl = new string[lines.Length - 1];

string[] dh = new string[lines.Length - 1];

string[] dz = new string[lines.Length - 1];

string[] bj = new string[lines.Length - 1];

string[] bz = new string[lines.Length - 1];

string[] yw = new string[lines.Length - 1];

string[] sx = new string[lines.Length - 1];

string[] yy = new string[lines.Length - 1];

for (int i = 1; i < lines.Length; i++)

{

string str = lines[i];

arr = str.Split('\t');

xh[i - 1] = arr[0];

xm[i - 1] = arr[1];

xb[i - 1] = arr[2];

nl[i - 1] = arr[3];

dh[i - 1] = arr[4];

dz[i - 1] = arr[5];

bj[i - 1] = arr[6];

bz[i - 1] = arr[7];

yw[i - 1] = arr[8];

sx[i - 1] = arr[9];

yy[i - 1] = arr[10];

}

int ii = 0;

while (true)

{

Console.WriteLine("修改以下操作:");

Console.WriteLine("1:姓名2:性别3:年龄4:电话5:地址6:班级7:班主任8:语文9:数学10:英语q:退出");

int tmp;

string str1 = Console.ReadLine();

//当输入q是跳出循环

if (str1 == "q")

{

break;

}

//当输入的是整数就返回,不是就报错

if (!int.TryParse(str1, out tmp)) //BAG:当输入大于10时

{

Console.WriteLine("没有此选项!请重新输入!");

continue;

}

Console.WriteLine("请输入学号");

string xuehao = Console.ReadLine();

for (int i = 0; i < xh.Length; i++)

{

if (xuehao == xh[i])

{

string xg = "";

switch (tmp)

{

case 1:

Console.WriteLine("请输入修改为");

xg = Console.ReadLine();

break;

case 2:

Console.WriteLine("请输入修改为");

xg = Console.ReadLine();

break;

case 3:

Console.WriteLine("请输入修改为");

xg = Console.ReadLine();

break;

case 4:

Console.WriteLine("请输入修改为");

xg = Console.ReadLine();

break;

case 5:

Console.WriteLine("请输入修改为");

xg = Console.ReadLine();

break;

case 6:

Console.WriteLine("请输入修改为");

xg = Console.ReadLine();

break;

case 7:

Console.WriteLine("请输入修改为");

xg = Console.ReadLine();

break;

case 8:

Console.WriteLine("请输入修改为");

xg = Console.ReadLine();

break;

case 9:

Console.WriteLine("请输入修改为");

xg = Console.ReadLine();

break;

case 10:

Console.WriteLine("请输入修改为");

xg = Console.ReadLine();

break;

default:

Console.WriteLine("输入有误!请重新输入!");

Console.WriteLine();

break;

}

Amend(i + 1, tmp, xg);//传出数组的坐标x,y和修改后的内容break;

}

else

{

if (ii == xh.Length - 1)

{

Console.WriteLine("你输入的学号不存在!请重新输入");

}

}

ii++;

}

}

}

//修改

static void Amend(int n, int m, string xg)

{

string[] lines = File.ReadAllLines(@".\学生管理系统文件.txt", Encoding.Default);

string[] arr = new string[11];

string[] xh = new string[lines.Length - 1];

string[] xm = new string[lines.Length - 1];

string[] xb = new string[lines.Length - 1];

string[] nl = new string[lines.Length - 1];

string[] dh = new string[lines.Length - 1];

string[] dz = new string[lines.Length - 1];

string[] bj = new string[lines.Length - 1];

string[] bz = new string[lines.Length - 1];

string[] yw = new string[lines.Length - 1];

string[] sx = new string[lines.Length - 1];

string[] yy = new string[lines.Length - 1];

for (int i = 1; i < lines.Length; i++)

{

string str = lines[i];

arr = str.Split('\t');

// Console.WriteLine(arr[2]);

xh[i - 1] = arr[0];

xm[i - 1] = arr[1];

xb[i - 1] = arr[2];

nl[i - 1] = arr[3];

dh[i - 1] = arr[4];

dz[i - 1] = arr[5];

bj[i - 1] = arr[6];

bz[i - 1] = arr[7];

yw[i - 1] = arr[8];

sx[i - 1] = arr[9];

yy[i - 1] = arr[10];

}

File.Delete(@".\学生管理系统文件.txt");

string temp = "";

for (int i = 0; i < lines.Length; i++)

{

string str = lines[i];

arr = str.Split('\t');

if (i == n)

{

for (int j = 0; j < 11; j++)

{

if (j == m)

{

arr[j] = xg;//修改

}

temp += arr[j] + "\t";

}

lines[i] = temp;

}

lines[i] += "";//换行

}

string stre = "";

for (int i = 0; i < lines.Length; i++)

{

stre += lines[i];

}

File.WriteAllText(@".\学生管理系统文件.txt", stre, Encoding.Default);

}

}

}

本文来源:https://www.bwwdw.com/article/ign4.html

Top