1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
#include <iostream>
using namespace std;
int RomanNumeralSum(char RomanNumeral);
int RomanToDecimal(char RomanNumeral);
int ArithmeticOp(char Sign);
int GetEquationResults
(char operatorSign, int romanNumeralOne, int romanNumeralTwo);
void PrintResultStatement
(int operatorSign, int romanNumeralOne, int romanNumeralTwo,int romanResults,int results);
void DecimalToRomanNumeral(int num);
void Converter(int num, char ch);
const int VALUE_M = 1000;
const int VALUE_D = 500;
const int VALUE_C = 100;
const int VALUE_L = 50;
const int VALUE_X = 10;
const int VALUE_V = 5;
const int VALUE_I = 1;
void main()
{
char operatorSign = 0;
char romanNum = 0;
char sign = 0;
int romanNumeralOne, romanNumeralTwo, romanResults, decimalResults;
romanNumeralOne = RomanNumeralSum(romanNum);
cout << "The first number is " << romanNumeralOne << endl;
romanNumeralTwo = RomanNumeralSum(romanNum);
cout << "The second number is " << romanNumeralTwo << endl;
operatorSign = ArithmeticOp(sign);
cout << "Arithmetic operation is " << operatorSign << endl;
decimalResults = GetEquationResults
(operatorSign, romanNumeralOne, romanNumeralTwo);
DecimalToRomanNumeral(decimalResults);
PrintResultStatement
(operatorSign, romanNumeralOne, romanNumeralTwo, romanResults, decimalResults);
}
//---------------------------------------------------------------------
void DecimalToRomanNumeral(int num)
{
int results;
int temp;
temp = num / VALUE_M;
Converter(temp, 'M');
temp = num % VALUE_M;
temp = temp / VALUE_D;
Converter(temp, 'D');
temp = temp % VALUE_D;
temp = temp / VALUE_C;
Converter(temp, 'C');
temp = temp % VALUE_C;
temp = temp / VALUE_L;
Converter(temp, 'L');
temp = temp % VALUE_L;
temp = temp / VALUE_X;
Converter(temp, 'X');
temp = temp % VALUE_X;
temp = temp / VALUE_V;
Converter(temp, 'V');
temp = temp % VALUE_V;
temp = temp / VALUE_I;
Converter(temp, 'I');
}
//---------------------------------------------------------------------
void Converter(int num, char ch)
{
int count = 1;
while( count <= num )
{
count++;
}
}
//---------------------------------------------------------------------
// This function compiles the arithmetic operator, roman numerals
// and the equation results and inputs them into a cout statement.
//---------------------------------------------------------------------
void PrintResultStatement
(int operatorSign, int romanNumeralOne, int romanNumeralTwo,int romanResults, int decimalResults)
{
int statement;
if ( operatorSign == '+' )
cout << "The sum of " << romanNumeralOne << " and "
<< romanNumeralTwo << " is " << romanResults << " (" << decimalResults << ")" << endl;
if ( operatorSign == '-' )
cout << "The difference of " << romanNumeralOne << " and "
<< romanNumeralTwo << " is " << romanResults << " (" << decimalResults << ")" << endl;
if ( operatorSign == '*' )
cout << "The product of " << romanNumeralOne << " and "
<< romanNumeralTwo << " is " << romanResults << " (" << decimalResults << ")" << endl;
if ( operatorSign == '/' )
cout << "The quotient of " << romanNumeralOne << " and "
<< romanNumeralTwo << " is " << romanResults << " (" << decimalResults << ")" << endl;
}
//---------------------------------------------------------------------
// This function reads in the the first number, the second number,
// and the arithmetic operator and forms an arithmetic equation.
// The result of that equation is stored and returned to the main
// function.
//---------------------------------------------------------------------
int GetEquationResults
(char operatorSign, int romanNumeralOne, int romanNumeralTwo)
{
int results;
if ( operatorSign == '+' )
results = romanNumeralOne + romanNumeralTwo;
if ( operatorSign == '-' )
results = romanNumeralOne - romanNumeralTwo;
if ( operatorSign == '*' )
results = romanNumeralOne * romanNumeralTwo;
if ( operatorSign == '/' )
results = romanNumeralOne / romanNumeralTwo;
return results;
}
//---------------------------------------------------------------------
// This function reads in the Arithmetic Operator sign and returns
// the sign to another function where it is used in an equation.
//---------------------------------------------------------------------
int ArithmeticOp(char sign)
{
cin.get(sign);
if ( sign == '+' )
return '+';
if ( sign == '-' )
return '-' ;
if ( sign == '*' )
return '*';
if ( sign == '/' )
return '/';
return sign;
}
//---------------------------------------------------------------------
// This function reads in a Roman Numeral and calls for another
// function to convert the value of the Roman Numeral to decimal
// form. The function then adds all values of the Roman characters
// to make a number.
//---------------------------------------------------------------------
int RomanNumeralSum(char RomanNumeral)
{
char romanChar;
int sum = 0;
cin >> romanChar;
while ( !cin.eof() && romanChar != '\n' )
{
sum += RomanToDecimal(romanChar);
cin.get(romanChar);
}
return sum;
}
//---------------------------------------------------------------------
// This function reads the character of the Roman Numeral and returns
// the decimal value of that charater.
//---------------------------------------------------------------------
int RomanToDecimal(char RomanNumeral)
{
char romanChar = RomanNumeral;
if ( romanChar == 'M' )
return VALUE_M;
if ( romanChar == 'D' )
return VALUE_D;
if ( romanChar == 'C' )
return VALUE_C;
if ( romanChar == 'L' )
return VALUE_L;
if ( romanChar == 'X' )
return VALUE_X;
if ( romanChar == 'V' )
return VALUE_V;
if ( romanChar == 'I' )
return VALUE_I;
return 0;
}
|