Write a function get_Roman_token() based on the following pseudocode: try to rea
ID: 3620468 • Letter: W
Question
Write a function get_Roman_token() based on the followingpseudocode:
try to read a char c1
if it's a period, return 0
first = roman_to_int(c1)
try to read a char c2
if it's a period, put back c2 and return first
second = roman_to_int(c2)
if second > first, return second minus first
put back c2
return first
and a main function which which repeatedly (until end-of-file) asks the user to
enter a Roman number followed by a period, calls get_Roman_token() until it
returns 0, adds up all the values returned, then prints the decimal value.
For example, entering MCMXCIV. should output 1994. Name your program
roman2.cpp.
Explanation / Answer
Dear, Giving you snippets of code based on that frame int roman_to_int(char c) { char roman = c; roman = toupper(roman); if (roman == 'I') return 1; else if(roman == 'V') return 5; else if (roman == 'X') return 10; else if (roman == 'L') return 50; else if (roman == 'C') return 100; else if (roman == 'D') return 500; else if (roman == 'M') return 1000; else { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.