Lab 3
Solutions for this lab is now available!
In this lab we will again use the coin swap program, but this time focussing on how to use parameters.
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.
What You Need to Do
Find a partner. The two of you should take turns typing, swapping every 15 minutes or so.
Given the starter code coinswap.cpp (included as a file at the bottom of this page), move all the code from main() into the functions that are described, similar to what was done last lab. All variables must be declared in main() and passed as parameters as needed to the functions.
At the end of lab, one of you should raise your hand and show us your output during the last 10 minutes of lab so we can come by and grade your work. Late submissions are not accepted. Points will be assigned as follows:
0 points: Implement functions displayIdentifyingInformation()
1/2 points: Implement function displayBoard()
1/2 points: Implement function getFromAndToPositions()
1/2 points: Implement function makeMove()
1/2 points: Implement function gameIsOver()
1 point: Implement function moveIsValid()
Function calling examples:
Program functionCalling.c (included at the bottom of this page) has examples of 1. Using a function return type, as well as 2. call-by-value parameters, and 3. call-by-reference parameters.
You should have already read the Zyante background information on call-by-value and call-by-reference at:
https://zybooks.zyante.com/#/zybook/UICCS141Fall2015/chapter/5/section/2
https://zybooks.zyante.com/#/zybook/UICCS141Fall2015/chapter/5/section/9