CSC 2210, SPA 3: MeetingUp++

Description

This assignment will give you experience with implementing C++ classes. Possibly motivated by the CREATE Institute at MSOE, you have decided to build a general-purpose match-making application that takes the names of two groups of students and uses an algorithm to determine perfect matches for any activity from tandem kayaking to catching a musical at the Performing Arts Center. Unfortunately, you failed to realize the effort required to build a matching application and decide to use a trivial method: two students match if their names have a letter in common or they have the same day of birth. You are going to write C++ classes to solve your problem. This is an individual assignment.

This has been broken into steps with the idea that you can just start on the first step without reading the full writeup. But feel free to read it through at the start if you want!

Stage 1: Getting your code to compile

  1. First, set up a project in CLion:
    1. Open CLion and select New Project...
    2. Select C++ Executable, make sure the language standard is C++17 or later, and pick a location on your computer.
    3. Copy main.cpp into the folder. This will overwrite the old main.cpp with the new version.
    4. Use CLion to create the files pool.h and pool.cpp. For pool.h, select File | New | C/C++ Header File. For pool.cpp, use C/C++ Source File.
    5. Right click on pool.cpp and see if there is a menu item Add ‘pool.cpp’ to CMake Project; if so, click on it. Note you do not do this with pool.h.
    6. Build. This will fail because you do not have any code in the new files yet.
  2. Next, put two classes into pool.h: Student and Pool. For now, put no data in the classes.
  3. Add constructors to Student. You will need to be able to create a Student object with just a string (the student's name) and also with both a string and an integer (the day of birth). You can use default arguments if you like. You will refine these below.
  4. In addition, add prototypes for the following Student methods:
    • A method printableDescription which takes no arguments and returns a string.
    • A method matches which takes a pointer to a Student object and returns a boolean value.
      Warning: use *, not & to declare a pointer; declaring a reference instead will create problems throughout the assignment.
  5. CLion users may see wavy yellow lines at this point. This is typically due to the CLang-Tidy assistant, which might produce good advice to professionals but produces very bad advice to students in this class. If you have not turned it off yet, visit exercise 1 to see how to turn off this assistant.
  6. Add constructors to Pool. There needs to be a constructor with no arguments and a constructor with a string argument (representing a student's name) and an optional integer argument (representing the day of the month the student was born). The integer argument defaults to 0.
  7. Add prototypes for the following Pool methods:
    • A void method add that takes a string as an argument.
    • A void method add that takes a string and an integer as arguments. You could combine this with the previous one and use default values.
    • A void method readStudents that takes no arguments.
    • A void method printMatches that takes a Student pointer as an argument.
    • A void method printMatches that takes a Pool pointer as an argument.
    • An empty method that takes no arguments and returns a boolean value.
  8. Ensure there are no syntax errors. The code will not build because you have not yet defined the Student and Pool methods, but main.cpp should have no errors in it. You will likely need to include additional library code and make other changes. You should not change main.cpp.
  9. Uncomment the second #include for pool.h in main.cpp. This will break the build. Fix it by adding the appropriate "#ifndef magic" to pool.h. See the phonebook project for an example.
  10. Add implementation stubs for Student and Pool to pool.cpp. A stub is either an empty body or a body that returns a constant result (for example, always returns true).
  11. Fix the project so it builds without errors. You can get 20% credit for meeting just this goal. Your code will not do anything useful at this point, but it will have the appropriate structure and not be too far from running.

Stage 2: Reading Data

Add code to read all data. This will require adding private data in the class definitions (in pool.h) and appropriate implementations in pool.cpp.

  1. Implement Student so it holds a name and the day of the month the student was born. The day will be between 0 and 31 with 0 meaning "no information".
  2. Implement the Student constructors. The constructor which takes arguments initializes the pool to contain a student with that name and day. Recall the day defaults to 0.
  3. Implement printableDescription to return the name. If the day number is greater than 0, follow this by " born on day X" where X is the day number. Use std::to_string to convert the number into a string.
  4. Implement matches to return true if the birth day numbers are both greater than 0 and they match or any character in one of the names is also in the other student's name (ignoring underscores).
  5. Get this code to compile and build.
  6. Add an array of student pointers to Pool. The array must allow up to 20 students. You will also need a counter of the actual number of students in the pool. Note: this must use regular arrays; no vector or similar container classes.
  7. Implement the constructor with no arguments so it creates an empty pool.
  8. Implement the constructor with the string and integer arguments to create a pool with one student in it.
  9. Implement the add methods to create Student objects and add them to the pool.
  10. Implement readStudents so it reads student names and birth days from standard input until either end-of-file is reached or the text "END" is read; note that names are written as single words with '_' used to separate parts of the name. Assume each name is followed by an integer, and read that integer as the birth day. You do not have to test for the birth day being out of range. Each of the first 20 students is to be added to the pool. You can assume that if there is a name in the input, it is followed by an integer. This includes the word END. See input1.txt for an example.
  11. If readStudents finds more than 20 students before "END", ignore the additional students. That is, continue to read students until you reach END, but do not add them too the pool.
  12. You can assume that if two students have the same name, they are still unique (even if their birth dates also the same). That is, there will be two Student objects in the pool with the same name.
  13. Get this code to build.
  14. Run your program on input1.txt. It will not do anything at this point, but it should at least run without crashing. See the directions from assignment 1 to set your run configuration to read from the file.

When you are finished, your classes will match the structure shown in this diagram:

a
    class diagram capturing the methods mentioned above

Note this captures just the minimal data and methods. You can add private data and private methods. In fact, it is almost necessary to add other private elements to avoid duplicating code.

Stage 3: Printing Matches

This stage will lead you through printing matches for simple cases. More complex cases will be handled in later stages.

  1. Implement empty to return the appropriate result.

  2. Implement the version of printMatches that takes a Student argument and cycles through the whole pool, printing

            A perfect match for X: Y
    

    (where X is the name passed to printMatches and Y is a name in the pool) for each matching student. The rules for whether two students match are given below. When printing names, print a space instead of an underscore. This likely means changing printDescription to handle underscores. You might find it handy to create a printable version of the name and/or description as private data in Student.

  3. Implement the second version of printMatches so it prints all matches between this and the second pool. Process the students in the current object (the one pointed to by this) in the order they are in the array, and for each one call printMatches on the second pool.

    The rules for matching have a number of elements:

    • Allow matches anywhere in the name — "john" and "rebecah" do match on the h's.
    • ignore '_' (underscore) when matching. For example, "a_men" and "y_xi" would not match.
    • Ignore case — "John" and "jude" match on 'J' and 'j'. The full implementation is complex; start by just handling the first bullet and adding the second and third.

Note your main is configured so if the first name is TEST, the program runs simple tests and exits without processing any additional input. You can use this to do some basic testing at the start.

Constraints

These should be satisfied by doing the above, but just in case...

Other Notes

will read any type of character and print it out. If it is any non-letter, it will print the character unchanged. If it is a letter, it will print the uppercase form of the letter. You can use these in a loop to convert all of the letters in a string to either upper or lower case.

Submitting

Sample Files

This is not a complete list, but provides easy access to many of the tests.