C#實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)
本文實(shí)例為大家分享了C#實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
使用鏈表寫(xiě)學(xué)生成績(jī)管理系統(tǒng)
鏈表可以靈活的展示增刪改查
下面是結(jié)果演示
這是登錄及部分添加

繼續(xù)添加

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

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

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

刪除再輸出

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. 在用戶(hù)登錄界面提示用戶(hù)輸入用戶(hù)名和密碼,并根據(jù)用戶(hù)名和密碼決定 ? ?能否登錄系統(tǒng)。
? ? ? ? ? ? // ? 3. 合法用戶(hù)登陸成功后,在屏幕上顯示如下功能菜單:
? ? ? ? ? ? // ? ? ? ? ?1.學(xué)生成績(jī)輸入 2.學(xué)生成績(jī)輸出 3.學(xué)生成績(jī)查詢(xún) 4.學(xué)生成績(jī)修改 0.退出系統(tǒng)
? ? ? ? ? ? // ? ? ? ? ? ?提示用戶(hù)輸入選擇號(hào),用戶(hù)輸入正確的選擇好后執(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ī)查詢(xún)
? ? ? ? ? ? ? ? ? ? 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ī)查詢(xún) 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開(kāi)發(fā)人姓名:馬志勇\t\t\t|");
? ? ? ? ? ? Console.WriteLine("|\t\t\t開(kāi)發(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ī)查詢(xún)\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("沒(méi)有數(shù)據(jù),無(wú)法修改!");
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? ? ? StudentNode temp = head.next;
? ? ? ? ? ? while (true) {
? ? ? ? ? ? ? ? if (temp==null) {
? ? ? ? ? ? ? ? ? ? Console.WriteLine("沒(méi)有這個(gè)ID數(shù)據(jù)!");
? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (temp.s.getId()== id) {
? ? ? ? ? ? ? ? ? ? temp.s.setScore(score);
? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? temp = temp.next;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? //查詢(xún)
? ? ? ? public Student search(int id)
? ? ? ? {
? ? ? ? ? ? if (head.next == null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.WriteLine("沒(méi)有數(shù)據(jù),無(wú)法修改!");
? ? ? ? ? ? ? ? return null;
? ? ? ? ? ? }
? ? ? ? ? ? StudentNode temp = head.next;
? ? ? ? ? ? while (true)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (temp == null)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.WriteLine("沒(méi)有這個(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é)生類(lèi)
? ? 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();
? ? ? ? }
? ? }
? ? //這是用戶(hù)類(lèi)
? ? 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;
? ? ? ? }
? ? }
}以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Winform開(kāi)發(fā)中使用下拉列表展示字典數(shù)據(jù)的幾種方式
這篇文章介紹了Winform開(kāi)發(fā)中使用下拉列表展示字典數(shù)據(jù)的幾種方式,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-09-09
C# 無(wú)需COM組件創(chuàng)建快捷方式的實(shí)現(xiàn)代碼
做一個(gè)小程序, 需要?jiǎng)?chuàng)建快捷方式, 網(wǎng)上普遍的做法是引入 COM 組件, 雖然也挺方便的, 但引入之后, 程序就需要多帶一個(gè) dll 文件, 這樣, 想做成單文件便攜版就不行了2011-05-05
C# Partial:分部方法和分部類(lèi)代碼實(shí)例
這篇文章主要介紹了C# Partial:分部方法和分部類(lèi)代碼實(shí)例,本文直接給出代碼實(shí)現(xiàn),需要的朋友可以參考下2015-03-03
C#線(xiàn)程處理系列之線(xiàn)程池中的I/O線(xiàn)程
這篇文章主要介紹了C#線(xiàn)程處理系列之線(xiàn)程池中的I/O線(xiàn)程,在這篇文章中將介紹如何用線(xiàn)程池中的I/O線(xiàn)程來(lái)執(zhí)行I/O操作,感興趣的小伙伴們可以參考一下2016-04-04
c# 線(xiàn)程安全隊(duì)列的用法原理及使用示例
這篇文章主要介紹了c# 線(xiàn)程安全隊(duì)列的用法原理及使用示例,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2020-11-11
WinForm實(shí)現(xiàn)程序一段時(shí)間不運(yùn)行自動(dòng)關(guān)閉的方法
這篇文章主要介紹了WinForm實(shí)現(xiàn)程序一段時(shí)間不運(yùn)行自動(dòng)關(guān)閉的方法,涉及WinForm計(jì)時(shí)器及進(jìn)程操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09
C#多線(xiàn)程系列之任務(wù)基礎(chǔ)(一)
本文詳細(xì)講解了C#多線(xiàn)程的任務(wù)基礎(chǔ),文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-02-02
C#實(shí)現(xiàn)定時(shí)任務(wù)Task Scheduler的示例代碼
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)定時(shí)任務(wù)Task Scheduler的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-02-02

