Lab 13
For this week's lab we wish to implement a waiting list for a course. We will do this with a list of students, where we store the email, netid, and UIN for students, and the first student to register is the first one who gets added to the course.
The code we've given you should look somewhat familiar, it's got a Node struct, and a function which prints out the entire list. I've used a different struct, because I've got different data, but the form is the same. You may use your own structs, and rewrite the print method to match the form of your new struct, as long as the same data gets stored. Similarly, main is only there as an example of how the functions might be used, and can be modified as you wish, function calls included as long as the parameter types remain the same. Feel free to look at the previous lab examples and your solution from last week.
Stage 1 (1 point):
Write a function int addStudentToWaitingList(char[] email, char[] netid, int UIN, Node *& list). This function should take the student information, create the Node associated with that student, and add that node to the waiting list. If the add was successful, return 1. However, if the student is already in the waiting list, do not add a new student to the list, and instead return 0. You must look through the list for a matching netid or UIN, and if one is found then cancel the add, returning 0.
Stage 2 (1 point):
Write a function Node* fillAnOpening(Node*& list). This function should take the earliest student who registered and is still on the list, remove them from the list, and return the pointer to the Node containing that student's information.
Stage 3 (Extra Credit) (1 point):
Write a function int positionInList(char[] netid, Node* list) or int positionInList(int UIN, Node* list). This function should take the netid or UIN of a student, search through the list for the first (and only) occurrence of that student, and return the number of openings there would need to be in order for that student to get in to the class. The first student to register should be at position 1, the second at position 2, the third at position 3, etc. After there was one opening and the first student got in, the second one to register should be at position 1, the third at position 2, etc.
With the example in main that I've given you, this is the output I produce.
List contains: ee ddd cc bbbbb aa
Student D is waiting on 4 slots to open.
Student A is waiting on 1 slots to open.
Student C is waiting on 3 slots to open.
Student A@uic.edu aa 111111111 added to Course
Student B@uic.edu bbbbb 222222222 added to Course
Student C@uic.edu cc 333333333 added to Course
Student D@uic.edu ddd 444444444 added to Course
List contains: ee
Student E@uic.edu ee 999999999 added to Course
List contains:
Feel free to modify main as you wish (for example, if you want to pass the tail of a list as opposed to the head to a function).
Notes:
Keep in mind that this is a team effort so you should agree with your partner on what you are going to do before you start typing. The partner who is typing is the "driver" and the partner watching is the "navigator." Be sure to switch roles every 10 to 15 minutes, to foster a deep understanding of the code for both partners. The navigator should be watching for syntax errors and verifying the correctness of the code you're writing.
It will speed things up for you if you keep a window open for editing and have a separate window open for compiling and running your program. Remember that windows are resizable!
Submission:
1. You should work with a partner for this (and all the remaining) lab(s). Only one of you need to submit the program to Blackboard, though you should be certain that both of your names be present in a comment at the top of the .c or .cpp source file.
1.5 If you work alone, include just your name in a comment at the top so that I know you worked alone, and not have to guess.
2. You should turn in to Blackboard by the END OF THE LAB. I know it's tempting to keep working on it, but other classes come in, and it's not fair to the students who are limited to that particular time span if you go over. Which isn't to say that you can't work on it later, to check your solution against the one I post for your own understanding. But what you submit for a grade should be before the next hour begins.
3. If you wish, you may submit your lab by noon on Friday for a 1 point penalty. If you can't finish up the second point by the end of lab, you can still earn the score by completing all three steps and submitting your code by the day after.