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:

Formal Description

Write the following four programs:
  1. [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.
  2. [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.
  3. [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.
  4. [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 For the American English Short Scale number names, hereafter known as english, we will use the following rules: Arabic numbers are represented by the standard output format, no commas are needed.

Roman numerals should be represented according to the following rules

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:

100
four
....
IV
4

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

Required Files

You should submit the following in a tar file: You should not submit

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.