Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / A university provides inexpensive education to students

A university provides inexpensive education to students

Computer Science

A university provides inexpensive education to students. The tuition rates are very low and this attracts more students than can be accommodated in the available classes. This causes a problem as the university cannot hire enough faculty members to offer enough courses for all students. Popular classes run out of space very soon after the course registration system is open. The following priority rules have therefore been put in place to decide which students have priority in registering for specific classes.

·        Students who are majors in the department offering a class have priority to register this class over students from other departments.

·        After that, a student who is closer to graduation has priority to register for the class. For example, seniors have priority over juniors, sophomores have priority over freshmen, etc.

·        If two students from the same department are also in the same year (or level), the priority is given to the student with the higher GPA.  

·        If the priority cannot be decided by applying the above rules, the "first come, first served" rule will be applied to decide who has priority to register for the class.

 

Develop a Python application to implement this Course Registration System. Each class in your application should be in its own separate file using the specified class names.

 

The courses offered are contained in a text file in the format shown below. The input file is a comma-separated file (but not with .csv extension). Data stored in the file is in the order: course department code, course number, capacity (maximum number of students that can be accommodated in the class). Use this file to make a list of Course objects (more details specified in the Design Requirements section).

 

Example: Input file for available courses (named course.txt)

CS,1040,10

CS,1060,2

