Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program to implement a form of a Roman numeral calculator. We are us

ID: 2901148 • Letter: W

Question

   
   
 Write a C++ program to implement a form of a Roman numeral calculator. We are using the purely additive form of Roman numerals.  By that, we mean that a number is simply the sum of its digits; for example, 4 equals IIII, in our additive notation.  This means that we are NOT using IV for 4. Each Roman numeral must start with the digit of highest value and ends with the digit of smallest value.  That is 9 is VIIII and NOT IIIIV. Your program continually (in a loop) inputs 2 Roman numbers and an arithmetic operator and prints the result of the operation as a Roman number.  The values of the Roman digits (upper case letters only) are as follows:        Roman Digit            Value of Roman Digit            I                         1            V                         5            X                        10            L                        50            C                       100            D                       500            M                      1000  So, the Roman number MMVIIII represents 2009.  The arithmetic operators that your program must recognize in the input are +, -, *, and /. These should perform the C++ integer operations of addition, subtraction, multiplication, and division, respectively. Your program must loop,  processing 2 Roman numbers with an operator, finishing when end of file  is reached.  You do not have to ensure that the input is in purely additive form,  i.e., your program does NOT have to check for this.  You can assume that only positive numbers will be entered as input and  you don't have to check for negative numbers.  If the result is negative, you must print out a minus sign followed  by the absolute value of the result printed as a Roman Numeral. See the sample runs below.  If the result is zero, print the word "zero".  ------------------------------------------------------------------------  The following additional requirements must be followed: A. Your main function must implement the following pseudocode:          read a roman numeral [Hint: use a value returning function]         While Not at the end of file Do            echo first number            read second roman numeral             echo second number            read operator            echo operator            calculate the result            print results            read a roman numeral         End While     You must use ONE function to read a roman numeral.  B. You must correctly implement and use the following functions    in your program (-2 points off per function that is either    not correctly implemented or correctly used):     //---------------------------------------------------------------------    // This function prints, to the standard output and in purely additive    // notation, the Roman numeral corresponding to a natural number.    // If the input value is 0, nothing is printed.    // params: (in)    //---------------------------------------------------------------------    void PrintRomanNumeral ( int val )      //---------------------------------------------------------------------    // This function outputs the result in Roman numeral format to    // the standard output.    // It presumes that the operation is valid and does    // not check for that.    // params: (in, in, in, in)    //---------------------------------------------------------------------    void PrintResult ( int operand1, int operand2,                        int result, char operation )               //---------------------------------------------------------------------    // This function returns the Roman numeral digit corresponding    // to an integer value.    // params: (in)    //---------------------------------------------------------------------    char RomanDigitChar ( int val )      //---------------------------------------------------------------------    // This function returns the integer value of a Roman numeral digit.    // params: (in)    //---------------------------------------------------------------------    int RomanDigitValue(char roman_digit)   C. Functions should be single-minded, performing a     focused task that can be well-named. You should    design pseudocode for each of these functions.    All function bodies, including the body of main,    should be NO more than 30 lines long,    including braces, blank lines and comments.  D. You must NOT use arrays.  You will lose ALL points if     you use arrays.  E. You must follow the programming ground rules.  F. You must follow the formatting of the sample I/O below.  G. You must thoroughly test your program.   H. Hint: use a combination of a sentinel-controlled and end of file    loop to read in a roman numeral.  Ask in class as to what the     sentinel should be.  You must have ONLY one function to read in    a Roman number.  Otherwise you will lose 3 points.  I. To get credit for the assignment, your solution must minimally    work on Test Case # 1 below.  J. (HINT) Have a single function that reads a roman numeral    from the standard input and returns its integer value.     It can use a loop that is a combination of a sentinel-controlled     loop and an end-of-file controlled loop. That is, you must check     for both the end of file and sentinel condition in the loop test     (which condition to check first?). You will have to read characters     from the standard input one at a time using cin.get() until the     sentinel value of ' ' is reached. As you read each character in,     convert it to its integer value using the appropriate function     listed above. Keep a running total of the sum of all the     (integer values) of the roman numerals that you read in and return    this value.   ------------------------------------------------------------------------  Sample I/O Below are two sample runs. They do NOT cover all cases.  Input for Run 1: MCCXXVI LXVIIII + DCX MCI - LXVI CCLXI / MD XXX / LXVIIII XXVIIII *  The output for Test Run 1:   The first number is 1226 The second number is 69 Arithmetic operation is  + The sum of 1226 and 69 is MCCLXXXXV (1295)  The first number is 610 The second number is 1101 Arithmetic operation is  - The difference of 610 and 1101 is -CCCCLXXXXI (-491)  The first number is 66 The second number is 261 Arithmetic operation is  / The quotient of 66 and 261 is zero (0)  The first number is 1500 The second number is 30 Arithmetic operation is  / The quotient of 1500 and 30 is L (50)  The first number is 69 The second number is 29 Arithmetic operation is  * The product of 69 and 29 is MMI (2001)   Input for Test Run 2: CCLXXXVII XVIII * DXXVIIII M - III II + X V - V V - XXXX X + XXXX X *   Output for Run 2:  The first number is 287 The second number is 18 Arithmetic operation is  * The product of 287 and 18 is MMMMMCLXVI (5166)  The first number is 529 The second number is 1000 Arithmetic operation is  - The difference of 529 and 1000 is -CCCCLXXI (-471)  The first number is 3 The second number is 2 Arithmetic operation is  + The sum of 3 and 2 is V (5)  The first number is 10 The second number is 5 Arithmetic operation is  - The difference of 10 and 5 is V (5)  The first number is 5 The second number is 5 Arithmetic operation is  - The difference of 5 and 5 is zero (0)  The first number is 40 The second number is 10 Arithmetic operation is  + The sum of 40 and 10 is L (50)  The first number is 40 The second number is 10 Arithmetic operation is  * The product of 40 and 10 is CCCC (400) 

Explanation / Answer

Sum = ValueOfOne * ICount + ValueOfFive * VCount + ValueOfTen * XCount + ValueOfFifty * LCount + ValueOfOneHundred * CCount + ValueOfFiveHundred * DCount + ValueOfOneThousand * MCount; cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote