Goals
- to get more practice writing C++ programs
- to think about how information is stored in data structures you've designed
Problem Overview
This program creates lists of which people have met.
Each line of input is a space-separated list of the names of people
who have met - a group.
If a person is in a group with someone, they have met and should be
on each other's contact list.
Names do not contain spaces and are unique.
Upper and lower case are significant. For example, Beth ≠
BETH ≠ bEtH.
The output is a list of each person's contacts on a separate line. That line has the person's name followed by a colon followed by a space-separated list of their contacts' names. The people and their contacts do not have to be in any particular order.
Problem Specification
Write a C++ program to solve this problem.
You may use classes from the Standard Template Library.
The input is multiple lines of groups of people terminated by end-of-file on standard input. Ignore blank lines and keep reading.
To help see what is happening, if the first character of an input line is the question mark character, the program should print the current contact lists and ignore the remainder of that line. Otherwise, the only output other than optional prompts for input will be when input ends. At that point, print the current contact lists and end the program. People should not be listed on their own contact list. There should not be duplicate names on a contact list.
To obtain input, your program should use the LineScanner class from the list assignment with string as the type.
You may use any data structure you wish. Use what you are most comfortable with. You will not be graded on which data structure you use as long as you use it correctly.
You should create and use your own data for testing.
There is no specified data size. Your structures should be able to grow. The data will be a reasonable size. It will not be big enough to cause problems if you use O(N2) algorithms.
Emphasize ease of understanding and writing. Efficiency is not as important as your understanding what you are building. You may have to modify this program later this term.
You must use functions, pass parameters appropriately, and include comments in your code.
Develop the program in a separate directory that contains the LineScanner.h file.
You may put your entire program in one file or put it in separate files.
You may use classes if you wish, but you do not have to.
You should include a proper Makefile that builds your program by default.
However, I should be able to compile your program cleanly with
g++ -Wall *.cpp
Please don't have extra .cpp files in your directory.
If you want to keep some extra C++ files there, rename them to end in .cxx.
Before submitting, compile and run your program from the command line/terminal with the command above. Submit it as the contact assignment.
C++ hints and warnings
To make code easier to read, you can use a typedef that creates a textual
shortcut for writing types. If you wanted to use the name Contact
instead of string, you would write:
typedef string Contact;
You could also use this if you wanted a vector of Nodes of Contacts
(that doesn't sound like a good idea here) as in:
typedef vector< Node<Contact> > ContactList;
If I have a typedef for Contact, I can use it in a parameter list as
const Contact & person
Note that I put spaces around the Node part in the typedef above. You do not want two >> next to each other because they create an input symbol rather than two > symbols.
Analysis - There may be a quiz about this before or after the due date.
Understand how well your program performs.
Think about the complexity of the algorithms you use for inserting
contacts and printing.
Be able to sketch how you are representing the data and discuss why you chose that approach.
Create and use your own data for testing. You may be asked to document what test cases you used. Test cases consist of input and expected output. Good test cases reveal bugs in your code. Bugs lurk in corners. Look for them at boundaries.