C#实现学生成绩管理系统
作者:理想艺术!马 发布时间:2021-06-05 22:51:31
标签:C#,成绩,管理系统
本文实例为大家分享了C#实现学生成绩管理系统的具体代码,供大家参考,具体内容如下
使用链表写学生成绩管理系统
链表可以灵活的展示增删改查
下面是结果演示
这是登录及部分添加
继续添加
继续添加及输出成绩
学生成绩查询
学生信息修改再输出
删除再输出
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. 在用户登录界面提示用户输入用户名和密码,并根据用户名和密码决定 能否登录系统。
// 3. 合法用户登陆成功后,在屏幕上显示如下功能菜单:
// 1.学生成绩输入 2.学生成绩输出 3.学生成绩查询 4.学生成绩修改 0.退出系统
// 提示用户输入选择号,用户输入正确的选择好后执行相应功能。执行完对应功 能后返回功能菜单。
Console.WriteLine("欢迎来到成绩管理系统!");
while (true) {
Console.WriteLine("***请输入账号:");
String userName = Console.ReadLine();
Console.WriteLine("***请输入密码:");
String userPassword = Console.ReadLine();
if (userName.Equals("123456") && userPassword.Equals("456789"))
{
Console.WriteLine("***账号密码正确请进入");
break;
}
else {
Console.WriteLine("账号密码不一致,是否重新进入![1:重新输入---2:退出]");
int n = int.Parse(Console.ReadLine());
while (true) {
if (n == 1 || n == 2)
{
break;
}
else {
Console.WriteLine("***序号有误请重新输入!");
n = int.Parse(Console.ReadLine());
}
}
if (n==2) {
Process.GetCurrentProcess().Kill();
}
}
}
showView();
showChoice();
StudentLinkedList link = new StudentLinkedList();
while (true) {
Console.WriteLine("***请选这些序号 ");
int n = int.Parse(Console.ReadLine());
switch (n) {
//0.退出系统
case 0: {
Process.GetCurrentProcess().Kill();
break;
}
//1.学生成绩输入
case 1: {
Console.WriteLine("***请输入ID账号:");
int id = int.Parse(Console.ReadLine());
Console.WriteLine("***请输入姓名:");
String name = Console.ReadLine();
Console.WriteLine("***请输入成绩:");
int score = int.Parse(Console.ReadLine());
link.add(getStudentNode(id, name, score));
break;
}
//2.学生成绩输出
case 2: {
link.show();
break;
}
// 3.学生成绩查询
case 3:
{
Console.WriteLine("***请输入你要查找的id账号");
int index = int.Parse(Console.ReadLine());
Student student=link.search(index);
Console.WriteLine(student.toString());
break;
}
//4.学生成绩修改
case 4:
{
Console.WriteLine("***[注]:只能 * !");
Console.WriteLine("***请输入你要修改的id账号");
int index = int.Parse(Console.ReadLine());
Console.WriteLine("***请输入你要修改的id分数");
int score = int.Parse(Console.ReadLine());
link.upThis(index, score);
break;
}
case 5:
{
Console.WriteLine("***请输入你要删除的id账号");
int index = int.Parse(Console.ReadLine());
link.delete(index);
break;
}
default: {
break;
}
}
showChoice();
}
Console.ReadKey();
}
//获取节点对象
public static StudentNode getStudentNode(int id,String name,int score ) {
return new StudentNode(new Student(id,name,score));
}
//启动界面
// 1.学生成绩输入 2.学生成绩输出 3.学生成绩查询 4.学生成绩修改 0.退出系统
public static void showView() {
Console.WriteLine("|----------------------------程序启动---------------------------|");
Console.WriteLine("|\t\t\t学生成绩管理系统\t\t\t|");
Console.WriteLine("|---------------------------------------------------------------|");
Console.WriteLine("|\t\t\t开发人姓名:马志勇\t\t\t|");
Console.WriteLine("|\t\t\t开发时间:2020-20-14\t\t\t|");
Console.WriteLine("|\t\t\t按任意键进入系统\t\t\t|");
Console.WriteLine("|---------------------------------------------------------------|");
}
public static void showChoice() {
Console.WriteLine("|---------------------------------------------------------------|");
Console.WriteLine("|\t\t\t0.退出系统\t\t\t\t|");
Console.WriteLine("|\t\t\t1.学生成绩输入\t\t\t\t|");
Console.WriteLine("|\t\t\t2.学生成绩输出\t\t\t\t|");
Console.WriteLine("|\t\t\t3.学生成绩查询\t\t\t\t|");
Console.WriteLine("|\t\t\t4.学生成绩修改\t\t\t\t|");
Console.WriteLine("|\t\t\t5.删除这个学生\t\t\t\t|");
Console.WriteLine("|---------------------------------------------------------------|");
}
}
class StudentLinkedList
{
//定义一个头结点啥都不放
StudentNode head = null;
public StudentLinkedList() {
head=new StudentNode(null);
}
//添加 按照学号顺序顺序进行添加
//如果学号相同则不能添加
public void add(StudentNode node)
{
if (head.next == null)
{
head.next = node;
return;
}
//否则定义一个变量临时变量进行处理;
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)
{
//这个情况是有重复的就不能添加进去
flag = true;
break;
}
temp = temp.next;
}
if (flag)
{
Console.WriteLine("这个序号已经存在");
}
else {
node.next=temp.next;
temp.next = node;
}
}
//删除
//只能通过id进行删除
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;
}
//修改
//只能 *
public void upThis(int id,int score) {
if (head.next == null)
{
Console.WriteLine("没有数据,无法修改!");
return;
}
StudentNode temp = head.next;
while (true) {
if (temp==null) {
Console.WriteLine("没有这个ID数据!");
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("没有数据,无法修改!");
return null;
}
StudentNode temp = head.next;
while (true)
{
if (temp == null)
{
Console.WriteLine("没有这个ID数据!");
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分数");
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;
}
}
}
//创建一个链表进行处理这些数据
class StudentNode
{
public Student s;
public StudentNode next;
public StudentNode(Student s)
{
this.s = s;
}
}
//定义学生类
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成绩:" + 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;
}
}
}
来源:https://blog.csdn.net/mzy1711231996/article/details/109088492


