_______________________________________________________________________ CSC121 PYTHON Programming _______________________________________________________________________ Programming Project 2...

_______________________________________________________________________





CSC121 PYTHON Programming


_______________________________________________________________________











Programming Project 2


Objectives



In this project, students will learn:


- How to apply object oriented design


- How to create modules and functions


- How to create and use objects


- How to store data in lists


- How to create and use selection control structures


- How to create and use iterative control structures


- How to add comments to Python code


Goals



In this project, students will demonstrate the abilities to:


- Apply object-oriented design


- Create modules and functions


- Create and use objects


- Store data in lists


- Create and use selection control structures


- Create and use iterative control structures


- Add comments to Python code


Project Descrpiton



In project 1 we wrote a program for class registration system. This time we are going to rewrite that program with object oriented design.




This program creates a class registration system. It allows users to log in as students or administrators. A student user can add courses, drop courses and list courses he/she has registered for. An administrator user can show class rosters and change maximum class sizes.




There will be four classes in the object oriented design. The first one is the Course class.


















Course



- course_code: String


- max_size: Integer


- roster: List



+ Course(c_code: String, m_size: Integer)


+ add_student(id: String)


+ drop_student(id: String)


+ display_roster()


+ change_max_size()


+ get_course_code(): String


+ student_in_course(id): Bool





The Course class has three private instance variables. The constructor takes two arguments: c_code is course code; m_size is maximum class size. Use c_code and m_size to initialize the instance variables course_code and max_size. Initialize roster to an empty list.




The add_student method adds a student to the roster. It has one parameter: id, which is the ID of the student to be added. If the course is already full, display error message and stop. If the student is already enrolled, display error message and stop. Otherwise, add student to roster and display a message showing which student added to which course. It has no return value.




The drop_student method removes a student from roster. It has one parameter: id, which is the ID of the student to be dropped. If the student is not enrolled, display error message and stop. Otherwise, remove student from roster and display a message showing which student dropped from which course. It has no return value.




The display_roster method sorts and displays ID of the students enrolled in this course and the enrollment count. It has no parameter and no return value.




The change_max_size method changes the maximum class size. It has no parameter. It displays current enrollment count and current maximum class size. It asks user to enter new max size. If new max size is smaller than current enrollment count, display error message and ask for a new max size repeatedly until it is not smaller than current enrollment count. It has no return value.




The get_course_code method has no parameter and returns the value of the instance variable course_code.




The student_in_course method tests whether a student is enrolled in this course. It has one parameter: id, which is the ID of the student to be tested. If student is enrolled in this course, return true. Otherwise, return false.




The second class is User, which is the base class of Student and Admin.




















User



#id: String


#pin: String



+ User(id: String, pin: String)


+ get_id(): String


+ get_pin(): String



















Student






+ Student(id: String, pin: String)


+ add_course(c_list: List)


+ drop_course(c_list: List)


+ list_courses(c_list: List)

















Admin






+ Admin(id: String, pin: String)


+ show_roster(c_list: List)


+ change_max_size(c_list: List)







The User class has two protected instance variables: id and pin. The constructor takes two arguments: id and pin. Use these arguments to initialize corresponding instance variables.




The get_id method has no parameter and returns the value of the instance variable id.




The get_pin method has no parameter and returns the value of the instance variable pin.




The Student class has no instance variables other than the ones inherited from User. The constructor takes two arguments: id and pin. It calls the constructor of the base class.




The add_course method adds a student to a course. It has one parameter: c_list, which is the list of Course objects. It asks user to enter the course he/she wants to add. If the course is not offered, display error message and stop. Otherwise, call the add_student method of the course to add the student. This method has no return value.




The drop_course method drops a student from a course. It has one parameter: c_list, which is the list of Course objects. It asks user to enter the course he/she wants to drop. If the course is not offered, display error message and stop. Otherwise, call the drop_student method of the course to drop the student. This method has no return value.




