Question
I don't know where to go from what I have could somebody explain what I need to do to get the code working the way
I don't know where to go from what I have could somebody explain what I need to do to get the code working the way it should.
If you could explain with comments that would be great.
Make any changes to my code that you need and please explain why
Thank you in advance
My Code Below:
#include
bool isValidDecimalNumber(string s); bool isValidRomanNumber(string s); string convertRomanToDecimal(string s); string convertDecimalToRoman(string s);
int value(char r) { if (r == 'I'); return 1; if (r == 'V') return 5; if (r == 'X') return 10; if (r == 'L') return 50; if (r == 'C') return 100; if (r == 'D') return 500; if (r == 'M') return 1000;
return -1; }
int main() { cout
while (true) { cout > input;
if (input == "0") cout
bool isValidDecimalNumber(string s) { // check if the string represents a valid decimal number for (int i = 0; i
bool isValidRomanNumber(string s) { for (int r = 0; r
switch (s[r]) { case 1: 'I'; break; case 2: 'V'; break; case 3: 'X'; break; case 4: 'L'; break; case 5: 'C'; break; case 6: 'D'; break; case 7: 'M'; break; default: return false; } } }
Assignment Below
HOMEWORK - ROMAN NUMBERS Design a program that converts between Roman Numbers and decimal numbers, then implement that design in C++. See the textbook: Programming Exercises P3.6, P4.12, and P4.13 as references. Our specifications for Roman Numbers is on the next page. Your program should: Display a friendly greeting to the user. Prompt the user for a string (either a decimal number or a Roman number) Accept that string. If the value entered is the digit 0 or the letter O, state the number of values converted and exit the program. Test the string to ensure that it adheres to the required format of either decimal or Roman. If the string does not adhere to an appropriate format, display a message (input error) and continue to process entries. Convert the input string to the desired output string by invoking a function. Display the appropriately-formatted output. Display the prompt again. Your program must include these four functions, with these prototypes: bool isvalidDecimalnumber (string s); bool isvalidRomanNumber (string s); string convertRomanToDecimal (string s); string convertDecimaltoRoman(string s); You may make use of any other helper functions (such as the one recommended in P4.12) as you see fit. Note: Roman Numbers can be entered in upper and/or lower case. Sample Run (user input in bold): Welcome to Roman Number Conversion! Please enter a value to convert: MCMLXXVII MCMLXXVII ( Roman) =1977 (Decimal) Please enter a value to convert: 1977 1977 (Decimal) is MCMLXXVII (Roman) Please enter a value to convert: HELLo I did not understand input HELLO Please enter a value to convert: 0 2 numbers were converted (1 Decimal to Roman, 1 Roman to Decimal) Thank You for playing Roman Number Conversion! HOW TO PARSE ROMAN NUMBERS There is no "standard" set of rules for parsing Roman Numbers, so we will establish our own. The only symbols we will allow are M (1000), D (500), C (100), L (50), X (10), V (5), and I (1). Note that we accept both upper and lower case. - Set the accumulator to zero. - Parse from left to right. - If the symbol you see is followed by a symbol of equal or lesser value - Consume that symbol and add that value to the accumulator - If the symbol you see is followed by a symbol of greater value - Consume both symbols and add their difference to the accumulator - Continue until the string has been consumed. If any value produced is greater than the preceding value, the Roman Number is invalid. MCMLXXVII =1977 M is followed by a lesser value, so consume M and add 1000 to the accumulator. C is followed by the greater value M, so consume CM and add 900 to the accumulator. L is followed by a lesser value, so consume L and add 50 to the accumulator. X is followed by an equal value, so consume X and add 10 to the accumulator. X is followed by a lesser value, so consume X and add 10 to the accumulator. V is followed by a lesser value, so consume V and add 5 to the accumulator. I is followed by an equal value, so consume I and add 1 to the accumulator. I is the final token; consume I and add 1 to the accumulator. MIMXCIX =2098 M is followed by a lesser value, so consume M and add 1000 to the accumulator. I is followed by the larger value M, so consume both and add 999 to the accumulator X is followed by the larger value C, so consume both and add 90 to the accumulator I is followed by the larger value X, so consume both and add 9 to the accumulator IIM = ???? I is followed by the same value, so consume it and add 1 to the accumulator. I is followed by M, so consume both for 999 , but that's greater than the previous value. Note that in some interpretations this is valid and produces 998 , but not by our rules. In fact, one way to say "998" in Latin translates as "two from a thousand." IIIIIIIIIIIIIIIIIIIIIIIII = 23 We do not limit the number of times a symbol may be repeated. This sequence of twenty-three I actually does appear on an ancient Roman monument
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started