猜你喜欢
- 最近一直在调用微信的API,却发现一直调用不成功,纠结了好久,各方面找教程,找官方,官方里的文档也只是写得很模糊,说是按三步走。1、申请Ap
- 一、前言对于任何框架而言,在使用前都要进行一系列的初始化,MyBatis也不例外。二、MyBatis的初始化做了什么2.1 Mybatis的
- using System;using System.Collections.Generic;using System.Linq;using
- equalsIgnoreCase() 方法用于将字符串与指定的对象比较,不考虑大小写。实例equals() 会判断大小写区别,equalsI
- 基于Java swing+MySQL实现学生信息管理系统:主要实现JDBC对学生信息进行增删改查,应付一般课设足矣,分享给大家。(由于篇幅原
- 一、前言微信接口调用验证最终需要用到的三个参数noncestr、timestamp、signature:接下来将会给出获取这三个参数的详细代
- 本文实例讲述了Android实现Service获取当前位置(GPS+基站)的方法。分享给大家供大家参考。具体如下:需求详情:1)、Servi
- jdk8之前 一、java.lang.Systemlong times = System.currentTimeMillis();
- 本文实例为大家分享了Java实现学生管理系统的具体代码,供大家参考,具体内容如下1.学生管理系统(控制台界面实现)//学生类,继承Seria
- 自定义View分为继承自View和ViewGroup,继承ViewGroup相比继承View在事件分发上ViewGroup多dispatch
- Spring中BeanFactory FactoryBean和ObjectFactory的三种的区别引言关于FactoryBean 和 Be
- 在WPF的DrawingContext对象中,提供了基本的绘制椭圆和矩形的API:DrawEllipse和DrawRectangle。但是,
- 前言本文详细介绍如何使用spring-boot2.x快速整合log4j2日志框架。spring-boot2.x使用logback作为默认日志
- 引用Spring官方文档的说法介绍一下@Conditional注解:Spring5.0.15版本@Conditional注解官方文档@Con
- 原理 Redis Cluster 一般由多个节点组成,节点数量至少为 6 个才能保证组成完整高可用的集群,其中三个为主
- 每一个应用程序,其实都会有分享的需求,比如一键分享一篇文章或者一些活动到微博或者微信亦或者是twitter等社交平台,因为人类是社交动物,而
- 前言最近接手了一个老项目,“愉悦的心情”自然无以言表,做开发的朋友都懂,这里就不多说了,都是泪...
- 1.配置自定义共享线程池(Spring线程池)@Configuration@EnableAsyncpublic class ThreadPo
- 1、前言Android Studio对模块化开发提供的一个很有用的功能就是可以在主项目下新建库项目(Module),但是在使用库项目时却有一
- 前言现在很多web应用,做过web项目的童鞋都知道,web结果由html+js+css组成,html结构都有一定的规范,数据动态交互可以通过