Lab 2

The solution has been posted!

Lab 2 is about breaking a program into functions. We have a small game called "Coin Swap" with all the code written in main(). You are asked to divide up into meaningful functions.

Here is the description of the game.

The playing board starting position is:

     1   2   3   4  5

     X  X       O  O

The object of the game is to swap the X and O pieces, ending up with:

     1   2   3   4  5

     O  O       X  X

X can only move a single square to the right, or jump an O to the right into an open square.  O can only move a single square to the left, or jump an X to the left into an open square.  The ' ' denotes a blank space.

The user is responsible for only making valid moves. You can only make 8 moves to reach the target state. 

Take some time to think about the solution if you want, but not too much time. That is NOT the important part of the lab. The solution is given in the source code file coinSwap.cpp attached below. 

Lab 2 requirement:

Grading policy:  You must finish question 0. The maximum score is 3. Each question of 1, 2, 3 worth 1 point. 

You should raise your hand and show me your work at the last 10 mins of lab, and I will give you grades. Late submission is not accepted.

0. Change the identifying information to display YOUR information

1. Rewrite it using 4 functions, making the program as easy to understand as possible, where the functions meaningfully separate the code. You solution should not use any loops.

    Hint: call those four functions eight times (eight moves).

2. After finishing the above step, add loops to your programs where ever it makes sense to do so.

3. Count the number of moves and display the information.

    Hint: just use printf() inside the loop.

    E.g. When it is the third move, it should print out "Move Step: 3" before you input the two integers for "from" and "to".