作业:
选课系统项目中涉及到诸多数据与功能,要求引入面向对象的思想对其进行高度整合
1、学校数据与功能整合
class School:
school_count = 0
def __init__(self, campus, address):
School.school_count += 1
self.class_count = 0
self.campus = campus
self.address = address
def creat_class(self, clas):
self.class_count += 1
self.clas = clas
def tell_class(self):
print(f'班级:{self.clas} 班级所在校区:{School.school} 校区地址:{School.school_address}')
2、班级数据与功能进行整合
class Clas:
clas_school = '老男孩上海校区'
clas_count = 0
def __init__(self, clas):
Clas.clas_count += 1
self.course_count=0
self.clas = clas
def creat_course(self,course):
self.course=course
self.course_count+=1
def tell_course(self):
print(f'课程:{self.course} 课程所属班级:{self.clas} 班级所在校区:{Clas.clas_school}')
3、课程数据与功能进行整合:
class Course:
course_count = 0
def __init__(self,course_name,course_period,course_price):
Course.course_count+=1
self.course_name=course_name
self.course_period=course_period
self.course_price=course_price
def tell_course_info(self):
print(f'课程:{self.course_name} 课程周期:{self.course_period}月 课程价格:{self.course_price}元')
4、学生数据与功能进行整合
class Student:
stu_school = '老男孩上海校区'
students_count = 0
def __init__(self, name, age, number, gander):
Student.students_count += 1
self.choice_class = 0
self.name = name
self.age = age
self.number = number
self.gander = gander
def choice_course(self, choice_class):
self.choice_class = choice_class
self.choice_class += 1
print(f'学生所在校区:{Student.stu_school}
'
f'学生信息:[姓名:{self.name} 年龄:{self.age} 学号:{self.number} 性别:{self.gander}]
'
f'选课结果:[选课成功! 学生:{self.name} 选择课程:{self.choice_class}]')
5、讲师数据与功能进行整合
class Teacher:
teacher_count = 0
def __init__(self, teacher_name, teacher_salary, teacher_grade):
Teacher.teacher_count += 1
self.teacher_name = teacher_name
self.teacher_salary = teacher_salary
self.teacher_grade = teacher_grade
self.mark_count = 0
def teacher_mark(self, student, score):
self.mark_count += 1
self.student = student
self.score = score
print(f'老师姓名:{self.teacher_name} 教师等级:{self.teacher_grade}教师 已批阅{self.mark_count}
'
f'学生姓名:{self.student}
'
f'得分:{self.score}')