The list_courses method displays and counts courses a student has registered for. It has one parameter: c_list, which is the list of Course objects. It iterates over c_list to display and count courses the student is in the roster. This method has no return value.




The Admin class has no instance variables other than the ones inherited from User. The constructor takes two arguments: id and pin. It calls the constructor of the base class.




The show_roster method displays the roster of a course. It has one parameter: c_list, which is the list of Course objects. It asks user to enter the course he/she wants to see the roster. If the course is not offered, display error message and stop. Otherwise, call the display_roster method of the course to display the roster. This method has no return value.




The change_max_size method changes the maximum size of a course. It has one parameter: c_list, which is the list of Course objects. It asks user to enter the course he/she wants to change max size. If the course is not offered, display error message and stop. Otherwise, call the change_max_size method of the course to maximum size. This method has no return value.




You must define the following functions in the main module.




























Function



Specification



login(u_list)



This function allows a student or an administrator to log in. It has one parameter: u_list, which is a list of User objects (Student objects and Admin objects are User objects). This function asks user to enter ID and PIN. If they match the data of an element in u_list, display message of verification and return the index of that element (e.g. return 0 if it is the first element of the list, 1 if it is the second element, and so on). Otherwise, display error message and return -1.



student_session(c_list, s_list)



This function creates a student session. It has two parameters: c_list is the list of Course objects; s_list is the list of Student objects. It calls the login function for the student user to log in. If login is successful, use a loop to allow the user to add, drop and list courses until the user wants to exit. Call methods of the Student object to handle the tasks. This function has no return value.



admin_session(r_list, m_list, a_list)



This function creates an administrator session. It has two parameters: c_list is the list of Course objects; a_list is the list of Admin objects. It calls the login function for the administrator user to log in. If login is successful, use a loop to allow the user to show class roster and change max class size. Call methods of the Admin object to handle the tasks. This function has no return value.



main()



This function manages the whole registration system. It has no parameter. It creates student list, administrator list and course list. It uses a loop to allow users to create student and administrator sessions until the user wants to stop. Call either the student_session function or the admin_session function, depending on what the user chooses. This function has no return value.





The main function is partially written for you. You must include the following code in your program without modifications.




def main():





course_list = []



student_list =[]



admin_list = []





init_lists(course_list, student_list, admin_list)






The main function creates three lists and calls an init_lists function. This function adds a few elements to these lists. This function makes testing and grading of the program easier. The code of this function has been written. You just need to copy and paste it in your main module.





def
init_lists(c_list, s_list, a_list):



# ------------------------------------------------------------

# This function adds elements to course_list, student_list and

# admin_list. It makes testing and grading easier. It has

# three paramters: c_list is the list of Course objects;

# s_list is the list of Student objects; a_list is the list of

# Admin objects. This function has no return value.

# -------------------------------------------------------------



course1 = Course("CSC121", 2)

course1.add_student("1004")

course1.add_student("1003")

c_list.append(course1)

course2 = Course("CSC122", 2)

course2.add_student("1001")

c_list.append(course2)

course3 = Course("CSC221", 1)

course3.add_student("1002")

c_list.append(course3)



student1 = Student("1001",
"111")

s_list.append(student1)

student2 = Student("1002",
"222")

s_list.append(student2)

student3 = Student("1003",
"333")

s_list.append(student3)

student4 = Student("1004",
"444")

s_list.append(student4)



admin1 = Admin("7001",
"777")

a_list.append(admin1)

admin2 = Admin("8001",
"888")

a_list.append(admin2)






The following is an example.




Student 1004 added to CSC121


Student 1003 added to CSC121


Student 1001 added to CSC122


Student 1002 added to CSC221


Enter 1 if you are student, 2 if you are administrator, 0 to quit: 1


Enter ID: 1001


Enter PIN: 1


ID or PIN incorrect




