A+ Work





Regis University CC&IS
CS362 Data Structures

Programming Assignment #5 (covers classes and objects)

A college wants to you to write a test program for tracking their course sections.  
Classroom capacities on campus range from a minimum of 1 student to a maximum of 30 students.

Data stored about each course includes:  the course number, the course title, the capacity (number of seats) for the course, the number of students enrolled in the course, and a list of student ids for students enrolled in the course. 

Class Details

The following data members must be declared as part of the new class, course.

 Data Field   Data Type
 course number   string (2 uppercased letters followed by 3 digits)
 course title   string
 capacity    integer (between 1 and 30)
 number students enrolled integer (between 0 and capacity)
 student id list   array of 5-digit student ids (size = maximum course capacity)
   
The following member functions must be declared as part of the new class, course.

 Two constructor functions (one without parameters, and one with parameters)

 Constructor without parameters will set the initial values to:
  course number to “ “
  course title to “ “ 
  capacity  to minimum capacity of a classroom
  number students enrolled to 0

 Constructor with parameters will provide the following parameters and default values:
  course number (no default – must be supplied)
  course title (no default – must be supplied)
  capacity  = (default = maximum capacity)
 The number students enrolled will not be a parameter, and this constructor will set it to 0.

 Mutator functions (assign values to data members)
setCourseNum
setCourseTitle
setCapacity

 Accessor functions (access values from data members)
getCourseNum
getCourseTitle
getCapacity
getNumEnrolled

 Facilitator functions:
  printCourse  (display course data)
  printStudentIds  (display all student ids on student id list)
  addOneStudent  (add one student to course)
  dropOneStudent  (drop one student from course)

Operator overloading functions:
  operator++  (increment capacity by one)
  operator<<   (displays object data)

NOTE:  Data members within the course type class may only be accessed via the above member functions.

You will also need to define several functions outside of the class, for reading and error checking user input and managing the courses.

Program Details

When the program begins, it will create three course type objects as follows:

Create using the constructor with parameters to set the course number and course title to
CS361, Control Structures (will use the default capacity).
Create using the constructor with parameters to set the course number and course title to
CS362, Data Structures, and set the capacity to 10.
  Create using the constructor without parameters.
  
After course3 is created, prompt the user for the course number and course title, and assign
them to the object data fields.

When all three courses objects have been created, the program will allow the user to manipulate the objects.

The program will access the course number and course name in each of the course objects to present a
Choose Course menu to the user for choosing a course to manage.

The Choose Course menu must be implemented so that the user enters either a course number or E to exit.

Example:
Choose a course to manage:
CS361 – Control Structures
CS362 – Data Structures
MT415 – Linear Algebra
Enter the course number (e.g. CS200) or E to exit:

After the user chooses a course to manage, the program will display a Course Management menu of action
choices, as detailed on the next page.

The actions will be applied to the course that was chosen to be managed.
Course Management menu choices:

 P - Print course data (to the screen)

  Use the overloaded << operator to display the course data as follows:

     CS361 - Control Structures:
       1 seats taken, out of 15 total seats

N – Modify course Number

Call a function to read, error check, and return a valid course number.

Course numbers must be 2 letters followed by 3 digits. If a course number entered by the
user is invalid, issue an error message stating why it is invalid.  Loop and re-prompt for the
course number, until it is valid.

The function should uppercase the letters, if user enters them in lowercase, before returning
the value.

Then use setCourseNum to store the new value, and then confirm the change.
Example:
 New course number is CS430

T - Modify course Title

Call a function to read, error check, format, and return a valid course title (i.e. course name). 

Course titles can contain only letters and spaces.  If a title entered by the user is invalid,
issue an error message stating why it is invalid.  Loop and re-prompt for the title, until it is
valid.

NOTE:  In order to read the title, you will need to use getline (covered in text Chapter
3) because the extraction operator (>>) will only read strings up to the first whitespace.

After error checking the title characters, format the title. The first letter and each letter
following a space will be uppercased, and the rest will be lowercased.  Return the valid
formatted title.

Then use setCourseTitle to store the new value, and confirm the change.
Example:
 New course title is Operating Systems

C - Modify course Capacity

Call a function to read, error check, and return a valid course capacity.  The function should
insure that the new capacity is within the minimum and maximum allowable capacity.

Using the returned value, check to insure the new capacity is not less than the current student
enrollment (use getNumEnrolled to check the current enrollment).
If the new value is below the current number of students enrolled, issue a message saying that
students must be dropped from the course first.
Example:
Error - cannot change capacity to 20 unless 2 students are
dropped, because 22 students are already registered.

Otherwise, use setCapacity to store the new value and confirm the change.
Example:
Capacity is now 11

 I - Increment course Capacity

Use the overloaded ++ operator to increment the course capacity by one, as long as it does not
exceed the maximum capacity allowed, and then confirm change. 
Example:
Capacity is now 12
  
 S – Student Management

Display a Student Management sub-menu (display student ids, add one student, drop one
student, and return back to the Course Management menu).

The options should be implemented as follows:

      P – Print Student IDs (to the screen)

Use printStudentIds to display the ids of students enrolled in the course,
one student per line.

Example:
2 students enrolled in CS361
77777 
87228  

   A - Add one student

    If course is full, issue an error message.  
  Example:
     Course is full.  Cannot add any more students.

Otherwise, use addOneStudent to add one student to the course, as follows:

Call an input function to read, error check, and return a valid student ID (must be a 5digit
integer,
no leading
zeros allowed).
Then store the student id number in the list, increment the student enrollment, and Confirm the change.
If the course is empty, simply display a message stating there are no students enrolled.
  Example:
     Cannot drop a student -- no students are enrolled.
  
Otherwise, use dropOneStudent to drop one student from the course, as follows:

  a)  Display the student ids
  b)  Ask the user for the student id number of the student to drop
c)  Find the student id number in the list
     d)  If the student id number is found, delete the id from the list
          and decrement the enrollment.
Reminder:  Deleting from unordered arrays was covered in
                    online content sections 3.4.3 and 3.4.4.
  e)  Display a message confirming which student id number was dropped,
                                or stating that the student id number could not be found.

  B – Back to Course Management menu
  
   Exit the Student Management menu and return to the Course Management menu.

  Loop around the Student Management menu options, until the user chooses B.
  [END of Student Management menu options]

B - Back to Choose Course menu

 Exit the Course Management menu and return to the Choose Course menu.

 Loop around the Course Management menu options, until the user chooses B.

The program will loop around the Choose Course menu, until the user chooses Exit. 

NOTE:  For each menu, when a menu choice is entered, the program will error check the user has entered a valid choice, and will issue an error message if the choice is not valid.

Before exiting the program, use the overloaded << operator again to display the course data for all three courses.

Program Notes:

1. Your program must conform to all CS362 Coding Standards specified in Content section 1.7.
- The program should include a file header at the top of each program file
- Each function should include a function header.
2. This program should be of modular design (minimum of FIFTEEN functions/methods).  
  - The breakdown of the code must be logical, not arbitrary!
©2015, RegisUniversity, All Rights Reserved
Unauthorized distribution (including uploading to any non-Regis Internet website) violates copyright law
- The main function should do little more than call other functions.
- The other functions/methods should each perform ONE well-defined task.
3.   Your program should be thoroughly tested, and test data files should be submitted.