zoukankan      html  css  js  c++  java
  • 面向对象之组合(学生管理系统)

    #--*-- coding: utf-8 --*--
    class Teacher:
        """教师"""
        def __init__(self,teach_name,teach_age,teach_date,course):
            self.teach_name = teach_name
            self.teach_age = teach_age
            self.teach_date = teach_date
            self.course = course
    class Course:
        """课程"""
        def __init__(self,course_name,course_price,course_startdate):
            self.course_name = course_name
            self.course_price = course_price
            self.course_startdate = course_startdate
    class Student:
        """学生"""
        def __init__(self,stu_name,stu_age,course,teacher,credit):
            self.stu_name = stu_name
            self.stu_age = stu_age
            self.course = course
            self.credit = credit
            self.teacher = teacher
        def study(self,obj):
            print("%s study good in  %s"%(
                self.stu_name, self.course.course_name
            ))
        def game(self):
            print("%s study unot very good in %s"%(
                self.stu_name,self.course.course_name
            ))
    class Date:
        """日期"""
        def __init__(self,start_time,end_time,course):
            self.start_time = start_time
            self.end_time = end_time
            self.course = course
    class Credit:
        """分数"""
        def __init__(self,score,course):
            self.score = score
            self.course = course
    course_obj = Course('python', 15800, '2017-02-19')
    teacher_obj = Teacher('alex','22','2017-01',course_obj)
    credits_obj = Credit('90',course_obj)
    stu1 = Student('piter',20,course_obj,teacher_obj,credits_obj ) #引入对象,方便后期可以直接调用它内部属性或者方法
    stu2 = Student('tido',12,course_obj,teacher_obj,credits_obj )
    go_info = []
    go_info.append([{"stu_name":stu1.stu_name,
                    "teach_name":stu1.teacher.teach_name,
                    "course_name":stu1.course.course_name,
                    "score":stu1.credit.score,
                    "course_price":stu1.course.course_price
                    },{"stu_name":stu2.stu_name,
                       "teach_name":stu2.teacher.teach_name,
                       "course_name":stu2.course.course_name,
                       "score":20, #stu2.credit.score
                       "course_price":stu2.course.course_price
                    }])
    print("学生 		""老师		""课程		""成绩	""课程价格")
    for i in go_info[0]:
        stuinfo = """{stu_name}		{teach_name}		{course_name}		{score}		{course_price}
    """.format_map(i).strip('
    ')
        print(stuinfo)
    stu1.study(course_obj)
    stu2.game()
    # print(id(stu1.course.course_name)) #6670576
    # print(id(course_obj.course_name))
    运行结果:
    学生 		老师		课程		成绩	课程价格
    piter		alex		python		90		15800
    tido		alex		python		20		15800
    
  • 相关阅读:
    android中设置快捷键方法setShortcut参数的说明
    LayoutInflater
    Java读取文本文件中文乱码问题 .转载
    eclipse+ADT 进行android应用签名详解
    实验课表
    程序员技术练级攻略
    超过4000长度的字符串如何添加到oracle数据库中
    Hive sql创建表以及插入分区表
    Hive Sql 时间格式化处理
    oracle如何查询分区表所占空间大小
  • 原文地址:https://www.cnblogs.com/hongyongshang/p/6734539.html
Copyright © 2011-2022 走看看