Enter 1 if you are student, 2 if you are administrator, 0 to quit: 1


Enter ID: 1001


Enter PIN: 111


ID and PIN verified




Enter 1 to add course, 2 to drop course, 3 to see courses you have registered, 0 to exit: 1


Enter course you want to add: csc


Course not found




Enter 1 to add course, 2 to drop course, 3 to see courses you have registered, 0 to exit: 1


Enter course you want to add: CSC121


Course already full




Enter 1 to add course, 2 to drop course, 3 to see courses you have registered, 0 to exit: 1


Enter course you want to add: CSC122


You are already enrolled in this course




Enter 1 to add course, 2 to drop course, 3 to see courses you have registered, 0 to exit: 3


Course registered:


CSC122


Number of courses registered: 1




Enter 1 to add course, 2 to drop course, 3 to see courses you have registered, 0 to exit: 2


Enter course you want to drop: CSC


Course not found




Enter 1 to add course, 2 to drop course, 3 to see courses you have registered, 0 to exit: 2


Enter course you want to drop: CSC121


You are not enrolled in this course




Enter 1 to add course, 2 to drop course, 3 to see courses you have registered, 0 to exit: 2


Enter course you want to drop: CSC122


Student 1001 removed from CSC122




Enter 1 to add course, 2 to drop course, 3 to see courses you have registered, 0 to exit: 3


Course registered:


Number of courses registered: 0




Enter 1 to add course, 2 to drop course, 3 to see courses you have registered, 0 to exit: 0


Student session ended.




Enter 1 if you are student, 2 if you are administrator, 0 to quit: 2


Enter ID: 7001


Enter PIN: 777


ID and PIN verified




Enter 1 to show class roster, 2 to change max class size, 0 to exit: 2


Enter course: CSC221


Current enrollment: 1


Current max size: 1


Enter new size: 0


New max size cannot be smaller than current enrollment


Enter new size: 2




Enter 1 to show class roster, 2 to change max class size, 0 to exit: 1


Enter course: CSC121


1003


1004


Number of student: 2




Enter 1 to show class roster, 2 to change max class size, 0 to exit: 0


Administrator session ended.




Enter 1 if you are student, 2 if you are administrator, 0 to quit: 1


Enter ID: 1001


Enter PIN: 111


ID and PIN verified




Enter 1 to add course, 2 to drop course, 3 to see courses you have registered, 0 to exit: 1


Enter course you want to add: CSC221


Student 1001 added to CSC221




Enter 1 to add course, 2 to drop course, 3 to see courses you have registered, 0 to exit: 3


Course registered:


CSC221


Number of courses registered: 1




Enter 1 to add course, 2 to drop course, 3 to see courses you have registered, 0 to exit: 0


Student session ended.




Enter 1 if you are student, 2 if you are administrator, 0 to quit: 0


Submission Requirments



You must create five Python files: one for the Course class, one for the User class, one for the Student class, one for the Admin class, and one for the main module. Add appropriate comments to your code. At the minimum, you must have program-level comment and function-level comments. Submit the five Python files to Blackboard for credit.


Grading Rubric



main function [5 points]


login function [5 points]


student_session function 5 points]


admin_session function [5 points]


constructor of User class [3 points]


get_id method of User class [3 points]


get_pin method of User class [3 points]


constructor of Student class [3 points]


add_course method of Student class [5 points]


drop_course method of Student class [5 points]


list_courses method of Student class [5 points]


constructor of Admin class [3 points]


show_roster method of Admin class [5 points]


change_max_size method of Admin class [5 points]


constructor of Course class [3 points]


add_student method of Course class [5 points]


drop_student method of Course class [5points]


display_roster method of Course class [5 points]


change_max_size method of Course class [5 points]


get_course_code method of Course class [3 points]


student_in_course method of Course class [3 points]


Program-level and function-level comments [6 points]


Putting class, method and function definitions in correct modules [5 points]





May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here