Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using a text editor, create a data file containing at least 7 Roman numeral numbers. Save the data file with the name roman.txt. Use the

Using a text editor, create a data file containing at least 7 Roman numeral numbers. Save the data file with the name roman.txt. Use the following numbers to create your data file:

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 base 10 decimal form (an integer) and then prints the result. Your program must contain the following features:

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 varl = '#';

var = toupper(var);

cout

varl = toupper( varl); //

displays uppercase A and var now contains uppercase A

// since it is not an alphabetic character, it is ignored.

b. Read the file until it is empty.

h) Validate the character read from the input file to verify it is part of the Roman numeral set. If not, write the error message: \"Invalid character in input file \"

c) 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.

d) Roman numeral numbers are converted to decimal according to the criteria Rules to evaluate numbers in Roman numeral form which is below. You will need 3 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.

e) If the Roman numeral is not formed correctly, your program should skip the remaining characters and proceed to the next record in the file.

f) Global variables should not 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 the error message \"*** 2 the same and the next bigger *** \" 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 the error message \"Two subtractions in a row have occurred \"; and ignore the rest of the number.

Walk through the algorithm using the above test data to determine the correct output. This process will assist you in writing the program.

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

understand the restrictions of top-down job redesign approaches;

Answered: 1 week ago

Question

Propose a reasonable mechanism for the following reaction. OH

Answered: 1 week ago