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
|
#include <fstream>
using namespace std;
int get_Data(ifstream& input, ofstream& output, char numin);
int convert_from_Roman_to_Decimal(char numin);
char get_Oper(ifstream& input, int& stop);
void calc_Romans(int num1, int num2, char oper, int& result);
void print_Roman_Result(int result, ofstream& output);
int main()
{
ifstream input;
ofstream output;
char numin, oper;
int num1 = 0, num2 = 0, result = 0, stop = 0;
input.open("mp4romanletr-data.txt");
output.open("outfile.txt");
while(stop != 1)
{
output << "The first number is ";
num1 = get_Data(input, output, numin);
output << " ( " << num1 << " )" << endl;
output << "The second number is ";
num2 = get_Data(input, output, numin);
output << " ( " << num2 << " )" << endl;
output << "The operator is ";
oper = get_Oper(input, stop);
output << oper << endl;
calc_Romans(num1, num2, oper, result);
output << "The result is ";
print_Roman_Result(result, output);
output << " ( " << result << " )" << endl;
}
input.close();
output.close();
return 0;
}
int get_Data(ifstream& input, ofstream& output, char numin)
{
int x, y = 0;
x = 0;
input.get(numin);
while (y < 1)
{
if (numin == ' ')
{
input.get(numin);
}
else y++;
}
while(numin != ' ')
{
output << numin;
x = x + convert_from_Roman_to_Decimal(numin);
input.get(numin);
}
return x;
}
char get_Oper(ifstream& input, int& stop)
{
char oper;
int y = 0;
input.get(oper);
while (y < 1)
{
if (oper == ' ')
{
input.get(oper);
}
else y++;
}
if (input.eof())
stop++;
return oper;
}
|