Object-oriented Application: Students ' Course selection system

Source: Internet
Author: User
Tags ming

I. Requirements: Course selection system

Administrator:
Create Teacher: Name, gender, age, asset
Create a Course: Course name, class time, lesson fee, associated teacher
Save in file using pickle

Students:
Student: username, password, gender, age, Course selection list [], class Record {Lesson 1: "Di,a,"}
1. List all courses
2. Select Course
3, students in class,
4. Ret = course. Work () Get the return of the course; Asset + = Class fee


second, the code idea

2.1 Administrator System

A, defines the teacher class, Name,age,gender,property, where the property is a private member, with the object call ordinary method can modify and extract Self.__property
B, defines the course class, Course_name,course_time,coure_cost,teacher_obj
C, created 3 teachers, 3 courses
D, finally put three course objects into the list, and then pickle.dump the list directly into the Course_list file (each element of the deposit is the course object)

2.2 Student-side (import pickle and Administrator files)

A, defines the student class, Name,pwd,gender,age,l2,w, wherein: L2 is the choice class list, W is the class number dictionary, key is the course name, value is the class number
Methods of selecting courses, removing course methods and classes

b, through the load Course_list file, get the course object, print all course names (which courses can be selected)
C. Course Selection:
First, the student file content is extracted by load, and the last selected course is printed.
Enter the course you want to choose, and if the course has been selected, prompts you to repeat the lesson, and if you don't repeat, append the list of selected courses.
Select and print one more time until now, all the courses that have been selected

D. Delete Course:
Print a course that can be deleted (courses that have been selected)
Enter the course to be deleted, determine if the course exists, delete it if it exists, or show that it does not exist

E, class:
Extract student file content from load, print last selected course and course already taken
Enter the course you want to take, and if the course is a course that has already been selected, add 1 to the value of the course name key, otherwise create the key value pair
If the course is not already selected, you are prompted that the course does not exist
Return the number of lessons dictionary
Note: The whole class process, only the class dictionary key value changes

F, student user name and password
Save into the dictionary, dump into the file, load it in again, then judge, if it is consistent, allow access to the system

G, teacher class fee calculation :
Create Teacher Lesson fee Dictionary {}
Combine all students ' class times dictionaries into a single dictionary
Revolving course object, when the course name = = Student's course name, then the teacher class fee for the course = Class fee per course * Number of lessons
H, teacher total assets calculation
Create a teacher's total assets dictionary
Revolving course object, when the teacher of the course object already exists in the lesson fee dictionary, then the teacher total Assets = Teacher Total Lesson fee + Initial Asset
When the teacher of the course does not exist in the classroom fee dictionary, that is, the teacher does not have a class, his total assets are the initial assets

Note: teacher private assets are called by the ordinary method of the object to implement calling a private member

Iii. Overview of the document

This program altogether 6 files: administrator.py is Administrator file
student.py is a student-side file
Course_list is a Course object file
Name_pwd is a user name and password file for two students Xiao Ming and Xiao Hong
Xiao Ming is Xiao Ming's course record and number of classes
Little Red is a little red. course record and number of lessons

