Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

________________________________________________________________________________________________________________________________________________________________________________________________________...

1 answer below »
______________________________________________________________________________________________________________________________________________________________________________________________________________________
    CSC121    Programming Project 2    Page 9
______________________________________________________________________________________________________________________________________________________________________________________________________________________
_______________________________________________________________________
    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: Intege
- 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 e
or message and stop. If the student is already enrolled, display e
or 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 e
or 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 cu
ent enrollment count and cu
ent maximum class size. It asks user to enter new max size. If new max size is smaller than cu
ent enrollment count, display e
or message and ask for a new max size repeatedly until it is not smaller than cu
ent 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.
    Use
    #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 co
esponding 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 e
or 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 e
or 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 e
or 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 e
or 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 e
or 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 inco
ect
Enter 1 if you are student, 2 if you are administrator,
Answered Same Day Dec 06, 2021

Solution

Yogesh answered on Dec 08 2021
138 Votes
Admin.py
import Use
class admin(User.user):
def __init__(self, Id, pin):
super().__init__(Id, pin)
def show_roster(self, c_list):
pass
def change_max_size(self, c_list):
pass
Course.py
class course:
def __init__(self, c_code, m_size):
self.course_code = c_code
self.max_size = m_size
self.roster = []
def add_student(self, Id):
if len(self.roster) == self.max_size:
print("E
or...!")
# STOP
else:
self.roster.append(int(Id))
print("Student added to the Course.")
def drop_student(self, Id):
if Id in self.roster:
self.roster.remove(Id)
print("Student is dropped from the Course")
def display_roster(self):
self.roster.sort()
print(self.roster)
print(len(self.roster))
def change_max_size(self):
print(len(self.roster))
print(self.max_size)
new_size = input("Enter new max Class size: ")
if...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here