Prog 1: Toothpicks

1/27 Update: Submission instructions changed to indicate you must turn in a .cpp file that is not zipped.  This will allow us to edit it online within Blackboard.

Once while waiting for food to show up at a restaurant I was shown a puzzle using toothpicks. Write a C++ program that allows you to explore possible solutions to this puzzle. 

Sample Runs

See a video demo of running the program:

Running the program should look like the following, where user input is shown in bold letters:

Program #1: Toothpicks  Class: CS 141           Author: Dale Reed       Lab: Tues 5am           System:  C++ Mac Xcode   Welcome to the Toothpick Puzzle, where the goal is to get an equal     number of toothpicks in each stack, in three moves.                                      Stack:   A   B   C       Number of Toothpicks:  11   7   6      A move consists of moving toothpicks from one stack to a second stack,      where the number of toothpicks moved is exactly the number that is in the   destination stack.  In other words, to move from stack B (7 toothpicks)     to stack C (6) as shown above, we would move 6 from B to C, leaving us      with 1 in B and 12 in stack C.     Here we go...                      Stack:   A   B   C      Number of Toothpicks:  11   7   6  1. Enter FROM and TO stack letters: B C                   Stack:   A   B   C      Number of Toothpicks:  11   1  12  2. Enter FROM and TO stack letters: CA                   Stack:   A   B   C      Number of Toothpicks:  22   1   1  3. Enter FROM and TO stack letters: ab                   Stack:   A   B   C      Number of Toothpicks:  21   2   1  Nope, sorry, that's not it.  Try again. 

Note that when you run your program, input doesn't have to appear in bold. Your program must accept user input with and without spaces between the letters, and in upper or lower case.  Note that only valid moves are allowed, as shown below in step 2 when running your program again: 

Program #1: Toothpicks  Class: CS 141           Author: Dale Reed       Lab: Tues 5am           System:  C++ Mac Xcode   Welcome to the Toothpick Puzzle, where the goal is to get an equal     number of toothpicks in each stack, in three moves.                                      Stack:   A   B   C       Number of Toothpicks:  11   7   6      A move consists of moving toothpicks from one stack to a second stack,      where the number of toothpicks moved is exactly the number that is in the   destination stack.  In other words, to move from stack B (7 toothpicks)     to stack C (6) as shown above, we would move 6 from B to C, leaving us      with 1 in B and 12 in stack C.     Here we go...                      Stack:   A   B   C      Number of Toothpicks:  11   7   6  1. Enter FROM and TO stack letters: a c                   Stack:   A   B   C      Number of Toothpicks:   5   7  12  2. Enter FROM and TO stack letters: ab    Sorry, not enough toothpicks in A. Retry...  2. Enter FROM and TO stack letters: ca                   Stack:   A   B   C      Number of Toothpicks:  10   7   7  3. Enter FROM and TO stack letters: ab                   Stack:   A   B   C      Number of Toothpicks:   3  14   7  Nope, sorry, that's not it.  Try again. Ending program...  

What You Need to Know

Notes

Steps

Work on your program one step at a time, following your own instincts on what those steps are.  If you get stuck then using the following sequence may be helpful:

Turning In Your Program

The name of the program you will turn in should be prog1 followed by your netid and the .cpp file extension.  In other words, if your netid is reed then your program would be called prog1reed.cpp   

Blackboard considers program source code as a threat and sometimes replaces random parts of it.  To avoid this you must also zip up the code you turn in.  To zip a file right-click on the single .cpp file to be turned in (e.g. prog1reed.cpp) and select "Send To" and then select the "compress" menu option. On a Mac simply right-click and then select the "compress" option.  The resulting file (for instance) will then be called prog1reed.zip 

Only turn in this single file, turning it in on Blackboard into the Assignment Program1: Toothpicks.  

Failing to follow these naming conventions or failing to turn in a zip file will result in a 5 point deduction.  (Note that I am not requesting some compression, but specifically zip compression).  Questions about this?  Ask on Piazza, or see a member of the instructional staff.

You may turn in multiple versions, but only the latest version will be graded.

Extra Credit (10 points) 

Do not turn in a "regular" version of the program if you are planning on doing the extra credit.  If you turn in both, then you will not be eligible for any extra credit points.

For the extra credit version the program prompts for the number of toothpicks in each stack and then figures out the answer on its own, if there is one. If there is no solution it should print the message "No solution is possible." For this version the only user input is the number of initial toothpicks in the 3 stacks. Running this program would look like:

Grading Rubric

Inside your program itself you must include the following grading rubric, just below your header documentation, as shown below.  We will use this when grading your program as a place to annotate and list any deductions taken off within each category.  Note that this is in your code but is within a comment block so should not appear on the screen when you run your program.  

/* ------------------------------------------------    prog1toothpicks.cpp      Program #1: Toothpicks: Puzzle to equalize the number of toothpicks in three stacks.    Class: CS 141    Author: Dale Reed    Lab: Tues 5am    System:  C++ Mac Xcode     Grading Rubric:     50 Execution points          5 Displays header info on screen when run          5 Displays instructions          5 Output is formatted as shown in sample output          3 Handles both upper and lower case input          5 Input can be adjacent or have spaces between them         15 Makes moves correctly         10 Handles the specified error conditions          2 Gives appropriate end of program messages     45 Programming Style (Given only if program runs substantially correctly)          5 Program naming convention is followed         10 Meaningful identifier names         10 Comments: Has header.  Comments on each block of code         10 Appropriate data and control structures         10 Code Layout: Appropriate indentation and blank lines    ------------------------------------------------ */ 

Additional rubric deduction details are given below.

The 50 points for program execution will be allocated as follows:

The 45 points for program style will be allocated as described below. (While your personal style may disagree with the standards shown, it is important that be able to follow a coding standard that is given to you.)