实现学生选修课程成绩管理系统,要求如下: 编写类记录学生基本信息、学生选修的课程及学分;一个类为数据类,一个类为业务逻辑类,一个类为用户交互类 使用菜单提供以下功能,每个功能通过函数实现: • 添加新的学生; • 记录学生的选修课程及分数; • 使用文件存储学生的信息,并能够读取和显示; • 查询学生课程选修记录,显示平均成绩。
时间: 2024-04-12 14:30:42 浏览: 78
学生成绩管理系统 系统功能基本要求 学生信息,学号、姓名、性别、专业、年级等
好的,我将为您编写一个满足您要求的学生选修课程成绩管理系统。首先,我们需要创建三个类:`Student`、`Course`和`ManagementSystem`。
```python
class Student:
def __init__(self, name, student_id):
self.name = name
self.student_id = student_id
self.courses = []
def add_course(self, course, score):
self.courses.append((course, score))
def calculate_average_score(self):
if not self.courses:
return 0
total_score = sum(score for _, score in self.courses)
return total_score / len(self.courses)
class Course:
def __init__(self, name, credits):
self.name = name
self.credits = credits
class ManagementSystem:
def __init__(self):
self.students = []
def add_student(self, student):
self.students.append(student)
def save_to_file(self, filename):
with open(filename, 'w') as file:
for student in self.students:
file.write(f"{student.name},{student.student_id}\n")
for course, score in student.courses:
file.write(f"{course.name},{score}\n")
def load_from_file(self, filename):
self.students = []
with open(filename, 'r') as file:
lines = file.readlines()
for i in range(0, len(lines), 2):
name, student_id = lines[i].strip().split(',')
student = Student(name, student_id)
courses = lines[i + 1].strip().split(',')
for j in range(0, len(courses), 2):
course_name, score = courses[j], float(courses[j + 1])
course = Course(course_name, score)
student.add_course(course, score)
self.students.append(student)
def display_student_info(self, student_id):
for student in self.students:
if student.student_id == student_id:
print(f"Student Name: {student.name}")
print(f"Student ID: {student.student_id}")
***
阅读全文