在一个学校中有教师和学生两类人员。学生信息有身份证号、学号、专业、姓名、 性别、年龄及数学、英语、Java 程序设计三门课程的成绩。教师信息有身份证号、教师号、 专业、姓名、性别、年龄及授课的学时数。创建学生和教师的对象并输出对象的信息
时间: 2024-12-06 22:24:13 浏览: 20
在学校场景中,我们可以创建两个类来分别代表教师和学生。这里假设我们使用Python语言来编写这个简单的类:
```python
class Teacher:
def __init__(self, id_number, teacher_id, specialty, name, gender, age, teaching_hours):
self.id_number = id_number
self.teacher_id = teacher_id
self.specialty = specialty
self.name = name
self.gender = gender
self.age = age
self.teaching_hours = teaching_hours
def display_info(self):
print(f"教师ID: {self.teacher_id}, 姓名: {self.name}, 专业: {self.specialty}, 性别: {self.gender}, 年龄: {self.age}, 授课时数: {self.teaching_hours}")
class Student:
def __init__(self, id_number, student_id, major, name, gender, age, math_score, english_score, java_score):
self.id_number = id_number
self.student_id = student_id
self.major = major
self.name = name
self.gender = gender
self.age = age
self.math_score = math_score
self.english_score = english_score
self.java_score = java_score
def display_info(self):
print(f"学生ID: {self.student_id}, 学号: (未给出), 专业: {self.major}, 姓名: {self.name}, 性别: {self.gender}, 年龄: {self.age}, 数学成绩: {self.math_score}, 英语成绩: {self.english_score}, Java成绩: {self.java_score}")
# 创建教师和学生实例
teacher = Teacher("123456", "T001", "计算机科学", "张老师", "女", 35, 180)
student = Student("789012", "S001", "软件工程", "李明", "男", 18, 90, 85, 78)
# 输出对象信息
teacher.display_info()
student.display_info()
```
当你运行这段代码,会输出教师和学生的基本信息,包括他们的身份号码、姓名、专业等。
阅读全文