For this assignment, you will provide implementations for three functions. The first will read a roman numeral from an input stream and write a string containing that numeral into a buffer. The second will take a string representing a roman numeral and return the integer represented by that numeral. The third will take an integer and write a string containing the english representation of that integer into a buffer. Putting these functions together, you will construct a program that reads in roman numerals and prints out the english equaivalent, producing a very limited Latin to English Translator.
This assignment will emphasize meeting a specification. You should not think of the Latin to English Translator as the final product; instead, consider the three functions you write as the programming goal. Since these functions may be used to read the output from another program, or produce text to be used as input for another program, it is important to conform to the specification you are given. Similarly, since any of these functions could be incorporated into another program, it is important not to change the number of parameters, the types of the parameters, or the return value.
Before you can write the first two functions, you need to know what a roman numeral is. If you are not familiar with them, then the Roman Numerals 101 site is a good place to look.
For this assignment, you need only read in roman numerals consisting of the following characters: I, V, X, L, C, D, and M (that is, you will not need to read in characters with bars over them, or lowercase, or alternate forms of letters). Also, while there are sometimes multiple acceptible representations of the same number (four can be represented as IV or IIII) you need only read in the short form (IV). The largest number you will be expected to read in is 9999, or in roman numerals, MMMMMMMMMCMXCIX. The longest number you will be expected to read in is MMMMMMMMMDCCCLXXXVIII, or 9888. The length of this numeral is given by the const int MAX_ROMAN_LEN.
English forms of numbers will conform to the following specifications:
The following list contains the proper spellings of all words you will need (counting hyphenated words as two rather than one): zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty, thirty, fourty, fifty, sixty, seventy, eighty, ninety, hundred, thousand
There are multiple longest strings of english text you will need to generate; one such string is "seven thousand seven hundred seventy-seven". The length of this string is given by the const int MAX_ENGLISH_LEN.
main.cpp
: the driver to test your code
roman.h
: the specifications for
functions on roman numerals
inttoeng.h
: the specification for the
integer to english function
You will provide two files, roman.cpp
which implements
the functions in roman.h
, and inttoeng.cpp
which implements the function in inttoeng.h
.
istream& getRomanNumeral(istream& i, char buf[])
reads
a roman numeral from input stream i
and writes a string containing
that roman numeral into the char array buf
. This function should
i
(unless the valid sequence ends at end of file)
buf
, if one exists
buf
if no valid string of
roman numeral characters exists
buf
if the string is longer than
MAX_ROMAN_LEN
i
after i
has been read
istream::get(char& c)
and
istream::putback(char c)
to implement this function
int romanToInt(const char roman[])
takes a string
containing a roman numeral, and returns an integer. The function should
roman.cpp
.
int intToEnglish(int i, char buf[])
takes an integer
and writes a string containing the english spelling of that number to
the char array buf
. It should
buf
if the integer is
in the range [0, 9999]
inttoeng.cpp
.
roman.cpp
and inttoeng.cpp
. But these
functions should be used only by the file in which they reside. And
you may not redefine the function prototypes we have given you above.
Always make sure to test your program against a variety of inputs! Roman numerals and English text were chosen for this assignment partly because they have some special cases that must be dealt with. Try enough different inputs that you are confident your program behaves correctly on all inputs.
When you're finished writing your solution, you can use the electronic turn-in form to submit it. Follow the instructions on that form (especially with regards to file naming conventions), print the receipt, and submit the receipt at the start of section, Tuesday, July 7th, 1998. For full credit, you must turn in electronically, print the receipt, and hand in that receipt in your section. You may also be able to drop your receipt in the drop box located on the first floor of Sieg hall, across from room 127. More details on this will follow.
If you need help with the lab environment or the online resources, go talk to a consultant in the IPL. I also encourage you to work through Homework 0, designed to get you up to speed on these issues.
If you can't make progress in the actual assignment, please talk to the instructor or a TA. They are available during posted office hours, and sometimes by appointment. They will also occasionally help you out over email. You are invited to seek help from any available TA, not just your own.
You can discuss the assignment in general terms with other students. You
can ask general questions on the student discussion list for this course,
cse143@cs
. But any code you write must be your own.
For more details about what is and is not allowed, see the
Software hygiene page.