设计一个简单的学生信息管理系统,学生信息包括学号、姓名、年龄、性别、专业、学院等。要求实现以下功能: (1)学生信息录入功能; (2)学生信息浏览功能; (3)学生信息查询功能,按学号、姓名查询; (4)学生信息的删除与修改。
时间: 2024-11-25 09:08:37 浏览: 3
设计一个简单的学生信息管理系统,可以采用结构化程序设计的思想,使用对象导向语言如Python或Java来实现。以下是基于Python的一个简要设计:
```python
class Student:
def __init__(self, id, name, age, gender, major, college):
self.id = id
self.name = name
self.age = age
self.gender = gender
self.major = major
self.college = college
class StudentManagementSystem:
def __init__(self):
self.students = []
# 学生信息录入
def add_student(self, student_data):
new_student = Student(*student_data)
self.students.append(new_student)
# 学生信息浏览
def view_students(self):
for student in self.students:
print(f"ID: {student.id}, Name: {student.name}, Age: {student.age}, Gender: {student.gender}, Major: {student.major}, College: {student.college}")
# 学生信息查询
def search_student(self, query_type, query_value):
if query_type == "id":
for student in self.students:
if student.id == int(query_value):
return student
elif query_type == "name":
for student in self.students:
if student.name == query_value:
return student
else:
print("Invalid query type")
# 学生信息删除与修改
def delete_student(self, student_id):
self.students = [student for student in self.students if student.id != student_id]
def update_student(self, student_id, updated_data):
for i, student in enumerate(self.students):
if student.id == student_id:
self.students[i] = Student(student.id, *updated_data)
break
# 使用示例
sms = StudentManagementSystem()
sms.add_student(["1001", "张三", 20, "男", "计算机科学", "计算机学院"])
sms.view_students()
# 查询
search_result = sms.search_student("id", "1001")
print(search_result.name) # 输出张三
# 删除与更新
sms.delete_student(1001)
sms.update_student(1002, ["1002", "李四", 22, "女", "软件工程", "软件学院"])
```
阅读全文