Topical Information

This program should help you understand the use of (char-mixed) input and list management.

Program Information

Some students (as early as junior high or even as late as college) find reading assignment lists difficult. They see the teacher write something like 4-10 and do problem 4 and problem 10 — but not the other 5 assigned problems!

To help these poor lost souls, we'll write a program that can take in the (possibly) hyphenated assignment list and print back out a list of all problems assigned. Just in case, we'll also make sure our list is sorted (non-decreasing order) and contains no duplicates. You can assume that all problem numbers are whole numbers and that the user will enter the numbers with no typos.

Here are some examples...(These are all fine — I've checked them myself!)

User Types In...We Display...
L6 Do problem 6 of L.
L1-3 Do problems 1, 2, and 3 of L.
L1,2,5 Do problems 1, 2, and 5 of L.
L1-3,5 Do problems 1, 2, 3, and 5 of L.
L1-3,5-7 Do problems 1, 2, 3, 5, 6, and 7 of L.
L1-1,3-3,5-8 Do problems 1, 3, 5, 6, 7, and 8 of L.
L4-5,1-3,7-10 Do problems 1, 2, 3, 4, 5, 7, 8, 9, and 10 of L.
L4-5,1-3,7-10,8-12 Do problems 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, and 12 of L.

Let the problem set name be either a single character, a single word (containing no digits), a quoted string, or even a quoted, space-containing string. The problem set name will always be entered first. If the user uses a quoted problem set name, allow them to use either a single quote (tick-mark) or double quote — but the open and close can be assumed to match. So any of L, LssnTwo, "Lssn2", or even 'Lesson 2' would be a valid problem set name. (Note that the quoted problem set name can have a digit in it — just not a single-word or single-character problem set name.)

Spaces around the input should be optional (so L1-3 should result in the same answer as L 1 - 3). All items/hyphenated groups are to be comma separated (so L1,2,5 is okay but L1 2 5 and L125 are not; well, the second could mean they just want to do problem 125, *grin*).

We'll assume that all problems are to be done for simplicity. (See the option below about evens vs. odds for more fun.)

If the display of the problem list is longer than a line, wrap it gracefully — don't let the terminal window wrap it for you (or the printer could very well chop it off!).

Thought Provoking Questions

  1. In what data type(s) can you store something like the problem set name that might be anything from one character to a whole bunch of text?

  2. How can you detect that the problem set name is a quoted string? How can you read in the whole thing to a single variable? (Don't worry that the user has missed a close quote.)

  3. If the user's problem set name is a quoted string, how can you remove the quotes from it? (Just like C++ won't leave your quotes on a string when it prints it, you shouldn't leave the user's quotes on their string. They are just there to separate the problem set name from the problem list...and group it together as it may contain a space or tab...)

  4. When placing items (say problem numbers?) into a list, how can you keep those items sorted from the beginning? (I.E. from their very insertion into the list..?)

  5. How can you avoid placing a duplicate item into a list? (Note: I'm not asking how you can remove duplicates from a list, but rather how can you avoid having any duplicates in the list in the first place!)

  6. If the problem list is long (like in math or physics), how can you wrap the long output line to multiple lines without too much difficulty? (Hint: The output line can be around 70-75 chars long, we saw in 121 how to tell how many digits long an integer is, we know we are outputting a comma and space between the problem numbers, and we know how many chars we are adding before the list and after the list. Just don't forget the 'and' before the last element. So, knowing all that, especially that you need to drop to a new line after every 70-ish chars you've output, how do you tell if total chars printed is 70*n?)

This assignment is (Level 4).