C#--作业5:利用数组编写程序实现控制台的学生成绩管理系统

利用数组编写程序实现控制台的学生成绩管理系统。具体要求如下:

1.程序运行时,先显示启动界面,启动界面上至少包括系统名称、开发人姓名和开发时间,按任意键后进入用户登录界面。

2.在用户登录界面提示用户输入用户名和密码,并根据用户名和密码决定能否登录系统。

3.合法用户登陆成功后,在屏幕上显示如下功能菜单:

1.学生成绩输入2.学生成绩输出3. 学生成绩查询4.学生成绩修改0.退出系统

提示用户输入选择号,用户输入正确的选择好后执行相应功能。执行完对应功能后返回功能菜单。

在这里插入代码片
using System;

namespace StuProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            string[,] student = new string[3, 7];
            Console.WriteLine("===========学生成绩管理系统===========");
            Console.WriteLine("======================================");
            Console.Write("==请输入用户名:");
            string username = Console.ReadLine();
            Console.Write("==请输入密码:");
            string password = Console.ReadLine();
            string user = "哆啦A梦";
            string key = "12345678";
            int count = 1;
            bool flag = true;
            while (flag == true)
            {
                if (username == user && password == key)
                {
                    Console.WriteLine("===============欢迎进入===============");
                    Console.WriteLine("=系统名称:学生成绩管理系统          =");
                    Console.WriteLine("=开发者:哆啦A梦                    =");
                    Console.WriteLine("=开发时间:2020/3/9                  =");
                    Console.WriteLine("======================================");
                }
                else
                {
                    if (count >= 3)
                    {
                        Console.WriteLine("三次输入错误,请退出重新登录");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("用户名或密码错误!请您重新输入,您还有{0}次机会", 3 - count);
                        Console.Write("=请重新输入用户名:               =");
                        username = Console.ReadLine();
                        Console.Write("=请重新输入密码:                = ");
                        password = Console.ReadLine();
                        count++;
                    }
                }
                Console.WriteLine("===============菜单选择===============");
                Console.WriteLine("=1.学生成绩输入:                    =");
                Console.WriteLine("=2.学生成绩输出:                    =");
                Console.WriteLine("=3.学生成绩查询:                    =");
                Console.WriteLine("=4.学生成绩修改:                    =");
                Console.WriteLine("=5.退出系统:                        =");
                Console.WriteLine("======================================");
                Console.WriteLine("=请选择(1-5):                       =");
                int choice = int.Parse(Console.ReadLine());
                switch (choice)
                {
                    case 1:
                        {
                            Console.WriteLine("======================================");
                            Console.WriteLine("=1.学生成绩输入:                    =");
                            Input(student, 3);
                            break;
                        }
                    case 2:
                        {
                            Console.WriteLine("======================================");
                            Console.WriteLine("=2.学生成绩输出:                    =");
                            Output(student, 3);
                            break;
                        }
                    case 3:
                        {
                            Console.WriteLine("======================================");
                            Console.WriteLine("=3.学生成绩查询:                    =");
                            Console.WriteLine("=请输入学生学号查询:                =");
                            string id = Console.ReadLine();
                            Search(student, id);
                            break;
                        }
                    case 4:
                        {
                            Console.WriteLine("======================================");
                            Console.WriteLine("=4.学生成绩修改:                    =");
                            Console.WriteLine("请输入学号:");
                            string id = Console.ReadLine();
                            change(student, id);
                            break;
                        }
                    case 5:
                        {
                            Console.WriteLine("======================================");
                            Console.WriteLine("=5.退出系统:                        =");
                            break;
                        }
                }
            }
        }
        //输入
        static void Input(string[,] student, int num)
        {
            int t;
            string strStudent = string.Empty;
            string[] strInfo;
            Console.WriteLine("=请输入学生信息(用空格分开):学号、姓名、语文、数学、英语");
            for (int i = 0; i < num; i++)
            {
                Console.Write("=请输入第{0}个学生信息:", i + 1);
                strStudent = Console.ReadLine();
                strInfo = strStudent.Split(' ');
                for (int j = 0; j < strInfo.Length; j++)
                {
                    student[i, j] = strInfo[j];
                }
                // 计算总分
                t = Convert.ToInt32(student[i, 2]) + Convert.ToInt32(student[i, 3]) + Convert.ToInt32(student[i, 4]);
                student[i, 5] = Convert.ToString(t);
                student[i, 6] = string.Format(" {0:f2}", t / 3.0);
            }
        }
        //输出
        static void Output(string[,] student, int num)
        {
            string strStudenet = string.Empty;
            Console.WriteLine();
            Console.WriteLine("=该学生信息为                        =");
            Console.WriteLine("======================================");
            Console.WriteLine("=学号=姓名=语文=数学=英语=总分=平均分=");
            Console.WriteLine("======================================");
            for (int i = 0; i < num; i++)
            {
                Console.WriteLine("={0,8}={1,3}={2,4}={3,4}={4,4}={5,5}={6,6:F2)}=", student[i, 0],
                    student[i, 1], student[i, 2], student[i, 3], student[i, 4], student[i, 5], student[i, 6]);
                Console.WriteLine("======================================");
            }
        }
        //查找
        static void Search(String[,] student, string id)
        {
            int i = 0;
            for (; i < student.Length; i++)
            {
                if (student[i, 0] == id)
                {
                    Console.WriteLine("=该学生信息为                        =");
                    Console.WriteLine("======================================");
                    Console.WriteLine("=学号=姓名=语文=数学=英语=总分=平均分=");
                    Console.WriteLine("======================================");
                    Console.WriteLine("={0,8}={1,3}={2,4}={3,4}|{4,4}={5,5}={6,6:F2)}=", student[i, 0], 
                        student[i, 1], student[i, 2], student[i, 3], student[i, 4], student[i, 5], student[i, 6]);
                    break;
                }
            }
            if (i >= student.Length)
            {
                Console.WriteLine("查找失败,该学号不存在! ");
            }

        }
        //修改
        static void change(String[,] student, string idl)
        {
            int i = 0;
            for (; i < student.Length; i++)
            {
                if (student[i, 0] == idl)
                {
                    Console.WriteLine("=该学生信息为                        =");
                    Console.WriteLine("======================================");
                    Console.WriteLine("=学号=姓名=语文=数学=英语=总分=平均分=");
                    Console.WriteLine("={0,8}={1,3}={2,4}={3,4}|{4,4}={5,5}={6,6:F2)}=", student[i, 0], student[i, 1], student[i, 2], student[i, 3], student[i, 4], student[i, 5], student[i, 6]);
                    Console.WriteLine();
                    Console.WriteLine("可修改的序号选项: 0、结束修改1.姓名2、语文成绩3、数学成绩4、英语成绩");
                    Console.Write("=请输入要修改的序号选项: ");
                    int j = Convert.ToInt32(Console.ReadLine());
                    while (j != 0)
                    {
                        switch (j)
                        {
                            case 0:
                                Console.WriteLine("=修改结束=================================");
                                break;
                            case 1:
                                Console.Write("=1.请输入修改后的姓名: ");
                                student[i, 1] = Console.ReadLine();
                                break;
                            case 2:
                                Console.Write("2.请输入修改后的语文成绩: ");
                                student[i, 2] = Console.ReadLine();
                                break;
                            case 3:
                                Console.Write("3.请输入修改后的数学成绩: ");
                                student[i, 3] = Console.ReadLine();
                                break;
                            case 4:
                                Console.Write("4.请输入修改后的英语成绩: ");
                                student[i, 4] = Console.ReadLine();
                                break;
                            default:
                                Console.WriteLine("输入错误!请重新输入:");
                                break;
                        }
                        Console.WriteLine("可修改的序号选项: 0、结束修改1、姓名2、语文成绩3、数学成绩4、英语成绩");
                        Console.Write("请输入要修改的序号选项: ");
                        j = Convert.ToInt32(Console.ReadLine());
                    }
                    //计算总分
                    int t = Convert.ToInt32(student[i, 2]) + Convert.ToInt32(student[i, 3]) + Convert.ToInt32(student[i, 4]); 
                        student[i, 5] = Convert.ToString(t); student[i, 6] = string.Format(" {0:F2}", t/ 3.0);
                    Console.WriteLine("=修改后的学生信息为");
                    Console.WriteLine("======================================");
                    Console.WriteLine("=学号=姓名=语文=数学=英语=总分=平均分=");
                    Console.WriteLine("======================================");
                    Console.WriteLine("={0, 8}={1,3} ={2, 4}={3, 4}={4, 4}= {5, 5}= {6, 6:F2)=}", student[i, 0], student[i, 1], 
                        student[i, 2], student[i, 3], student[i, 4], student[i, 5], student[i, 6]);
                    break;
                }

                if (i >= student.Length)
                {
                    Console.WriteLine("=查找失败,该学号不存在!             =");
                }
            }
        }
    }
}

你可能感兴趣的:(C#--作业5:利用数组编写程序实现控制台的学生成绩管理系统)