You will also be keeping a priority queue of registration requests - this means that the items (Requests) in the queue will be stored in order according to the priority rules specified above (not strictly in the "first in, first out" manner of a typical queue. You will first read in a series of registration requests from a second text file (request.txt), and then insert each one into the queue according to the priority rules. The item with the highest priority should be at the front of the queue.

 

Data stored in the request.txt file is in the order: student name, student level (i.e., sophomore, junior, etc.), student major, course dept, course number, list of grades in four courses with each grade followed by the corresponding number of credits (to enable calculation of the student's GPA). Each grade is on a 4.0 scale. Format for the grades and credits is: grade1, credits1, grade2, credits2, grade3, credits3, grade4, credits4.

 

Example: Input File containing information about students waiting /requesting to be registered for courses (input file is named request.txt)

Jeremy Anderson,Senior,ECE,CS,1040,3.2,3,3.1,2,4.0,3,3.6,2

Jeremy Anderson,Senior,ECE,CS,1060,3.2,3,3.1,2,4.0,3,3.6,2

Peter Bond,Junior,CS,CS,1060,3.0,3,3.0,2,3.9,3,3.5,2

Peter Bond,Junior,CS,CS,1040,3.0,3,3.0,2,3.9,3,3.5,2

Jonah Fish, Senior,CS,CS,1060,3.1,2,3.4,2,4.0,3,3.7,2

Jonah Fish, Senior,CS,CS,1040,3.1,2,3.4,2,4.0,3,3.7,2

Jonathan Fin,Freshman,CS,CS,1040,3.9,2,3.8,3,4.0,3,3.8,3

Jonathan Fin,Freshman,CS,CS,1060,3.9,2,3.8,3,4.0,3,3.8,3

 

After inserting all requests from the input file into the priority queue, you then need to process each request in the ordered queue (starting from the front of the queue and proceeding in order).

For each request in the priority queue:

·        print out the request;

·        either add the student to the course's class list if there is room, or print a message indicating that the student cannot be registered for the course.

 

You also need to print the queue contents before and after the processing of all requests (the queue should be empty after all requests have been processed).

 

Finally, print out the class list showing students enrolled for each course (after all requests have been processed).

 

Design Requirements

 

A Priority Queue is similar to a typical queue where we insert an element at the rear and remove an element from the front; but there is one difference: the order of storing elements in the priority queue depends on the priority of the elements. The element with highest priority will be moved to the front of the queue and one with lowest priority will move to the back of the queue. Thus, it is possible that the last item enqueued could be inserted at the front of the queue because of its higher priority.

 

In your implementation of a priority queue, you should have methods to enqueue an object, dequeue an object, determine if the queue is empty, and print the queue contents. Specifically, your Priority Queue class should implement the following methods:

  # Attribute - list representing priority queue

  def __init__(self):

 

  # If queue is empty, return true.

  def is_empty(self):

 

  # If queue is empty, enqueue data (which is an object of Request class).

  # Else, iterate through queue, compare priority level of existing objects

  # with that of 'request', and insert object at the right position (based

  # on priority, not just at the end of the queue).

  def enqueue(self, request):

 

  # Dequeue the request at the 'front' of the queue.

  def dequeue(self):

 

  # Print all items in the queue (each is a Request object)

  def queue_print(self):

 

 

In addition, you should have a class Course representing a Course object, with attributes for the data contained in the courses.txt input file, along with a list of enrolled students for that course. Class Course should have the following methods:

 

class Course:

  # Includes a list for enrolled students. Determine attributes.

  def __init__ ...

 

  # Returns true if a course has reached capacity.

  def is_full(self):

 

  # Add newly enrolled student to the llist.

  def add_student(self, name):

 

  # Print class list for this course.

  def print_class_list(self):

 

  # Print course

  def __str__(self):

 

  # Getters and setters

  def get_capacity(self):

  

  def set_capacity(self, new_cap):

  

  def get_course_dept(self):

  

  def get_course_number(self):

 

 

 

You should also have a Request class representing a registration request, which includes attributes for the data contained in the request.txt input file. This class represents the objects that you will be inserting into the queue. Some requests have a higher priority than other requests. In order to compare two requests and determine the order of priority between the two, the class should use the compare_to() method in this class. Your Request class should implement the following methods:

 

# A FUNCTION-is not called by an object of the class. Not contained within class.

# This determines how many years from graduation a student is (e.g. freshman

# has three more years at the end of the academic year, sophomore has 2, etc.)

def years_from_graduation(level):

 

class Request:

  # Refer to the request input file to determine attributes; you can add

  # additional ones if necessary.

  def __init__ ...

 

  # For printing Request objects.

  def __str__(self):

 

  # Calculate GPA:

  # For each grade, find the product of grade and credit hours, and

  # compute the sum of all the products.

  # (Each grade is on a 4.0 scale.)

  # Find the sum of all credits for that student.

  # Divide sum of products by sum of credits.

  def gpa_cal(self, gpa_list):

 

  # Used in determining priority using the criteria outlined in the document.

  # Returns a value that indicates which has higher priority - the calling

  # object or 'other'.

  def compare_to(self, other):

 

  def get_student_name(self):

  

  def get_student_dept(self):

 

  def get_course_dept(self):

 

  def get_course_number(self):

 

 

 

Finally, you should have a Controller class which runs everything. This class works with the other classes to process course registration for students. It is responsible for the following:

·        adding new requests from the requests input file,

·        adding courses from the course input file,

·        processing all of the requests (registering students where this is possible, and then

·        printing out the class list for all courses as mentioned earlier.

 

  # Controller class initializer. Attributes?

  # Should also have a list for courses.

  def __init__ ...

 

  # Use try - except for FileNotFoundError

  # Read from course.txt file and create Course objects for each course.

  # Store Course objects in list (attribute)

  def read_course_file(self):

 

  # Use try - except for FileNotFoundError

  # Read request.txt file and store the different components on each line

  # in variables, make a Request object and pass the variables as parameters

  # to the Request class initializer.

  # Add the Request object to the Priority Queue.

  def read_request_file(self):

 

  # Enqueue the request received as argument

  def add_request(self, new_request):

 

  # Process each request in the queue as follows:

  # Call the appropriate method to search for the requested course in the

  # list of courses.

  # If the course is not full yet, add the student who made this request;

  # Decrement the capacity for this course.

  # If the course is full, print an appropriate message.

  def process_requests(self):

 

  # Search through the list of courses for the course with department code

  # and number matching those received as arguments, and return the course.

  def find_course(self, course_dept, course_number):

 

  # Print a list of the requests in the Priority queue.

  # For each course, print a list of students registered for the course.

  def print_class_list(self):

 

 

 

The main method has been provided below (separate class). It should not be changed.

 

def main():

   request_queue = Queue.PriorityQueue()

   control = Ctrl.Controller(request_queue, 'course.txt', 'request.txt')

   control.read_course_file()

   control.read_request_file()

   control.process_requests()

   control.print_class_list()

 

You may create new methods, but must use the provided methods (i.e. the methods provided must not be by-passed).

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE