#include "MixedExpression.h"
#include<iostream>
#include<fstream>
using namespace std;
int main(int argc, char *argv[])
{
MixedExpression res;
MixedExpression op1;
MixedExpression op2;
char symbol;
long x,y;
ifstream in;
ofstream out;
if(argc > 1)
{
in.open(argv[1]);
if(in)
{
out.open(argv[2]);
while(!in.eof())
{
op1.ReadMixedExp(in);
in >> symbol;
op2.ReadMixedExp(in);
switch(symbol)
{
case '+': res = op1.add(op2); // Get the sum.
break;
case '-': res = op1.subtract(op2); // Get the difference.
break;
case '*': res = op1.multiply(op2); // Get the product.
break;
case '/': res = op1.divide(op2); // Get the quotient.
break;
}
op1.printData(out);
out << " " << symbol << " ";
op2.printData(out);
out << " = ";
res.printData(out);
out << endl;
}
// Close the input file.
in.close();
// Close the output file.
out.close();
}
}
return 0;
}
I2luY2x1ZGUgIk1peGVkRXhwcmVzc2lvbi5oIgojaW5jbHVkZTxpb3N0cmVhbT4KI2luY2x1ZGU8ZnN0cmVhbT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pCnsKCU1peGVkRXhwcmVzc2lvbiByZXM7CglNaXhlZEV4cHJlc3Npb24gb3AxOwoJTWl4ZWRFeHByZXNzaW9uIG9wMjsKCWNoYXIgc3ltYm9sOwoJbG9uZyB4LHk7CglpZnN0cmVhbSBpbjsKCW9mc3RyZWFtIG91dDsKCiAgCWlmKGFyZ2MgPiAxKQoJewoJCWluLm9wZW4oYXJndlsxXSk7CgkJaWYoaW4pCgkJewoJCQlvdXQub3Blbihhcmd2WzJdKTsKCQkJd2hpbGUoIWluLmVvZigpKQoJCQl7CgkJCQlvcDEuUmVhZE1peGVkRXhwKGluKTsKCQkJCWluID4+IHN5bWJvbDsKCQkJCW9wMi5SZWFkTWl4ZWRFeHAoaW4pOwoJCQkJc3dpdGNoKHN5bWJvbCkgICAKCQkJCXsKCQkJCQljYXNlICcrJzogcmVzID0gb3AxLmFkZChvcDIpOyAvLyBHZXQgdGhlIH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