Lab 4 Ex 3: Guest List
You cannot submit for this problem because the homework's deadline is due.
Related Topics: IO.
This exercise will help you get familiar with string streams
.
After a great success of making the apple pies, you cannot wait to show off your cooking skills in front of your friends. Tim, a close friend of you, volunteered to contact and invite others to your apple pie party. He sent you a message of all the people he has invited just now, but message seems a bit messy, maybe because he was typing too fast... Tim's message is something like
Ann ,Peter , Owen,Alice , Bob, Tim
He uses spaces and commas to separate the names, but sometimes there are too many spaces between a name and a comma and sometimes there's no space. Now, you want to make a name list using that message. Also, you want to know the exact number of people.
Please write your code in a file named ex3.cpp
. Here are the requirements:
Input: The input is Tim's message like the one shown above. You can assume that all the names only contain English letters, and there is no space inside the names (i.e, names like "Tim White" will not appear in the test cases). Also, you can assume that only 1 comma can appear between 2 names. However, the number of spaces and the number of names are not fixed. The name list could be much longer.
Output: Output the list of guest names followed by the number of guests. Example:
Ann Peter Owen Alice Bob Tim 6
The sequence of names should be the same as the input message. Each name or the number occupies one line.
Hint: Please use
string stream
to solve this problem, which would greatly ease your work.
Testing
Compile ex3.cpp
to an executable file ex3
. Execute it and then input the message.
Example input:
Ann ,Peter , Owen,Alice , Bob, Tim
Example output:
Ann
Peter
Owen
Alice
Bob
Tim
6
Lab Four
- Status
- Finished
- Problems
- 3
- Open Since
- 2022-06-07 20:00
- DDL
- 2022-06-14 23:59
- Extension
- 72.0 hour(s)