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: 3641243 • 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 opertor, 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 adhere to the normal end of file loops, e.g.          --- 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  B. The above pseudocode suggests some functions.      Keep these functions single-minded, performing a     focused task that can be well-named.   C. You must NOT use arrays.  You will lose all points if     you use arrays.  D. You must follow the formatting of the sample I/O below.  E. Hint: use a combination of a sentinel-controlled and end of file    loop to read in a roman numeral.  You must have ONLY one function to read in    a Roman number.  Otherwise you will lose 5 points.  F. To get credit for the assignment, your solution must minimally    work on Test Case # 1 below.  ------------------------------------------------------------------------  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:  MCCXXVI The first number is 1226 LXVIIII The second number is 69 + Arithmetic operation is + The sum of 1226 and 69 is MCCLXXXXV (1295)  DCX The first number is 610 MCI The second number is 1101 - Arithmetic operation is - The difference of 610 and 1101 is -CCCCLXXXXI (-491)  LXVI The first number is 66 CCLXI The second number is 261 / Arithmetic operation is / The quotient of 66 and 261 is zero (0)  MD The first number is 1500 XXX The second number is 30 / Arithmetic operation is / The quotient of 1500 and 30 is L (50)  LXVIIII The first number is 69 XXVIIII The second number is 29 * Arithmetic operation is * The product of 69 and 29 is MMI (2001) 

Explanation / Answer

#include #include #include using namespace std; //Roman numeral to decimal int RomToDec(string rom) { int num = 0; for(int i = 0; i = 1000) { rom += "M"; dec-=1000; } while(dec >= 500) { rom += "D"; dec-=500; } while(dec >= 100) { rom += "C"; dec-=100; } while(dec >= 50) { rom += "L"; dec-=50; } while(dec >= 10) { rom += "X"; dec-=10; } while(dec >= 5) { rom += "V"; dec-=5; } while(dec >= 1) { rom += "I"; dec-=1; } return rom; } int operate(char arith, int a, int b) { if(arith == '+') return a+b; if(arith == '-') return a-b; if(arith == '*') return a*b; if(arith == '/') return a/b; } using namespace std; int main() { //The variables we will read in string r1, r2; char arith; //Open the file ifstream file("roman.txt"); while(!file.eof()) { file >> r1; 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