Objectives: 1. To be able to create and manipulate Queues. 2. To understand how to use Queues to simulate real-life prob
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Objectives: 1. To be able to create and manipulate Queues. 2. To understand how to use Queues to simulate real-life prob
Lab Exercise: Implement the following classes: 1. class course that includes two instance variables: course id id name #course name Your class should have the following: A constructor that initializes the two instance variables sd and name. • Set and get methods for each instance variable. 2. class DepartmentQueue (using the circular queue approach) that includes five instance variables: deptane deptQueue maxSize head tail department name Department Quee maximum size of the queue Queve head Que tall Your class should have the following: a constructor that initializes the department name exist (id) that checks whether the course object with id passed as parameter exists in the queue or not. • enqueue (id, name) that creates and adds the course if the course with id passed as parameter does not exist in the enqueue. The course must be added to the top. Then return: o 1: if the insert was successful o 2: if the enqueue is full o 3 if the value is a duplicate enqueue (temp) that inserts a node given as a parameter at the end of the queue. • dequeue () removes and returns the first Node of the queue if the queue is not empty; otherwise, returns None. • findCourse (id) that returns a course name if the id exists in the queue otherwise, return None. • print () that prints the department name and all the courses in the queue. Write the expected time and space complexity as a comment at the beginning of each method of your class. 3. Write a test program named Lab3Test. Do the following: • Input the department name then create a department object. • Display a menu to the user asking for a choice to be entered. (see the sample output) . The program will perform the action selected by the user and display a proper message when necessary. • The program will repeat these actions until the user terminates the program (Hint: Use a loop).
Sample Output: Please enter the department name: Computer Engineering How many courses does the department have? 4 This program can perform the following enqueue a course 1 2 3 4 5 exit Please enter your selection: 4 Computer Engineering does not have any courses. This program can perform the following 1 enqueue a course 2 3 4 dequeue a course search for a course print queue dequeue a course search for a course print queue 5 - exit Please enter your selection: 1 Enter the course number or -1 to stop: 325 Enter the course name: Human-Computer Interaction Enter the course number or -1 to stop: 262 Enter the course name: Digital Logic Enter the course number or -1 to stop: 207 Enter the course name: Data Structures Enter the course number or -1 to stop: 262 Enter the course name: testing duplicate Error! duplicate ID number... Enter the course number or -1 to stop: 221 Enter the course name: Software Engineering Enter the course number or -1 to stop: 200 Enter the course name: Testing Full The Department is full... The course could not be inserted... This program can perform the following enqueue a course 1 2 dequeue a course 3 search for a course 4 print queue 5 exit Please enter your selection: 4 Courses in Computer Engineering department are: 1- 325 Human-Computer Interaction 2- 262 Digital Logic
3- 207 Data Structures 4 221 Software Engineering This program can perform the following enqueue a course dequeue a course search for a course print queue 1 2 3 4 5 exit Please enter your selection: 3 Enter the course number: 207 The id: 207 corresponds to Data Structures This program can perform the following enqueue a course dequeue a course search for a course print queue exit 1 2 3 4 5 Please enter your selection: 2 The course removed was 325 Human-Computer Interaction This program can perform the following 1 enqueue a course 2 dequeue a course 3 search for a course. 4 print queue 5 exit Please enter your selection: 2 The course removed was 262 Digital Logic This program can perform the following 1 enqueue a course 2 3 dequeue a course search for a course print queue 4 5 exit Please enter your selection: 2 The course removed was 287 Data Structures This program can perform the following 1 enqueue a course 2 dequeue a course 3 search for a course
4 - print queue 5 - exit Please enter your selection: 3 Enter the course number: 207 The id: 207 does not correspond to any course in the department This program can perform the following enqueue a course. dequeue a course search for a course 1 2 3 4 5 exit Please enter your selection: 2 The course removed was 221 Software Engineering This program can perform the following 1 enqueue a course 2 3 print queue 1 2 3 dequeue a course search for a course print queue exit 4 5 Please enter your selection: 2 The queue is empty! This program can perform the following enqueue a course. dequeue a course search for a course. 4 print queue 5 - exit Please enter your selection: 5 Exiting the program!