Lab 9: Passing data with structs and classes
Contents
Instructions
This lab will give you experience using structs and classes in C++. You will write a program for creating and modifying a course schedule. The program should ask the user for a year (e.g., 2017) and a semester (e.g., Winter, Spring, Summer, or Fall). It should then continually present a menu with four choices until the quit option is selected:
- add a course to the schedule
- remove a course from the schedule
- print the schedule
- quit the program
If the user chooses to add a course, the program should ask for the following information and add the course to the schedule:
- course number (e.g., CSC160)
- number of credits
- instructor
- course title
- time (e.g., MWF 9:50-10)
If the user chooses to remove a course, the program should ask for the number of the course to remove. It should then remove that course in the list of courses by replacing it with whatever course is at the end of the list, then ignoring the course at the end of the list.
If the user chooses to print the schedule, the program should display all of the courses in the schedule (not including removed courses) in a tidy format and include at the end the total number of credits in the schedule. All information about a course should be displayed (number, credits, instructor, title, and time).
Your program should include a struct to keep track of course information and a class to keep track of the schedule. Give these good names. The schedule class should include a constructor to set the semester and year. It should also have a method to add a course (that takes a course instance as a parameter), remove a course (that takes a course number as a parameter), and print the schedule. A schedule shouldn't allow more than 8 courses.
One note. You will need an array to hold the list of courses inside the schedule class. When setting the max size of this array, you will want to use a constant as we have in the past. You can declare a constant data member of a class, but you need to declare it as static, which means that it will be the same across all instances of the class. E.g., you will declare the constant as a data member like this:
Submission
Submit your .cpp files to here. You can view the rubric here.
(Back to top)