It’s about time for registration at UNM. In that spirit, we will be writing some code that assigns students to classes and includes all the relevant information about the student and instructors involved.
The program needs to be named scheduler.c.
Create a struct to represent a person at the university and call it Person. People all have the following attributes (you’re free to name these in your underlying datastructure whatever you want as long as your names are appropriately descriptive:
In tandem with this, you should have the following methods:
This method will print out the person’s first and last name, separated by a space. If the person is not a student, then the person is a professor and the method will print out “Prof. ” followed by their names.
This method will create a Person struct, allocate space for them on the heap, instantiate all the fields in the struct, and then return a pointer on the heap.
Create a struct to represent a class taught at the university and call it UNMclass. Classes all have the following attributes (again, free naming)
Note: Your struct can contain other variables inside it to help you with the problem. This is the minimum that your UNMclass needs to contain.
In tandem with this, you should have the following methods:
This method will print out the UNM department followed by the course number, separated by a space.
This method will create a UNM class struct, allocate space for them on the heap, instantiate all the fields in the struct (except for the array of student pointers), and then return a pointer on the heap.
Create a few students and allocate memory for them on the heap. Write a few print statements to make sure that you’re properly writing to these structures. In particular, char *s can be tricky to write to.
Create a few UNMclasses and appropriate instructors for the courses, allocating memory for them on the heap.
Create a data structure on the heap to hold all of the UNM classes in for a particular semester and call it spring19. This should be a variable held in main. (If you try to make this a global, your program will give you an error. Why?) You can safely assume there are going to be fewer than one thousand classes in a semester. Your data structure should not duplicate UNMclasses. What type should this be?
Be sure to update your datastructure after calling the createunmclass method each time.
Fill in the following method:
enroll should return a zero if enrollment was successful and a different number otherwise. Enrollment is unsuccessful if a UNMclass is full or a person is not a student.
Fill in the following method:
printschedule should look through the spring19 schedule of classes to find each one that the student is enrolled in. This method should print the department name followed by a space followed by the class number. Each course a student is enrolled in should be on a new line.
For instance, if a student “Julia Campbell” was enrolled in CS241, CS251, Math162, and English107, this method should print out:
We provide some testing code in scheduler.c which the instructors will use to grade your assignment along with the expected output in testscheduler.out. You will need to provide additional testing code for your testing grade. Think of additional edge cases to cover.
Zip your file and turn it in via the hw-07 folder in the course dropbox.
12 points: | Program compiles without errors or warnings on moons.cs.unm.edu using /usr/bin/gcc with the -Wall -ansi -pedantic options. Correct output for the provided main method. The expected output is found in testscheduler.out. Note that we will use a diff test, so whitespace matters. Everything allocated on the heap is later freed. |
4 points: | The program starts with a comment stating the students first and last name. The program is correctly named. The code follows the CS 241 coding standard. |
4 points: | The code the student wrote in the main method tests the functionality of the program in normal and error cases. The testing code is nontrivially different than the provided code (eg more than just names are changed). |