Homework 1, Number Games
Short Description:
Write a series of programs that allow the user to work with integers in different representations.
This assignment is worth 100 points.
Goals
When you finish this homework, you should:
- Have reviewed basic C++ and refreshed your programming skills.
- Have reviewed and strengthened your design skills.
- Have reviewed and strengthened your skills with procedures and functions.
- Be able to create, compile and link code stored in multiple files.
- Employ the tools make and tar
Formal Description
Write the following four programs:
- [rosetta] A program which prompts a user for starting integer (low), ending integer (high) and file name. This program produces, in the named file, a table of corresponding integer representations for all formats supported.
- [babbleFish] A program which reads a file, containing integers in a number of different representations and the desired representation to convert to and creates a file containing the converted representation.
- [highLow] A program that prompts the user for a representation, low and high number. The program selects a random number in that range and plays a game of High-Low with the user.
- [quiz] A program which quizzes the user on converting between the given representations.
Each of these programs will be discussed in turn.
Representations
You are to support the following representations in your programs
For each representation, you should support numbers between 1 and 3,999.
Since the ascii system lacks
the ability to display the Mayan characters, we will use the following
system.
Digits
Mayan 'character' | Arabic number |
0 | 0 |
. | 1 |
.. | 2 |
... | 3 |
.... | 4 |
_ | 5 |
._ | 6 |
._ _ | 11 |
Further, we will use the "," to separate digits. Thus
- ".,0" represents 1x201+0x200 = 20
- "._,..." represents 6x201+3x200 = 123
For the American English Short Scale number names, hereafter known as english, we will use the following rules:
- There is a space in the name of 23, twenty three.
- 1,500 is read one thousand five hundred, not fifteen hundred.
Arabic numbers are represented by the standard output format, no commas are needed.
Roman numerals should be represented according to the following rules
- (decreasing order) Numerals are stored in decreasing order, except when employing the subtractive rule. XXVI not XIVX
- (minimal representation) Numerals are stored using the fewest symbols possible. L not XXXXX
- (subtractive) Three symbols (I,X,C) can proceed the next two larger symbols (I before V and X, X before L and C, and C before D and M). When this occurs, it represents subtraction. IX represents 10-1 or 9
A binary representation always begins with a 1. As only positive integers are being represented, only the magnitude of the number needs to be encoded. (do not use sign magnitude or twos compliment)
rosetta
Input
This is a semi-interactive program. It should prompt the for two integers and a string. The integers are in arabic representation.
Please enter the starting (lower) value: 3
Please enter the ending (upper) value: 6
Please enter the output file name: outfile
Output
The output file (outfile) corresponding to the above input should contain:
3 11 three ... III
4 100 four .... IV
5 101 five _ V
6 110 six ._ VI
The output order should be arabic, binary, english, mayan, roman.
babbleFish
Input
This semi-interactive program should prompt the user for an input file name.
The input file will have the following format:
Line 1:outputFileName
Line 2:X Y string
Line N:X Y string
outputFileName is a single string, containing no spaces. This is the name of the output file to be created.
X and Y are single characters. They represent the Input representation and Output representation. They are one of the following (A,B,E,M,R) as associated with
the formats above.
string is a representation string, it can contain spaces.
The following is a very simple example of an input file:
Converted
A B 4
B E 100
E M four
M R ....
R A IV
Output
For each data line in the input file, a single string should be written which
contains the equivalent representation.
The following would be the output file (Converted) associated with the input file:
highLow
Input/Output
This is an interactive program. It should prompt for three values: representation, low and high.
representation is a single character (A,B,E,M,R) which represents the base in which the program will function.
low is the lower bounds for the game, represented in the selected format.
high is the upper bounds for the game, represented in the selected format.
Please Enter a format (A,B,E,M,R): M
Please enter the starting (lower) value: ...
Please enter the ending (upper) value: _ _
Once you have read in the upper and lower values, generate a random number between these values (for example 7).
The program should now go into a loop allowing the user to try to guess the random number, and provide a clue if the guess is too low, too high or just right.
The following is example output:
I am thinking of a number, try to guess it!
Enter your Guess: _
_ is too low!
Enter your Guess: ...._
...._ is too high!
Enter your Guess: .._
.._ is the number, Congratulations!!!
quiz
Input
The quiz program is an interactive program. It will generate numbers in various representations and ask the user to convert to a different representation.
The following is an example run:
Welcome to the Quiz.
Convert XI from Roman to Arabic : 11
11 is correct. Do you want another question? (y,n) : y
Convert 11 from Binary to Arabic : 3
3 is correct. Do you want another question (y,n) : y
Convert ._ from Mayan to Binary : 100
100 is incorrect. Do you want to try again? (y,n) : y
Convert ._ from Mayan to Binary : 110
110 is correct. Do you want another question (y,n) : y
Convert twelve from English to Mayan : ._
._ is incorrect. Do you want to try again? (y,n) : n
Do you want another question (y,n) : n
Thanks for playing the quiz.
Goodby!
Discussion
- You may assume that all user input is correct and error free.
- atoi, isdigit and isblank are a few functions from the isalpha family of functions. You might want to investigate these, and other associated functions.
- srand and rand allow you to generate random numbers.
- Whenever possible, eliminate repeated code by building subroutines. If you find you are repeating code, pull it out and put it into a subroutine.
- You must use multiple files and compile these using the make utility. I will show you how to do this.
- You should probably do a preliminary design on this set of programs.
- You should probably write some experimental code, and then revise your design.
- I would not create a full set of converters. For example, I would not build a Mayan to Binary converter.
- I would convert everything to a single representation. (One that is easy to work with).
- You should create a sub-directory and perform all work for this project within this directory. This will make the creation of the tar file easier.
- If you need help, you should ask.
- Please do not put this work off until the weekend before it is due.
Required Files
You should submit the following in a tar file:
- All source code required to build all programs.
- A makefile which will build all programs as well as clean the directory
- A README describing
- Author identification information
- The project
- Problems encountered
- Any portions of the code which are not working.
- Any unique features of the code.
- Any other information you wish to share.
You should not submit
- Object files or executables.
- Core files.
- Source code files which are not related to the project.
Submission
Please create a tar file containing the files described above. Email this file to dbennett@edinboro.edu by class time of the due date.