Challenge 78

Description

The purpose of this challenge is to create user-defined types by creating structs. This challenge creates a rudimentary enrollment system.

 Requirements

  1. Create the structs below
    struct Student 
    {
        string first, last;
    };
    
    struct ClassInfo
    {
        string title;
        int units;
        int maxenroll;
        int maxwait;
        int enrollcount;
        int waitcount;
        Student enrolled[5];
        Student waitlist[3];
    };
    
  2. Copy the starting main()
    int main()
    {
        // initialize a ClassInfo instance
        ClassInfo cmps { "CMPS2020", 5, 5, 3, 0, 0 };
    
        char input;
    
        do
        {
            cout << endl;
            cout << "Action (a-add, s-show, q-quit): "; 
            cin >> input;
            cout << endl;
     
            if (input == 'a')
            {
                if (cmps.maxenroll == cmps.enrollcount)
                {
                    cout << cmps.title << " is full" << endl;
                    if (cmps.maxwait == cmps.waitcount)
                    {
                        cout << "Wait list is full" << endl;
                    }
                    else
                    {
                        cout << "Wait list is open" << endl;
                        // TODO - Call the add_student() function
                    }
                }
                else
                {
                    cout << "Register for " << cmps.title << endl;
                    // TODO - Call the add_student() function
                }
            }
    
            if (input == 's')
            {
                // TODO - call show_enrolled()
                // TODO - call show_waitlist()
            }
    
        } while (input != 'q');
    
        return 0;
    }
    
    
  3. Write a function void add_student(ClassInfo & ci). In this function
    1. Ask the user to enter values for a first name and a last name
    2. Check that ci.enrollcount is less than ci.maxenroll. If so, add the first name and last name into the ci.enrolled array. Use ci.enrollcount as the index into the array, remembering that ci.enrolled is an array of Student. After adding the first name and last name into the ci.enrolled array, increment ci.enrollcount. 
    3. In Step 2, you checked if ci.enrollcount is less than ci.maxenroll and added the first name and last name to the ci.enrolled array. If that is not the case, then first name and last name will have to be added to the ci.waitlist array instead. Similarly, you would use the ci.waitcount properties as you did in Step 2
  4. Create a function void show_waitlist(const ClassInfo & ci). This function will display all the students in the ci.waitlist array, showing one student per line
  5. Create a function void show_enrolled(const ClassInfo & ci). This function will display all the students in the ci.enrolled array, showing one student per line
  6. Review the sample main provided above, and fill in the TODO sections

Sample main()

Provided above

LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT

CATALOG ID: CPP-CHAL00078

Print Requirements