Question: Level 1: Units-only numbers Begin by writing a program that converts a single Roman number in the range I (1) to IX (9) to Arabic

Level 1: Units-only numbers Begin by writing a program that converts a single Roman number in the range I (1) to IX (9) to Arabic form. The program should read a single string from standard input and print the corresponding value on standard output. Hint: Use an array of strings to represent the Roman units digits, organised so that the string index corresponds to the digit value. For example, the array would have the string IV at index position 4, and the string VII at index position 7. Then convert the input string by searching through the array until you find a match. The index where you find the match will be the digit value you need. Note that for reasons explained below, it's easiest to begin at the "9" end of the array and work downwards. Extend the program so that it works correctly when the input consists of either lower case or upper case Roman letters. The simplest approach is to convert each character in the input word into uppercase before trying to find a match. Run a loop over the characters in the string, using the index operator ([]) to access each character and the toupper function (you'll need to include the cctype header file) to get the uppercase value.
: Unitsonly numbers
Read a single string from standard input : cin
The input consists of either lower case or upper case Roman letters : toupper
Include the cctype header file Working from the "9" down to the "1" end : Why?
Level 2: Multiple numbers Extend the program so that it can deal with single-digit numbers of any value. A single-digit number is one that consists only of thousands, hundreds, tens, or units. Thus LXX (70) and CD (400) are single-digit numbers, but XIV (14) and MC (1100) are not. Use the same approach as for units digits, but with 4 different arrays, one each for the thousands, hundreds, tens, and units digits. Try looking for thousands digits first, then for hundreds, and so on. When you find a match in one of the arrays, print the corresponding value and stop. Extend the program so that it reads and converts all input numbers until end of file on standard input. You'll probably be able to do this simply by adding an appropriate "reading loop" around the code that reads a single line.
need 4 arrays
Multiple numbers
Same approach as level 1
Need a Loop to read multiple inputs : while ( cin ){}
Level 3: Multi-digit numbers Extend the program so that it can handle multi-digit numbers. The idea is to look for prefixes of the Roman number that correspond to valid Roman digits, beginning with the thousands digits and working from the "9" down to the "1" end. If you find a matching prefix, remove it and add the corresponding value to a progressive total, then move on to the next digit position. Since each digit is unique (and since larger digits are represented by longer strings than smaller ones), this process will always find the correct value. When youve considered all possible digits, the progressive total is the answer you need. Make sure the program behaves correctly even if the input does not consist of a valid Roman number. Simply convert the longest valid prefix and ignore any remaining characters. If no prefix characters are valid, display zero.
Multidigit numbers
Look for prefixes of the Roman number that correspond to valid Roman digits : find()
Beginning with the thousands digits and working from the "9" down to the "1" end : Why?
Convert the longest valid prefix and ignore any remaining characters. If no prefix characters are valid, display zero. For example:
error = 0
MMXerror =2010
XXXerrorIV = 30
CCCCC =300
Level 4: Convert either way Extend the program so that if the input is an Arabic number, the output is the corresponding Roman number. Use the first character in the input word to decide which way to convert. If it's an Arabic digit, convert as much as possible of the word to Roman. If it's a Roman digit letter, convert as much as possible to Arabic. (If it's neither, then output zero.) Use the same digit arrays to convert both to and from Roman numbers.
Convert either way
Use the first character in the input word to decide which way to convert
Arabic digit : isdigit()
Roman digit letter : find_first_of("MDCLXVI")
If it's neither, then output zero. Arabic to Roman
Using % and / to separate each digit as index.
Using lookup table to find the Roman numbers.
please use C++ to answer the assignment
How would life be different if the Roman Empire was still alive in the computer age? For a start, computer programs would have to deal with input and output of numbers specified using a rather different scheme than the Arabic system we currently use. Your task is to write a C++ program, roman, that reads numbers specified in Roman form, then writes the numbers translated into Arabic. The program should read from standard input and write to standard output. Input will consist of series of lines each containing a number to be converted. For each input line, the program shoul write a line of output that consists of the converted number terminated with a newline. Th program should continuously read input and write output until all input is processed Automatic Testing This task is available for automatic testing using the name roman. You can run the demo using demo roman and you can test your work using try roman > When you'r ready to submit your work, use handin roman >. If your source code consists o more than one file, you'll need to submit a zip file. Background Like the familiar Arabic scheme, Roman numbers are written in decimal form; a Roman numbe contains thousands, hundreds, tens, and units "digits". However, Roman numbers use strings o letters to represent each digit, with different letters used for the thousands, hundreds, tens, and unit digits. Moreover, although Roman numbers are always written so that the thousands digit come first and the units digit last, there is no way to write "zero", you simply leave the digit out. Roman digits are written using the following letters, with each letter standing for a certain value M or m one thousand D or d five hundred Lor l: fifty V or v five C or c one hundred Xorx: ten To represent digit values other than those above, digit letters are repeated; as a special case, digits and 9 (and their corresponding higher place values) are written by prefixing the "S" and "10" letter with the "I" letter. The following table lists all valid Roman digits; note that the highest valii Roman number using this scheme is 3999 (MMMCMXCIX). thousands hundreds units ccC VI Vil LX DCC XC IX
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
