溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

C#實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)的代碼如何寫

發(fā)布時(shí)間:2022-08-03 17:41:57 來(lái)源:億速云 閱讀:188 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要介紹“C#實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)的代碼如何寫”,在日常操作中,相信很多人在C#實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)的代碼如何寫問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”C#實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)的代碼如何寫”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

下面是結(jié)果演示

這是登錄及部分添加

C#實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)的代碼如何寫

繼續(xù)添加

C#實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)的代碼如何寫

繼續(xù)添加及輸出成績(jī)

C#實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)的代碼如何寫

學(xué)生成績(jī)查詢

C#實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)的代碼如何寫

學(xué)生信息修改再輸出

C#實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)的代碼如何寫

刪除再輸出

C#實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)的代碼如何寫

0直接退出了

/*
        Author:馬志勇
        date:2020-10-14
*/


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //2. 在用戶登錄界面提示用戶輸入用戶名和密碼,并根據(jù)用戶名和密碼決定    能否登錄系統(tǒng)。
            //   3. 合法用戶登陸成功后,在屏幕上顯示如下功能菜單:
            //          1.學(xué)生成績(jī)輸入 2.學(xué)生成績(jī)輸出 3.學(xué)生成績(jī)查詢 4.學(xué)生成績(jī)修改 0.退出系統(tǒng)
            //            提示用戶輸入選擇號(hào),用戶輸入正確的選擇好后執(zhí)行相應(yīng)功能。執(zhí)行完對(duì)應(yīng)功   能后返回功能菜單。

            Console.WriteLine("歡迎來(lái)到成績(jī)管理系統(tǒng)!");
            while (true) {
                Console.WriteLine("***請(qǐng)輸入賬號(hào):");
                String userName = Console.ReadLine();
                Console.WriteLine("***請(qǐng)輸入密碼:");
                String userPassword = Console.ReadLine();
                if (userName.Equals("123456") && userPassword.Equals("456789"))
                {
                    Console.WriteLine("***賬號(hào)密碼正確請(qǐng)進(jìn)入");
                    break;
                }
                else {
                    Console.WriteLine("賬號(hào)密碼不一致,是否重新進(jìn)入![1:重新輸入---2:退出]");
                    int n = int.Parse(Console.ReadLine());
                    while (true) {
                        if (n == 1 || n == 2)
                        {
                            break;
                        }
                        else {
                            Console.WriteLine("***序號(hào)有誤請(qǐng)重新輸入!");
                            n = int.Parse(Console.ReadLine());
                        }
                    }
                    if (n==2) {
                        Process.GetCurrentProcess().Kill();
                    }
                }
            }

            showView();
            showChoice();

            StudentLinkedList link = new StudentLinkedList();
            
            
            while (true) {
                Console.WriteLine("***請(qǐng)選這些序號(hào) ");
                int n = int.Parse(Console.ReadLine());
                switch (n) {
                    //0.退出系統(tǒng)
                    case 0: {
                            Process.GetCurrentProcess().Kill();
                            break;
                        }
                    //1.學(xué)生成績(jī)輸入
                    case 1: {
                            Console.WriteLine("***請(qǐng)輸入ID賬號(hào):");
                            int id = int.Parse(Console.ReadLine());
                            Console.WriteLine("***請(qǐng)輸入姓名:");
                            String name = Console.ReadLine();
                            Console.WriteLine("***請(qǐng)輸入成績(jī):");
                            int score = int.Parse(Console.ReadLine());
                            link.add(getStudentNode(id, name, score));
                            break;
                        }
                    //2.學(xué)生成績(jī)輸出
                    case 2: {
                            link.show();
                            break;
                        }
                    // 3.學(xué)生成績(jī)查詢
                    case 3:
                        {
                            Console.WriteLine("***請(qǐng)輸入你要查找的id賬號(hào)");
                            int index = int.Parse(Console.ReadLine());
                            Student student=link.search(index);
                            Console.WriteLine(student.toString());
                            break;
                        }
                    //4.學(xué)生成績(jī)修改
                    case 4:
                        {
                            Console.WriteLine("***[注]:只能修改成績(jī)!");
                            Console.WriteLine("***請(qǐng)輸入你要修改的id賬號(hào)");
                            int index = int.Parse(Console.ReadLine());
                            Console.WriteLine("***請(qǐng)輸入你要修改的id分?jǐn)?shù)");
                            int score = int.Parse(Console.ReadLine());
                            link.upThis(index, score);
                            break;
                        }
                    case 5:
                        {
                            Console.WriteLine("***請(qǐng)輸入你要?jiǎng)h除的id賬號(hào)");
                            int index = int.Parse(Console.ReadLine());
                            link.delete(index);
                            break;
                        }
                    default: {
                            break;
                        }
                        
                        
                }
                showChoice();
            }
            Console.ReadKey();
        }


        //獲取節(jié)點(diǎn)對(duì)象
        public static StudentNode getStudentNode(int id,String name,int score ) {
            return new StudentNode(new Student(id,name,score));
        }

        //啟動(dòng)界面
        // 1.學(xué)生成績(jī)輸入 2.學(xué)生成績(jī)輸出 3.學(xué)生成績(jī)查詢 4.學(xué)生成績(jī)修改 0.退出系統(tǒng)
        public static void showView() {
            Console.WriteLine("|----------------------------程序啟動(dòng)---------------------------|");
            Console.WriteLine("|\t\t\t學(xué)生成績(jī)管理系統(tǒng)\t\t\t|");
            Console.WriteLine("|---------------------------------------------------------------|");
            Console.WriteLine("|\t\t\t開發(fā)人姓名:馬志勇\t\t\t|");
            Console.WriteLine("|\t\t\t開發(fā)時(shí)間:2020-20-14\t\t\t|");
            Console.WriteLine("|\t\t\t按任意鍵進(jìn)入系統(tǒng)\t\t\t|");
            Console.WriteLine("|---------------------------------------------------------------|");
        }
        public static void showChoice() {
            Console.WriteLine("|---------------------------------------------------------------|");
            Console.WriteLine("|\t\t\t0.退出系統(tǒng)\t\t\t\t|");
            Console.WriteLine("|\t\t\t1.學(xué)生成績(jī)輸入\t\t\t\t|");
            Console.WriteLine("|\t\t\t2.學(xué)生成績(jī)輸出\t\t\t\t|");
            Console.WriteLine("|\t\t\t3.學(xué)生成績(jī)查詢\t\t\t\t|");
            Console.WriteLine("|\t\t\t4.學(xué)生成績(jī)修改\t\t\t\t|");
            Console.WriteLine("|\t\t\t5.刪除這個(gè)學(xué)生\t\t\t\t|");
            Console.WriteLine("|---------------------------------------------------------------|");
        }

    }

    class StudentLinkedList
    {
        //定義一個(gè)頭結(jié)點(diǎn)啥都不放
        StudentNode head = null;
        public StudentLinkedList() {
            head=new StudentNode(null);
        }
        //添加 按照學(xué)號(hào)順序順序進(jìn)行添加
        //如果學(xué)號(hào)相同則不能添加
        public void add(StudentNode node)
        {
            if (head.next == null)
            {
                head.next = node;
                return;
            }
            //否則定義一個(gè)變量臨時(shí)變量進(jìn)行處理;
            StudentNode temp = head;
            int id = node.s.getId();
            bool flag = false;
            while (true)
            {
                if (temp.next == null)
                {
                    flag = false;
                    break;
                }
                if (temp.next.s.getId() > id)
                {
                    flag = false;
                    break;
                }
                else if (temp.next.s.getId() == id)
                {
                    //這個(gè)情況是有重復(fù)的就不能添加進(jìn)去
                    flag = true;
                    break;
                }
                temp = temp.next;
            }
            if (flag)
            {
                Console.WriteLine("這個(gè)序號(hào)已經(jīng)存在");
            }
            else {
                node.next=temp.next;
                temp.next = node;
            }
        }

        //刪除
        //只能通過(guò)id進(jìn)行刪除
        public bool delete(int id) {
            if (head.next==null) {
                return false;
            }
            StudentNode temp = head;
            while (true) {
                if (temp.next==null) {
                    return false;
                }

                if (temp.next.s.getId()==id) {
                    break;
                }
                temp = temp.next;
            }
            if (temp.next.next != null)
            {
                temp.next = temp.next.next;
            }
            else {
                temp.next = null;
            }

            return true;
        }

        //修改
        //只能修改成績(jī)
        public void upThis(int id,int score) {
            if (head.next == null)
            {
                Console.WriteLine("沒有數(shù)據(jù),無(wú)法修改!");
                return;
            }
            StudentNode temp = head.next;
            while (true) {
                if (temp==null) {
                    Console.WriteLine("沒有這個(gè)ID數(shù)據(jù)!");
                    return;
                }
                if (temp.s.getId()== id) {
                    temp.s.setScore(score);
                    return;
                }
                temp = temp.next;
            }
        }

        //查詢
        public Student search(int id)
        {
            if (head.next == null)
            {
                Console.WriteLine("沒有數(shù)據(jù),無(wú)法修改!");
                return null;
            }
            StudentNode temp = head.next;
            while (true)
            {
                if (temp == null)
                {
                    Console.WriteLine("沒有這個(gè)ID數(shù)據(jù)!");
                    return null;
                }
                if (temp.s.getId() == id)
                {
                    return new Student(temp.s.getId(), temp.s.getName(), temp.s.getScore());
                }
                temp = temp.next;
            }
        }

        //遍歷
        public void show() {
            Console.WriteLine("ID\t\t姓名\t\t分?jǐn)?shù)");
            StudentNode temp = head.next;
            while (true) {
                if (temp==null) {
                    break;
                }
                Console.WriteLine(temp.s.getId()+"\t\t"+temp.s.getName()+"\t\t"+temp.s.getScore());
                temp = temp.next;
            }
        }
    }


    //創(chuàng)建一個(gè)鏈表進(jìn)行處理這些數(shù)據(jù)
    class StudentNode
    {
        public Student s;
        public StudentNode next;
        public StudentNode(Student s)
        {
            this.s = s;
        }
    }
    //定義學(xué)生類
    class Student
    {
        private int id;
        private String name;
        private int score;
        public Student(int id, String name, int score)
        {
            this.id = id;
            this.name = name;
            this.score = score;
        }

        public void setId(int id)
        {
            this.id = id;
        }
        public int getId()
        {
            return this.id;
        }

        public String getName()
        {
            return this.name;
        }

        public void setName(String name)
        {
            this.name = name;
        }

        public int getScore()
        {
            return this.score;
        }

        public void setScore(int score)
        {
            this.score = score;
        }

        public String toString() {
            return "ID:"+getId() + "\t姓名:" + getName() + "\t成績(jī):" + getScore();
        }
    }

    //這是用戶類
    class User
    {
        private String userName;
        private String userParsword;
        public User(String userName, String userParsword)
        {
            this.userName = userName;
            this.userParsword = userParsword;
        }
        public String getUserName()
        {
            return this.userName;
        }

        public void setName(String userName)
        {
            this.userName = userName;
        }

        public String getUserParsword()
        {
            return this.userParsword;
        }

        public void setUserParsword(String userParsword)
        {
            this.userParsword = userParsword;
        }
    }
}

到此,關(guān)于“C#實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)的代碼如何寫”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI