c++使用继承,按要求写出代码 要求:编写一个学生类,学生数据有编号、姓名、年龄、专业和成绩,要求将编号、姓名、年龄数据设计成一个人类Person,并作为学生类Student的基类。创建Student类对象,并使用显示show()函数对数据进行输出。
时间: 2024-06-11 18:09:25 浏览: 163
C++学生管理系统程序代码
```python
class Person:
def __init__(self, id, name, age):
self.id = id
self.name = name
self.age = age
class Student(Person):
def __init__(self, id, name, age, major, score):
super().__init__(id, name, age)
self.major = major
self.score = score
def show(self):
print("ID:", self.id)
print("Name:", self.name)
print("Age:", self.age)
print("Major:", self.major)
print("Score:", self.score)
student = Student(1001, "Tom", 18, "Computer Science", 90)
student.show()
```
输出结果:
```
ID: 1001
Name: Tom
Age: 18
Major: Computer Science
Score: 90
```
阅读全文