用自然语言描述 python设计思路 -定义类Student; -定义Student类的数据成员:学号、姓名、性别、专业、班级; -定义Student类的构造方法,实现对上述成员的赋值; -在Student类中定义所有数据成员的get和set方法。 -定义Student类的对象,测试上述函数功能。
时间: 2024-03-19 17:46:24 浏览: 66
Python设计思路:
1. 定义类Student。
```python
class Student:
pass
```
2. 定义Student类的数据成员:学号、姓名、性别、专业、班级。
```python
class Student:
def __init__(self, id, name, gender, major, cls):
self.id = id
self.name = name
self.gender = gender
self.major = major
self.cls = cls
```
3. 定义Student类的构造方法,实现对上述成员的赋值。
```python
class Student:
def __init__(self, id, name, gender, major, cls):
self.id = id
self.name = name
self.gender = gender
self.major = major
self.cls = cls
```
4. 在Student类中定义所有数据成员的get和set方法。
```python
class Student:
def __init__(self, id, name, gender, major, cls):
self.id = id
self.name = name
self.gender = gender
self.major = major
self.cls = cls
def getId(self):
return self.id
def setId(self, id):
self.id = id
def getName(self):
return self.name
def setName(self, name):
self.name = name
def getGender(self):
return self.gender
def setGender(self, gender):
self.gender = gender
def getMajor(self):
return self.major
def setMajor(self, major):
self.major = major
def getCls(self):
return self.cls
def setCls(self, cls):
self.cls = cls
```
5. 定义Student类的对象,测试上述函数功能。
```python
student = Student(1001, 'Tom', 'Male', 'Computer Science', 'Class 1')
print(student.getId())
print(student.getName())
print(student.getGender())
print(student.getMajor())
print(student.getCls())
student.setName('Jerry')
print(student.getName())
```
阅读全文