用c#帮我写一个学生成绩管理系统
时间: 2023-08-02 08:35:01 浏览: 96
好的,以下是一个基本的C#学生成绩管理系统示例:
```
using System;
using System.Collections.Generic;
using System.Linq;
namespace StudentGradeManagement
{
class Program
{
static void Main(string[] args)
{
List<Student> students = new List<Student>();
while (true)
{
Console.WriteLine("1. 添加学生信息");
Console.WriteLine("2. 查看学生信息");
Console.WriteLine("3. 修改学生成绩");
Console.WriteLine("4. 删除学生信息");
Console.WriteLine("0. 退出");
int choice = Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 0:
Console.WriteLine("欢迎下次使用!");
return;
case 1:
Console.Write("请输入学生姓名:");
string name = Console.ReadLine();
Console.Write("请输入学生年龄:");
int age = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入学生性别:");
string gender = Console.ReadLine();
Console.Write("请输入学生成绩:");
double grade = Convert.ToDouble(Console.ReadLine());
students.Add(new Student(name, age, gender, grade));
Console.WriteLine("添加成功!");
break;
case 2:
Console.WriteLine("姓名\t年龄\t性别\t成绩");
foreach (Student student in students)
{
Console.WriteLine("{0}\t{1}\t{2}\t{3}", student.Name, student.Age, student.Gender, student.Grade);
}
break;
case 3:
Console.Write("请输入要修改成绩的学生姓名:");
string modifyName = Console.ReadLine();
Console.Write("请输入新的成绩:");
double modifyGrade = Convert.ToDouble(Console.ReadLine());
Student modifyStudent = students.Find(student => student.Name == modifyName);
if (modifyStudent != null)
{
modifyStudent.Grade = modifyGrade;
Console.WriteLine("修改成功!");
}
else
{
Console.WriteLine("找不到该学生!");
}
break;
case 4:
Console.Write("请输入要删除的学生姓名:");
string deleteName = Console.ReadLine();
int index = students.FindIndex(student => student.Name == deleteName);
if (index != -1)
{
students.RemoveAt(index);
Console.WriteLine("删除成功!");
}
else
{
Console.WriteLine("找不到该学生!");
}
break;
default:
Console.WriteLine("输入有误,请重新输入!");
break;
}
}
}
}
class Student
{
public string Name { get; set; }
public int Age { get; set; }
public string Gender { get; set; }
public double Grade { get; set; }
public Student(string name, int age, string gender, double grade)
{
Name = name;
Age = age;
Gender = gender;
Grade = grade;
}
}
}
```
这个示例代码包含了添加学生信息、查看学生信息、修改学生成绩和删除学生信息四个功能。你可以在这个基础上进行修改和完善,比如添加文件读写、搜索等功能。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)