The assignment
In this project you will write a program that decodes telephone numbers
that use letters instead of digits. The number for National Car Rental,
for example, is 1-800-CAR-RENT which, when decoded, is 1-800-227-7368.
Now, when you are following behind that crazed driver on the interstate
with the "Don't like my driving? Call 1-800-DRP-DEAD" bumpersticker,
you can type it into your PDA and your C++ decoder will autodial 1-800-373-3323
and you can register your opinion.
This is your first program that not only has commercial potential,
but could be used for the common good (measured in hours saved having
to manually decode telephone numbers like National's).
Project Requirements
- On paper, write a pseudocode algorithm that will translate a
telephone number from digits and letters to all digits. For example,
1-800-drivers will become 1-800-3748377. Notice the digits, dashes,
periods, and parentheses were echoed straight to the output. Your
algorithm should only translate letters and leave all other characters
unchanged. The algorithm also handles both cases of letters.
The algorithm reads a string (you must use the C++ string
class for this project), and then processes it character by
character.
I/O Specification
Enter a symbolic telephone number (c-d to exit): 1-800-Drivers
Symbolic: 1-800-Drivers. Numeric: 1-800-3748377.
Enter a symbolic telephone number (c-d to exit): 1-(the)-program
Symbolic: 1-(the)-program. Numeric: 1-(843)-7764726.
Enter a symbolic telephone number (c-d to exit): bad.WORM
Symbolic: bad.WORM. Numeric: 223.9676
Enter a symbolic telephone number (c-d to exit): 1-541-346-3487
Symbolic: 1-541-346-3487. Numeric equivalent: 1-541-346-3487
Enter a symbolic telephone number (c-d to exit): ^d
Exiting..
Write out a complete algorithm that solves the problem.
Hand trace it thoroughly so you know it is correct.
- Once you have a correct algorithm that solves the problem, then
translate it into a handwritten C++ program. Hand trace it thoroughly
so
you
know
it
is correct.
- Once you have a correct handwritten C++ program that solves
this program, type it into emacs. Name the source file telDecoder.cpp,
and name the executable telDC.
Debugging assistance: When you come to office hours for debugging
assistance, your instructors will ask to see your handwritten algorithm,
program, and trace tables. So please follow this methodology carefully
(it will save you hours of time as you solve projects 6-8).
- Create a Test Set for telDC. When the program is correct, use
Emacs to create an input file, telDC.in, consisting of 10 symbolic
telephone numbers (including each of the 3 symbolic numbers shown
above), one per line. Use I/O redirection to create an output file
with this command:
telDC < telDC.in >! telDC.out
C++ Character-Testing and Related Functions
The header file ctype.h declares the following functions:
isalpha(c) returns true if c is a letter (a-z, A-Z)
isdigit(c) returns true if c is a digit (0-9)
ispunct(c) returns true if c is not a digit, not a letter,
not a space
toupper(c) returns uppercase conversion of c
(just returns c if it's uppercase already)
|