创建SchoolMem类,该类中包含三个数据成员:姓名、性别、年龄;创建Student类,继承自SchoolMem类,添加额外三个数据成员:班级、学号和数量统计;创建Teacher类,继承自SchoolMem类,添加额外三个数据成员:学院、工号和数量统计。要求给每个类适当添加属性、成员方法和特殊方法(如构造方法),实现学生和教师信息的输入输出。实现并测试这个类。(建议在父类和子类中使用同名函数以实现多态。)
class SchoolMen:
class Teacher(SchoolMen): #此处teacher是schoolmen的子类
class Student(SchoolMen):
class InputArray(): #储存数据并做数据处理
class SchoolMen:
def __init__(self):
self.name=''
self.sex=''
self.age=''#其他类同理 不再列举
def Get(self):
self.name=input('请输入姓名')
self.sex=input('请输入性别')
self.age=input('请输入年龄') #其他类同理 不再列举
def Output(self):
return self.name,self.sex,self.age
def CountAll(self):
self.totalNum+=1
class InputArray():
def __init__(self):
self.dataBaseName=[]
self.dataBaseSex=[]
self.dataBaseAge=[]
self.dataBaseClass=[]
self.dataBaseSNO=[]
self.dataBaseWorkPlace=[]
self.dataBaseWorkNum=[]
self.countAll=0
self.countStu=0
self.countWorker=0
def InputDataAll(self):
user=SchoolMen()
user.Get()
save=user.Output()
name=save[0] #处理return出来的值(元组)
sex=save[1]
age=save[2]
self.dataBaseName.append(name) #将数据插入到列表中
self.dataBaseSex.append(sex)
self.dataBaseAge.append(age)
self.countAll+=1
def InputDataStu(self):
user=Student()
user.Get()
save=user.Output()
class1=save[0] #处理return出来的值(元组)
sno=save[1]
self.dataBaseClass.append(class1) #将数据插入到列表中
self.dataBaseSNO.append(sno)
self.countStu+=1
def InputDataWorker(self):
user=Teacher()
user.Get()
save=user.Output()
place=save[0]
num=save[1]
self.dataBaseWorkPlace.append(place)
self.dataBaseWorkNum.append(num)
self.countWorker+=1
def GetStu(self):
return self.dataBaseName,self.dataBaseSex,self.dataBaseAge,self.dataBaseClass,self.dataBaseSNO,self.countAll,self.countStu
def GetWocker(self):
return self.dataBaseName,self.dataBaseSex,self.dataBaseAge,self.dataBaseWorkPlace,self.dataBaseWorkNum,self.countAll,self.countStu,self.countWorker
def main2():
user=InputArray()
for i in range(0,10000):
userinput=eval(input('1.输入信息,2.输出信息,3.结束'))
if userinput == 1:
user.InputDataAll()
choice=eval(input('您是1.老师,2.学生'))
if choice ==1:
user.InputDataWorker()
if choice ==2:
user.InputDataStu()
elif userinput == 2:
if choice == 1:
print(user.GetStu())
if choice == 2:
print(user.GetWocker())
class SchoolMen:
def __init__(self):
self.name=''
self.sex=''
self.age=''
def Get(self):
self.name=input('请输入姓名')
self.sex=input('请输入性别')
self.age=input('请输入年龄')
def Output(self):
return self.name,self.sex,self.age
def CountAll(self):
self.totalNum+=1
class Teacher(SchoolMen):
def __init__(self):
self.major=''
self.workNum=''
def Get(self):
self.major=input('请输入您所处的学院')
self.workNum=input('请输入您的工号')
def Output(self):
return self.major,self.workNum
class Student(SchoolMen):
def __init__(self):
self.classNum=''
self.numStu=''
def Get(self):
self.classNum=input('请输入班号')
self.numStu=input('请输入学号')
def Output(self):
return self.classNum,self.numStu
class InputArray():
def __init__(self):
self.dataBaseName=[]
self.dataBaseSex=[]
self.dataBaseAge=[]
self.dataBaseClass=[]
self.dataBaseSNO=[]
self.dataBaseWorkPlace=[]
self.dataBaseWorkNum=[]
self.countAll=0
self.countStu=0
self.countWorker=0
def InputDataAll(self):
user=SchoolMen()
user.Get()
save=user.Output()
name=save[0]
sex=save[1]
age=save[2]
self.dataBaseName.append(name)
self.dataBaseSex.append(sex)
self.dataBaseAge.append(age)
self.countAll+=1
def InputDataStu(self):
user=Student()
user.Get()
save=user.Output()
class1=save[0]
sno=save[1]
self.dataBaseClass.append(class1)
self.dataBaseSNO.append(sno)
self.countStu+=1
def InputDataWorker(self):
user=Teacher()
user.Get()
save=user.Output()
place=save[0]
num=save[1]
self.dataBaseWorkPlace.append(place)
self.dataBaseWorkNum.append(num)
self.countWorker+=1
def GetStu(self):
return self.dataBaseName,self.dataBaseSex,self.dataBaseAge,self.dataBaseClass,self.dataBaseSNO,self.countAll,self.countStu
def GetWocker(self):
return self.dataBaseName,self.dataBaseSex,self.dataBaseAge,self.dataBaseWorkPlace,self.dataBaseWorkNum,self.countAll,self.countStu,self.countWorker
def main2():
user=InputArray()
for i in range(0,10000):
userinput=eval(input('1.输入信息,2.输出信息,3.结束'))
if userinput == 1:
user.InputDataAll()
choice=eval(input('您是1.老师,2.学生'))
if choice ==1:
user.InputDataWorker()
if choice ==2:
user.InputDataStu()
elif userinput == 2:
if choice == 1:
print(user.GetStu())
if choice == 2:
print(user.GetWocker())