Anne
Dawson: CSCI101A_LAB7_FA04.htm
Last
updated: Monday 8th November 2004, 8:02 PT
This
document is subject to change without notice.
Please
report any errors or omissions in this document:
adawson@coquitlamcollege.com
Special instructions:
For this assignment you may work in teams of 2, or alone. This lab is due at the end of the lab
session.
Fall 2004
Lab
Assignment 7
Step 1
Study the following web page:
http://www.coquitlamcollege.com/adawson/MasterMindRules.htm
Step 2
Play a sample game:
http://www.bfoit.org/Intro_to_Programming/mastermind.html
In your own version of the game, you will use the six numbers:
1,2,3,4,5,6 instead of six colours, and the combination of numbers to be
guessed must not contain duplicates (you may assume that the user of the game
will not enter duplicate numbers in their guesses). You must use a C++ array to
store the 4 number combination, and a C++ array to store the score. The user gets a maximum of ten guesses
to get the correct combination.
Example:
If the combination is:
1234
And the first guess is
2345
The score is 0,3
(Meaning 0 numbers in the correct position, but 3 correct numbers).
An example game:
Hidden correct combination: 2461
(2461)
Guess Score
1234 0 3
4321 1 2
3421 2 1
2431 3 0
2451 3 0
2461 4 0 You win in 6 guesses!
For Bonus points, enforce unique number entry (no duplicates)
and generate a random 4 number sequence to be guessed at the start of each
game. At the end of the game, ask if the user wishes to play again, and repeat
the game on request.
Step 3
Study the algorithm below.
Algorithm:
1. Create a list of
any 4 unique numbers in the range 1 - 6.
2. Ask the user to
input their guess: 4 unique numbers in the range 1 - 6.
3. Check each
inputted number against the hidden combination:
If the guessed number is in the correct position add 1 to a score
counter
If the guessed number is one of the correct numbers but is in an
incorrect
position add 1 to a second score counter.
4. After each guess
add 1 to a guess counter
5. Display the
guess number and score counters
6. If first score counter
has a value of 4, player wins. Game over. Go to step 9.
7. If the guess
counter has a value of 10, player loses. Game over. Go to step 9.
8. If player has
not won or lost,
Set
score counters back to zero.
Go
back to step 2.
9. Output win or lose status and end.
Create your own pseudocode from the given algorithm.
Step 4
Using your pseudocode as a guide, implement your program in the
C++ language. Your program should start with a comment block that contains the
following information:
#
File: lab7.cpp
#
Purpose: The
Mastermind Game
#
Programmer: [your name]
#
Partner: [your
partner's name]
#
Course:
CSCI101A
#
Date: Monday 8th November 2004
Step 5
Test your program by supplying your
own test data. You should test your program with at least 3 sets of test data.
Show your test data and results in comments at the top of your program.
Step 6
At the end of the class, save your
program file (lab7.cpp) to your folder on the network in:
CSCI101A\Week10\Lab07
Program
points will be based on the following marking scheme:
Marking
Scheme: CSCI101A - Lab 7 -
Mastermind Game
Student
name(s):
|
Category |
Points |
Description |
|
Pseudocode |
15 |
A formal description of the
steps that must be taken to solve the problem. |
|
Comments |
10 |
The program is commented appropriately. |
|
Style |
15 |
The source code should use meaningful variable
names (identifiers). |
|
Output |
15 |
Screen prompts and results should be
user-friendly. |
|
Correctness |
15 |
The program should output correct results. |
|
Completeness |
15 |
The program should be complete. |
|
Test |
15 |
Comments in the code explain how the code was
tested. |
|
Bonus Points |
5 |
For Bonus points, enforce
unique number entry (no duplicates) and generate a random 4 number sequence
to be guessed at the start of each game. At the end of the game, ask if the
user wishes to play again, and repeat the game on request. |
Assignment Presentations : In the next class, a random selection
of lab assignment programs will be presented to the CSCI101A group.