设学生信息包括:学号、姓名、期末成绩、平时成绩,对学生的学习成绩信息进行管理。 设计要求: 实现学生信息的录入、修改、插入、删除、查询、计算总评成绩、根据总评程序排序和划分等级、按学号查询学生成绩等。 (1)从文件输入学生的成绩信息,包含学号、姓名、期末成绩和平时成绩; (2)显示全部学生成绩信息; (3)更新某个学生的基本信息或课程成绩; (4)对成绩统计分析(总分、平均分、最高分、最低分、及格率等);(5)学号查找并显示某个学生的成绩;(6)按姓名查找并显示某个学生的成绩;(7)按总评成绩由高到低排序显示;(8)统计各分数段人数并显示; (9)设计一个菜单,具有上述规定的操作要求、退出系统等最基本的功能(全部功能在一个程序中实现)
时间: 2023-12-19 17:03:55 浏览: 53
这是一个比较复杂的问题,需要编写一个程序来实现。以下是一个简单的 Python 程序示例,可供参考:
```python
class Student:
def __init__(self, number, name, final_score, daily_score):
self.number = number
self.name = name
self.final_score = final_score
self.daily_score = daily_score
self.total_score = final_score + daily_score
def __str__(self):
return f'{self.number} {self.name} {self.final_score} {self.daily_score} {self.total_score}'
class StudentManager:
def __init__(self):
self.students = []
def load_from_file(self, filename):
with open(filename, 'r') as f:
for line in f:
number, name, final_score, daily_score = line.split()
student = Student(number, name, float(final_score), float(daily_score))
self.students.append(student)
def display_all(self):
for student in self.students:
print(student)
def find_by_number(self, number):
for student in self.students:
if student.number == number:
return student
return None
def find_by_name(self, name):
for student in self.students:
if student.name == name:
return student
return None
def sort_by_total_score(self):
self.students.sort(key=lambda student: student.total_score, reverse=True)
def count_by_score_range(self, start, end):
count = 0
for student in self.students:
if start <= student.total_score <= end:
count += 1
return count
def menu(self):
while True:
print('1. Load from file')
print('2. Display all')
print('3. Update student')
print('4. Statistics')
print('5. Find by number')
print('6. Find by name')
print('7. Sort by total score')
print('8. Count by score range')
print('9. Exit')
choice = input('Please enter your choice: ')
if choice == '1':
filename = input('Please enter filename: ')
self.load_from_file(filename)
elif choice == '2':
self.display_all()
elif choice == '3':
number = input('Please enter student number: ')
student = self.find_by_number(number)
if student is None:
print('Student not found.')
else:
name = input('Please enter new name (enter to keep old): ')
if name:
student.name = name
final_score = input('Please enter new final score (enter to keep old): ')
if final_score:
student.final_score = float(final_score)
daily_score = input('Please enter new daily score (enter to keep old): ')
if daily_score:
student.daily_score = float(daily_score)
student.total_score = student.final_score + student.daily_score
elif choice == '4':
print(f'Total count: {len(self.students)}')
print(f'Total score: {sum(student.total_score for student in self.students)}')
print(f'Average score: {sum(student.total_score for student in self.students) / len(self.students)}')
print(f'Maximum score: {max(student.total_score for student in self.students)}')
print(f'Minimum score: {min(student.total_score for student in self.students)}')
print(f'Pass rate: {sum(student.total_score >= 60 for student in self.students) / len(self.students) * 100:.2f}%')
elif choice == '5':
number = input('Please enter student number: ')
student = self.find_by_number(number)
if student is None:
print('Student not found.')
else:
print(student)
elif choice == '6':
name = input('Please enter student name: ')
student = self.find_by_name(name)
if student is None:
print('Student not found.')
else:
print(student)
elif choice == '7':
self.sort_by_total_score()
self.display_all()
elif choice == '8':
start = input('Please enter score range start: ')
end = input('Please enter score range end: ')
count = self.count_by_score_range(float(start), float(end))
print(f'Student count in range [{start}, {end}]: {count}')
elif choice == '9':
break
else:
print('Invalid choice.')
if __name__ == '__main__':
manager = StudentManager()
manager.menu()
```
注意,这只是一个示例,实际应用中可能需要更复杂的实现。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://img-home.csdnimg.cn/images/20210720083646.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)