赞
踩
实现一个学生成绩管理系统,包括添加学生信息、删除学生信息、修改学生信息和查询学生信息等功能。
目录
using System;
using System.Collections.Generic;
class Student
{
public string Name { get; set; }
public int Age { get; set; }
public double Grade { get; set; }
}
class StudentManagementSystem
{
private List<Student> students = new List<Student>();
public void AddStudent(string name, int age, double grade)
{
var student = new Student { Name = name, Age = age, Grade = grade };
students.Add(student);
Console.WriteLine("学生信息已添加。");
}
public void RemoveStudent(string name)
{
var student = FindStudent(name);
if (student != null)
{
students.Remove(student);
Console.WriteLine("学生信息已删除。");
}
else
{
Console.WriteLine("未找到该学生信息。");
}
}
public void UpdateStudent(string name, int age, double grade)
{
var student = FindStudent(name);
if (student != null)
{
student.Age = age;
student.Grade = grade;
Console.WriteLine("学生信息已更新。");
}
else
{
Console.WriteLine("未找到该学生信息。");
}
}
public void GetStudentInfo(string name)
{
var student = FindStudent(name);
{
Console.WriteLine($"姓名: {student.Name}, 年龄: {student.Age}, 成绩: {student.Grade}");
}
{
Console.WriteLine("未找到该学生信息。");
}
}
private Student FindStudent(string name)
{
return students.Find(s => s.Name == name);
}
}
{
{
var system = new StudentManagementSystem();
system.AddStudent("张三", 20, 85.5);
system.AddStudent("李四", 21, 90.0);
system.GetStudentInfo("张三");
system.UpdateStudent("张三", 21, 90.0);
system.GetStudentInfo("张三");
system.RemoveStudent("李四");
system.GetStudentInfo("李四");
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。