• 4.7---选课系统(面向对象,整合数据与功能)


    选课系统

    选课系统项目中涉及到诸多数据与功能,要求引入面向对象的思想对其进行高度整合
      1、学校数据与功能整合
      2、课程数据与功能进行整合
      3、学生数据与功能进行整合
      4、讲师数据与功能进行整合
      5、班级数据与功能进行整合
    数据部分:
    校区的名字:如"老男孩上海校区"
    校区的地址:如"上海虹桥"

    班级名字
    班级所在校区

    学生的学校
    学生的姓名
    学生的年龄
    学号
    学生的性别

    课程名字
    课程周期
    课程价格

    老师的名字
    老师的年龄
    老师的薪资
    老师的等级

    功能部分:
    校区创建完毕后,可以为每个校区创建班级
    班级创建完毕后,可以为每个班级创建课程
    学生创建完毕后,学生可以选择班级
    老师创建完毕后,可以为学生打分

    1、定义类与实例化

    class School():
        def __init__(self,school_name,address):
            self.school_name = school_name
            self.school_address = address
            self.class_dict = {}
            self.stu_dict = {}
    
        def create_class(self,class_name):
            c1 = Class(class_name,self.school_name)
            self.class_dict[c1.class_name] = c1.curriculum_dict
            return c1
    
        def recruit_student(self,stu_name,stu_age,stu_num,stu_gender):
            stu = Student(self.school_name,stu_name,stu_age,stu_num,stu_gender)
            self.stu_dict[stu_name] = [stu.stu_age,stu.stu_num,stu.stu_gender,stu.stu_class]
            return stu
    
    class Class():
        def __init__(self, class_name, campus):
            self.campus = campus
            self.class_name = class_name
            self.curriculum_dict = {}
            self.stu_list = {}
    
        def create_curriculum(self,curriculum_name,curriculum_peroid,curriculum_price):
            cur = Curriculum(curriculum_name,curriculum_peroid,curriculum_price)
            self.curriculum_dict[curriculum_name] = [curriculum_peroid,curriculum_price]
            return cur
    
    #      学生的学校
    #      学生的姓名
    #      学生的年龄
    #      学号
    #      学生的性别
    #      学生创建完毕后,学生可以选择班级
    class Student():
        def __init__(self,school,name,age,num,gender):
            self.stu_school = school
            self.stu_name = name
            self.stu_age = age
            self.stu_num = num
            self.stu_gender = gender
            self.stu_class = {}
            self.stu_grade = None
    
        def chose_class(self,c):
            self.stu_class["班级"]= c.class_name
            self.stu_class["课程"]= c.curriculum_dict
            c.stu_list[self.stu_name] = [self.stu_age,self.stu_num,self.stu_gender]
    
    #      老师的名字
    #      老师的年龄
    #      老师的薪资
    #      老师的等级
    #      老师创建完毕后,可以为学生打分
    class Teacher():
        def __init__(self,tea_name,tea_age,tea_salary,tea_class):
            self.tea_name = tea_name
            self.tea_age = tea_age
            self.tea_salary = tea_salary
            self.tea_class = tea_class
            self.stu_list = {}
    
        def grade(self,stu,grade):
            stu.stu_grade = grade
            self.stu_list[stu.stu_name] = grade
    
    
    
    class Curriculum():
        def __init__(self,name,period,price):
            self.curriculum_name = name
            self.curriculum_period = period
            self.curriculum_price = price
            with open("db.txt",mode='wt',encoding="utf-8") as f:
                f.write(name)
    
    s1 = School("西南大学","天生街道")
    c1 = s1.create_class("Class 1")
    
    curriculum_Python = c1.create_curriculum("Python","6 months","20000")
    curriculum_Math = c1.create_curriculum("Math","12 months","100000")
    
    stu1 = s1.recruit_student("Jil",20,666666,"male")
    stu1.chose_class(c1)
    stu2 = s1.recruit_student("Fishball",18,188741,"female")
    stu2.chose_class(c1)
    
    t1 = Teacher("egon",18,50000,"A")
    
    t1.grade(stu1,99)
    t1.grade(stu2,59)
    
    print("学校属性:
    ",s1.__dict__,end="
    
    ")
    print("班级属性:
    ",c1.__dict__,end="
    
    ")
    print("学生1属性:
    ",stu1.__dict__,end="
    
    ")
    print("学生2属性:
    ",stu2.__dict__,end="
    
    ")
    print("老师属性:
    ",t1.__dict__,end="
    
    ")
     

    2、运行结果

    学校属性:
     {'school_name': '西南大学', 'school_address': '天生街道', 'class_dict': {'Class 1': {'Python': ['6 months', '20000'], 'Math': ['12 months', '100000']}}, 'stu_dict': {'Jil': [20, 666666, 'male', {'班级': 'Class 1', '课程': {'Python': ['6 months', '20000'], 'Math': ['12 months', '100000']}}], 'Fishball': [18, 188741, 'female', {'班级': 'Class 1', '课程': {'Python': ['6 months', '20000'], 'Math': ['12 months', '100000']}}]}}
    
    班级属性:
     {'campus': '西南大学', 'class_name': 'Class 1', 'curriculum_dict': {'Python': ['6 months', '20000'], 'Math': ['12 months', '100000']}, 'stu_list': {'Jil': [20, 666666, 'male'], 'Fishball': [18, 188741, 'female']}}
    
    学生1属性:
     {'stu_school': '西南大学', 'stu_name': 'Jil', 'stu_age': 20, 'stu_num': 666666, 'stu_gender': 'male', 'stu_class': {'班级': 'Class 1', '课程': {'Python': ['6 months', '20000'], 'Math': ['12 months', '100000']}}, 'stu_grade': 99}
    
    学生2属性:
     {'stu_school': '西南大学', 'stu_name': 'Fishball', 'stu_age': 18, 'stu_num': 188741, 'stu_gender': 'female', 'stu_class': {'班级': 'Class 1', '课程': {'Python': ['6 months', '20000'], 'Math': ['12 months', '100000']}}, 'stu_grade': 59}
    
    老师属性:
     {'tea_name': 'egon', 'tea_age': 18, 'tea_salary': 50000, 'tea_class': 'A', 'stu_list': {'Jil': 99, 'Fishball': 59}}
  • 相关阅读:
    随感
    createDocumentFragment() 创建文档碎片节点
    关于数组的map、reduce、filter
    CSS中的常用属性
    精通CSS version2笔记2.小知识
    精通CSS version2笔记之⒈选择器
    Spring入门_01
    Spring入门
    Java 流程控制
    Java 数据类型
  • 原文地址:https://www.cnblogs.com/zhubincheng/p/12656625.html
Copyright © 2020-2023  润新知