学生信息管理系统设计每个学生的信息包括:学号、姓名、性别、出生年月、数学、语文、英语三科成绩、总分。要求系统能够完成信息的一般增、删、改、查功能。python
时间: 2023-05-27 16:02:30 浏览: 147
C++课程设计_学生成绩信息管理系统
代码实现:
```python
class Student:
def __init__(self, sid, name, gender, birth, math, chinese, english):
self.sid = sid
self.name = name
self.gender = gender
self.birth = birth
self.math = math
self.chinese = chinese
self.english = english
def total_score(self):
return self.math + self.chinese + self.english
class StudentManagement:
def __init__(self):
self.students = []
def add_student(self, student):
self.students.append(student)
def remove_student(self, sid):
for student in self.students:
if student.sid == sid:
self.students.remove(student)
return True
return False
def modify_student(self, sid, name=None, gender=None, birth=None, math=None, chinese=None, english=None):
for student in self.students:
if student.sid == sid:
if name is not None:
student.name = name
if gender is not None:
student.gender = gender
if birth is not None:
student.birth = birth
if math is not None:
student.math = math
if chinese is not None:
student.chinese = chinese
if english is not None:
student.english = english
return True
return False
def query_student(self, sid=None, name=None):
result = []
for student in self.students:
if sid is not None and student.sid == sid:
result.append(student)
break
if name is not None and student.name == name:
result.append(student)
return result
def print_students(self):
for student in self.students:
print("{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}".format(
student.sid, student.name, student.gender,
student.birth, student.math, student.chinese,
student.english, student.total_score()
))
```
可以在交互式命令行下测试使用:
```python
>>> sm = StudentManagement()
>>> s1 = Student("001", "张三", "男", "2000-01-01", 75, 85, 90)
>>> s2 = Student("002", "李四", "女", "2001-02-02", 80, 90, 85)
>>> sm.add_student(s1)
>>> sm.add_student(s2)
>>> sm.print_students()
001 张三 男 2000-01-01 75 85 90 250
002 李四 女 2001-02-02 80 90 85 255
>>> sm.modify_student("002", name="王五", gender="男", chinese=70, english=75)
True
>>> sm.print_students()
001 张三 男 2000-01-01 75 85 90 250
002 王五 男 2001-02-02 80 70 75 225
>>> sm.remove_student("002")
True
>>> sm.print_students()
001 张三 男 2000-01-01 75 85 90 250
```
阅读全文