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
0
投稿
猜你喜欢
- BottomBarBottomBar是Github上的一个开源框架,因为从1.3.3开始不支持fragments了,要自己配置,弄了很久,不
- 本文实例为大家分享了Java实现简单贪吃蛇游戏的具体代码,供大家参考,具体内容如下贪吃蛇小游戏制作方法首先需要的准备有:1、掌握Java基础
- 前言:本文主要讲解以c语言编写猜数字游戏,目的是介绍C语言中的循环和分支的具体用法。一:猜数字游戏基本介绍&对程序预期.猜数字游戏,
- 静态代理: 由我们开发者自己手动创建或者在程序运行前就已经存在的代理类,静态代理通常只代理一个类, * 是代理一个接口下的多个实现类。动态
- 将SpringBoot项目部署到腾讯云注意:1、如果已经下载好MySql和JDK,可以直接跳过1、3步骤。但是不要忘记步骤2哦。2、如果已经
- 文章开始之前,先看一下效果图,看是不是您正所需要的:一、构建计算器的界面要构建出一个好看点的计算器界面,还是需要颇费些小心思的,我做这个的时
- 使用场景:自己项目对接多个外部系统,各个外部系统使用的字段并没有统一,所以要根据不同系统动态的输出序列化数据,使适应各个系统的要求实现方式使
- 目录什么是树形结构数据效果用法源码总结什么是树形结构数据效果用法String jsonStr = "{\"name\&q
- /// <summary> /// 实体转换辅助类 /// </summary> public class Mode
- 本文实例为大家分享了Java实现部门员工管理的具体代码,供大家参考,具体内容如下项目作业:部门员工管理题目要求:某公司要开发内部的 &
- 为什么要使用克隆? 想对一个对象进行处理,又想保留原有的数据进行接下来的操作,就需要克隆了,Java语言中克隆针对的是类的实例。如何实现对象
- 1.前言(基于JDK1.7)最近想把一些java基础的东西整理一下,但是又不知道从哪里开始!想了好久,还是从最基本的jvm开始吧!这一节就简
- 目录前言步入正题类的加载过程:1.加载2.验证3.准备4.解析5.初始化类加载器源码总结前言学生时代应抱着问题去学习一门语言,例如:在学习j
- 题主要区分清楚内码(internal encoding)和外码(external encoding)就好了。内码是程序内部使用的字符编码,特
- 本文实例讲述了C#线性渐变画刷LinearGradientBrush用法。分享给大家供大家参考。具体如下:using System;usin
- 本文实例讲述了C#实现身份证号码验证的方法。分享给大家供大家参考。具体实现方法如下:随着现在互联网的发展,越来越多的注册用户的地方都用到了身
- 由于近来学习java,遇到了一些在c++上没有的概念,将它记录下,以自己复习使用,如有不理解妥之处,望大家批评指导。资料均由网上经过自己整合
- 本文实例讲述了Android之复选框对话框用法。分享给大家供大家参考。具体如下:main.xml布局文件<?xml version=&
- 介绍Spring Cache是一个框架,实现了基于注解的缓存功能,只需要简单地加一个注解,就能实现缓存功能。Spring Cache提供了一
- 先看Demo运行效果SharedPreferences详解SharedPreferences是Android平台上一个轻量级的存储类,用来保