1、输入查询学生学号 2、通过二分法查找到学生基本信息及各科目信息 3、输入一个学号时,查询出此生的基本信息及所有课程情况,格式如下: 学号:xx 姓名:xxx 性别:x 宿舍号码:xxx 电话号码xxx 课程编号:xxx 课程名称:xxxxx 综合成绩:xxxx 实得学分:xx 课程编号:xxx 课程名称:xxxxx 综合成绩:xxxx 实得学分: xx … 共修:xx科,实得总学分为: xxx
时间: 2024-02-16 08:02:36 浏览: 39
不问题,我已经理解了你的要求。基于你的要求,我可以为你提供一个简单的学生信息管理系统。以下是该系统的核心代码示例:
```python
# 定义学生信息类
class Student:
def __init__(self, id, name, gender, dorm, phone, courses=[]):
self.id = id
self.name = name
self.gender = gender
self.dorm = dorm
self.phone = phone
self.courses = courses
def add_course(self, course):
self.courses.append(course)
def __str__(self):
s = f"学号:{self.id} 姓名:{self.name} 性别:{self.gender} 宿舍号码:{self.dorm} 电话号码:{self.phone}\n"
s += "课程信息:\n"
for c in self.courses:
s += f"课程编号:{c['id']} 课程名称:{c['name']} 综合成绩:{c['score']} 实得学分:{c['credit']}\n"
s += f"共修:{len(self.courses)}科,实得总学分为:{self.get_total_credit()}"
return s
def get_total_credit(self):
total = 0
for c in self.courses:
total += c['credit']
return total
# 定义学生信息管理类
class StudentManager:
def __init__(self):
self.students = []
def add_student(self, student):
self.students.append(student)
def get_student_by_id(self, id):
left, right = 0, len(self.students) - 1
while left <= right:
mid = (left + right) // 2
if self.students[mid].id == id:
return self.students[mid]
elif self.students[mid].id < id:
left = mid + 1
else:
right = mid - 1
return None
# 测试
manager = StudentManager()
s1 = Student("1001", "张三", "男", "101", "13512345678")
s1.add_course({"id": "001", "name": "语文", "score": 90, "credit": 4})
s1.add_course({"id": "002", "name": "数学", "score": 80, "credit": 3})
manager.add_student(s1)
s2 = Student("1002", "李四", "女", "102", "13587654321")
s2.add_course({"id": "001", "name": "语文", "score": 95, "credit": 4})
s2.add_course({"id": "002", "name": "数学", "score": 85, "credit": 3})
s2.add_course({"id": "003", "name": "英语", "score": 90, "credit": 3})
manager.add_student(s2)
s = manager.get_student_by_id("1001")
if s:
print(s)
else:
print("未找到该学生")
```
这是一个基于 Python 的简单实现,你可以根据自己的需求进行修改和扩展。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)