Iv. Implementation of the Code4.1 Administrator Files
#!/usr/bin/env python#-*-coding:utf-8-*-import pickleclass Teacher:    def __init__ (self,name,age,gender,property ):        self.name=name        self.age=age        self.gender=gender        self.__property=property    def __str__ (self ):        print (self.name)    def property_check (self):        return self.__propertyclass Course:    def __init__ ( Self,course_name,course_time,coure_cost,teacher_obj):        self.course_name=course_name        self.coure_cost= Coure_cost        self.course_time=course_time        self.teacher_obj=teacher_objt1=teacher (' Alex ', ' man ', 300) T2=teacher (' Eric ', ' Woman ', ' Max ') t3=teacher (' Oldboy ', ' A ', ' man ', ') c1=course (' Biology ', 10,300,t1) c2=course (' Mathematics ', 10,500,T2) c3=course (' Art ', 10,800,T3) l1=[c1,c2,c3]pickle.dump (L1,open (' course_list ', ' WB ')
4.2 Student-side
#!/usr/bin/env python#-*-coding:utf-8-*-import pickleimport administratorclass student:def __init__ (self,name,pwd, GENDER,AGE,L2,W): #l2选课列表 W is the class number dictionary, key is the course name, value is the number of lessons Self.name=name self.pwd=pwd self.gend Er=gender self.age=age self.l2=l2 self.w=w def selecting_courses (self): print ('%s ' Selected course list is ' %SELF.NAME,SELF.L2) while True:print (' Student%s elective '%self.name) a=input (' Please enter course name Selection course, each course can only be selected once, enter Q                Exit Course: ' If a== ' Q ': Break if A in Self.l2:print (' The course you entered has duplicates, please re-select: ')        Continue Self.l2.append (a) print ('%s ' Selected course list is '%self.name,self.l2 ') def del_course (self): Print ('%s ' can delete the course list for '%self.name,self.l2 ' while true:a=input (' Please enter the course you want to delete, enter Q to exit: ') if a = = ' Q ': Break if a isn't in Self.l2:print (' The course you entered does not exist, please re-enter: ') contin     UE Else:           Del Self.l2[self.l2.index (a)] def attend_class (self): print ('%s ' has already been on the course list%s, you can have a course listing of%s '% (self.name,se                LF.W,SELF.L2) # c={} while True:a=input (' Please enter the course name to be taught, enter Q to exit Course: ') if a== ' Q ': Break if a isn't in Self.l2:print (' The course you selected does not exist, please re-enter: ') continue Els E:if A in SELF.W: #创建上课次数字典 self.w[a]+=1 else:self. W[a]=1 print ('%s ' has already taken a course list of%s '% (SELF.NAME,SELF.W)) ' Return Self.wa=pickle.load (' Open (' Xiao Ming ', ' RB ') #读取小明上次的选课和上课 , # A[0] is the list of all courses previously selected by Xiaoming, A[1] std1=student (open (' Little Red ', ' RB ') for all courses and sessions previously attended by Xiaoming B=pickle.load ( ' Xiaoming ', 1, ' Man ', 18,a[0],a[1]) std2=student (' Little Red ', 2, ' Weman ', 18,b[0],b[1]) s={' xiaoming ': 1, ' Little Red ': 2}pickle.dump (S,open (' name_ PWD ', ' WB ')) ss=pickle.load (open (' name_pwd ', ' RB ')) R=pickle.load (open (' course_list ', ' RB ')) ret1=std1.wret2=std2.w# D,e=input (' Please enter the user name and password of%s, separated by a space, Xiao Ming's user name is Xiao Ming, the password is 1: '%std1.name). Split (') d,e= ' xiaoming ', ' 1 ' if d== ' xiaoming ' and int (e) ==ss[' xiaoming ']: print (Std1.name, ' currently optional Course: ') for I in R:prin T (i.course_name) print (' =================================================== ') while true:a=int (input (' Please enter the sequence number in Line selection: 1. Course Selection 2. Delete Lesson 3. Class 4. Exit ') if A==1:std1.selecting_courses () elif A==2:std1.del_cou RSE () elif A==3:ret1=std1.attend_class () A=[STD1.L2,STD1.W] Pickle.dump (A,open (' small Elif a==4:break else:print (' Your input is wrong, please re-enter ') d,e=input (' Please enter%s username and password, separated by a space, red        The username is little Red, the password is 2: '%std2.name '. Split (") if d== ' Little Red ' and int (e) ==ss[' Little Red ': print (Std2.name, ' The currently optional course is: ') for I in R: Print (i.course_name) print (' =================================================== ') while True:a=int (' please Enter the sequence number to select: 1. Course Selection 2. Delete Lesson 3. Class 4. Exit ') if A==1:std2.selecting_courses () elif a==2:std2.de L_course () Elif A==3:ret2=std2.attend_class () B=[STD2.L2,STD2.W] Pickle.dump (B,open (' Little Red ', ' WB ') el        If A==4:break else:print (' Your input is wrong, please re-enter ') for I in Ret2: #合并学生1和学生2的字典 if I in Ret1: Ret1[i]+=ret2[i] Else:ret1[i]=ret2[i]print (' The total number of lessons that all students have been in the dictionary is%s '%ret1) c={} #课时费字典for i in R: #上完课程, start calculating the student to all old                        The teacher creates all class fees, I course object for k,v in Ret1.items (): # Ret1 Two students after the merged class dictionary if i.course_name==k:    C[i.teacher_obj]=i.coure_cost*v #老师总课时费 = Class fee * Number of lessons g={} #总资产字典 (to prevent teachers from having classes), plus the teacher's original assets for I in R: #i课程对象, extract teacher objects according to the course        If i.teacher_obj in C:g[i.teacher_obj]=c[i.teacher_obj]+i.teacher_obj.property_check () #老师总资产 = Total Lesson fee + Initial Asset else:                                                        G[i.teacher_obj]=i.teacher_obj.property_check () #如果老师没上课, total assets = initial assets #通过普通方法调用私有成员 # Print Teacher total assets for i,j in G.items (): Print ('%s Teacher's total assets is%s '% (I.NAME,J))

  

Object-oriented Application: Students ' Course selection system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.