Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write up a detailed solution to the problem: Design a program to convert a Roman numeral to a decimal number. The program should read a

Write up a detailed solution to the problem:

Design a program to convert a Roman numeral to a decimal number. The program should read a Roman numeral. You may read it as a string or one character at a time. Do the conversion and then output the decimal number.

Here are the letters you need to know:

Symbol = Value I = 1 V = 5 X = 10 L = 50 C = 100 D = 500 M = 1,000

1. Code the pseudocode design as written into C++.

2. Develop test data to prove whether or not the design works. You may use the Roman Numeral-Decimal calculator at this website to create your test data http://www.csgnetwork.com/csgromancnv.html (Links to an external site.) Include test data that tests for all the subtractive exception only values ( 4, 9, 40, 90, 400, and 900, which are written as IV, IX, XL, XC, CD, and CM respectively ) as well as the additive cases. Summarize your results - the summary can be very simple. "I coded and tested your design it (does or doesn't work)."

4. Submit the source code, test data that shows if the code works or not, and your summary for the design

If the design does not work :

1. explain what changes you would have to make to the design to make it work

2. incorporate the changes into the pseudocode.

3. code the new design and use your test data to prove it works.

--------------------------------------------------------------------------------------------

Problem

Design a program to convert a Roman numeral to a decimal number. The program should read a Roman numeral. You may read it as a string or one character at a time. Do the conversion and then output the decimal number.

Here are the letters you need to know:

Symbol Value

I 1

V 5

X 10

L 50

C 100

D 500

M 1,000

Design #11

Variables:

string enteredNumerals

char numeral

int value1

int value2

int result = 0

Output a prompt to enter the number in Roman numerals

Read the input into enteredNumerals

Assign the first character in the string to numeral

Use a switch statement to assign the correct integer value to value1 based

on the character that was entered

While a counter (starting at 1) is less than the length of the string

Read the next character into numeral

Use another switch statement to convert the numeral to an integer and

assign it to value2

If value2 is greater than value 1

result = result + (value2 - value1)

end if

else

result = result + value1

if counter is equal to the length of the string - 1

result = result + value2

end if

end else

value1 = value2

increment counter

endwhile

if result = 0

output value1

end if

else

output result

end else

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

How to caculate risk/return use pf debt and real estate equities?

Answered: 1 week ago

Question

Did the team members feel that their work mattered

Answered: 1 week ago

Question

3. What may be the goal of the team?

Answered: 1 week ago