This assignment will give you practice with using arrays, including random access, sequential access and search.
You are to write a program which keeps track of a student’s schedule, which is a list of course numbers at different times. In this case, the legal times are between 8 and 15 (military time, again).
The user should continuously be prompted for whether the want to add a course, drop a course, or print their current schedule until they choose to quit the program. More details on each of these options below:
Adding courses
If the user chooses to add a course, the program should prompt them for:
o The course number they wish to add. This must be a number greater than 0.
o The time they wish to take the course. This must be a number between 8 and 15.
If both of these are legal, that course should be added to the schedule at that time, and a message confirming that the add has been done should be printed, and the program should return to the main menu.
The course number and/or time can be illegal in the following ways:
o The course number is not greater than 0.
o The time is not between 8 and 15.
o The student is already taking that course.
o The student is taking another course at that time.
In any of those cases, an error message should be printed, and the program should return to the main menu without adding anything.
Dropping courses
If the user chooses to add a course, the program should prompt them for the course number they wish to drop.
If that course is legal, then that course should be removed from the schedule at whatever time it is currently being taken, a message confirming that the drop has been done should be printed, and the program should return to the main menu.
If the user is not taking that course, then an error message should be printed, and the program should return to the main menu without dropping anything.
Printing the schedule
If the user chooses to print their schedule, then your program should list the hours 8 – 15, along with what course is being taken at that time (or a blank space if nothing is being taken at that time). See below for what this should look like.
Here is an example to help you out:
A)
Add a course
D) Drop a course
P) Print your schedule
Q) Quit
Enter one of the above options: A
Enter the course number: 0
That is not a legal course number!
A) Add a course
D) Drop a course
P) Print your schedule
Q) Quit
Enter one of the above options: A
Enter the course number: 2610
Enter the time to schedule the course (8 – 15): 17
That is not a legal time!
A) Add a course
D) Drop a course
P) Print your schedule
Q) Quit
Enter one of the above options: A
Enter the course number: 2610
Enter the time to schedule the course (8 – 15): 11
2610 has been added to your schedule.
A) Add a course
D) Drop a course
P) Print your schedule
Q) Quit
Enter one of the above options: A
Enter the course number: 1551
Enter the time to schedule the course (8 – 15): 11
You are already taking 2610 at 11!
A) Add a course
D) Drop a course
P) Print your schedule
Q) Quit
Enter one of the above options: A
Enter the course number: 1551
Enter the time to schedule the course (8 – 15): 9
1551 has been added to your schedule.
A) Add a course
D) Drop a course
P) Print your schedule
Q) Quit
Enter one of the above options: A
Enter the course number: 2610
You are already taking 2610 at 11!
A) Add a course
D) Drop a course
P) Print your schedule
Q) Quit
Enter one of the above options: P
-----------
8:
9: 1551
10:
11: 2610
12:
13:
14:
15:
-----------
A) Add a course
D) Drop a course
P) Print your schedule
Q) Quit
Enter one of the above options: D
Enter the course number: 1571
You are not taking that course!
Enter one of the above options: D
Enter the course number: 1551
1551 has been dropped from your schedule.
Enter one of the above options: P
-----------
8:
9:
10:
11: 2610
12:
13:
14:
15:
-----------
A) Add a course
D) Drop a course
P) Print your schedule
Q) Quit
Enter one of the above options: Q
Clearly, you will need to use an array to keep track of what courses the user is taking at what times. Since there are 8 legal times, the array must store 8 elements, each one to store what is currently being taken at that time (that is, one for the course being taken at 8, another for the course being taken at 9, etc.).
Since the user will be thinking in terms of times in the range 8 to 15, your program will have to translate the times entered by/printed for the user to and from the legal array indices, 0 through 7.
Finally, you will need to store some number in your array to represent no course currently being taken at the corresponding time. I suggest that you store the number 0 (which is not a legal course code) at any time when no course is being taken. This means you will have to do the following:
o Initialize all elements to 0 at the beginning of your program (initially, the schedule contains no courses).
o Before adding a course, make sure a 0 is stored at that time.
o When dropping a course, store a 0 in its place.
o When printing the schedule, check whether the course number at a given time is 0. If so, print a blank space for that time, rather than the course number.
In order to find whether a student is already taking a course, or to find a course the student wants to drop, you will have to search for that course in the array, finding the index number of the element (if any) which contains that course.
Since this is probably the hardest part of the assignment, you will probably want to save it for last. That is, start by writing a program that adds courses (without checking whether they are already being taken) and prints the current schedule. Once that works, add the other features.
You are also required to break your program up into functions in logical ways (that is, a function to add courses, a function to drop courses, a function to search, etc.). Note that you are **NOT** to use any global variables in this program.