Homework 3, A multiple base calculator.
Short Description:
Write a calculator that works with numbers in different bases.
This assignment is worth 20 points.
Goals
When you finish this homework, you should:
- Modified an existing program to perform another task.
Formal Description
Write a simple calculator to perform computations on numbers in different bases.
Your program should support the following operations:
- Add two numbers (+)
- Multiply two numbers (*)
- Convert a number from one base to a different base (%)
- Compare two numbers (<, > =)
- Quit (!).
For the following define:
- base: an integer between 2 and 35
- number: a string which contains digits 0-9 and A-Z, digits will be less than the specified base.
You may assume that there will be no errors
To add two numbers
- The input will be in the form of number base + number base = base
- Example: 1100 2 + A 16 = 5
- Read in the the first number and base and convert this to base 10
- read in the +
- read in the second number and base, convert these to base 10
- Perform the operation in base 10
- Convert the sum to the output base
- Print the output number, on a line followed by a newline character.
The same applies to multiply, but multiply instead of add.
For Convert
- The input will be in the form of number base % base
- Convert the input number to base 10
- Convert the base 100 number to the new base
- Output the new number on a line followed by a newline character.
For Comparison
- The input will be in the form number base operator number base
- Where operator will be '<', '>', or '='
- Convert the two numbers to base 10
- Perform the comparison
- Print "TRUE" if the statement is true, or "FALSE" if the statement is false"
For Quit
- the input will be "!"
- Your program should exit.
If the input is
1100 2 + A 16 = 5
1100 2 * A 16 = 5
1100 2 % 12
1100 2 < A 16
1100 2 > A 16
1100 2 = A 16
!
Your output should be.
42
440
10
FALSE
TRUE
FALSE
Discussion
- You should NOT prompt for input
- You must start with the code in single.C.
- You may not modify IntToNum, StringToInt, DigitToChar, CharToDigit. I don't care.
- You are not responsible for errors in the four routines mentioned above, nor are you responsible for input errors.
- You should use functions and a modular design to accomplish this program.
- We will revisit this program on future assignments.
Required Files
The source code in a single file.
Submission
Email your source code file as an attachment to danbennett360@gmail.com. Make sure that the title indicates that this is homework3 and that your name and section are included in the body of the message.