Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need Help understanding and solving this problem. I am hoping that someone can help me Understand the steps and not just solve the problem. Please

Need Help understanding and solving this problem. I am hoping that someone can help me Understand the steps and not just solve the problem. Please use comments to explain what is being done and how the code works as I am lost!

1.Using the Visual C++ text editor, create a data file containing at least 7 Roman numeral numbers. Use the data file called to test your program.

LXXXVII

cCxiX

MCCCLIV

CXXXLL

MMDCLXXIII

DXLCC

MCdLxxvI

XZ

X

IV

Note that character values for Roman numerals are:

M = 1000 D = 500 C = 100 L = 50 X = 10 V = 5 I = 1

2.Write a C++ program, which converts each Roman numeral number to Arabic form (an integer) and then prints the result. Your program must contain the following features:

a.Read in one character at a time using the get method.

b.Code to convert the character read from the file into an uppercase letter. This is accomplished by utilizing the header files cctype and cstdlib with the function call toupper. Example of usage:

char var = a;

char var1 = #;

var = toupper(var);

cout << var << endl; // displays upper case A and var now contains upper case A

var1 = toupper(var1); // since not alphabetic character, it is ignored.

c.Each line in the file will contain a Roman numeral to convert.

d.Validate the character read from the input file to verify it is part of the Roman numeral set.

e.Print the character of the file as soon as it is read from the file; however, do not print the rest of the characters if the Roman numeral is malformed. A malformed number would be as follows:

I.Invalid character

II.Does not follow the rules to evaluate Roman numerals on the next page.

f.When the end of the Roman numeral is reached (can be detected by testing for the newline character, you should output the conversion otherwise if it is malformed, output an error message.

g.Roman numeral numbers converted to decimal according to the criteria Rules to evaluate numbers in Roman numeral form which follows at the bottom of the page. You will need 3 integer variables to implement the algorithm below.

The first variable should be called value, which represents the value of the numeral just read from the file, the second variable should be called oldval, which represents the value of the previous numeral, and the third variable should be called oldestval, which represents the value of the numeral read before oldval.

h.If the Roman numeral is not formed correctly, your program should output an error message and skip the remaining characters in the current record (line) and proceed to the next record in the file for processing.

i.Global variables cannot be used. Global constants are allowed.

RULES TO EVALUATE NUMBERS IN ROMAN NUMERAL FORM

1.As each character is read, its value is added to the total.

2.If 2 Roman numerals in a row are the same, it is an error if the next numeral has a larger value. Write an error message and ignore the rest of the number.

3.If the value of a numeral is larger than the value of the previous numeral, the previous value is subtracted twice from the sum.

4.If two subtractions occur in a row, an error has occurred. Write an error message and ignore the rest of the number.

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books