#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]); // Open input file on command line.
if(in)
{
out.open(argv[2]); // Open output file on command line.
while(!in.eof())
{
op1.ReadMixedExp(in); // Read first mixed expression.
in >> symbol; // Read the symbol.
op2.ReadMixedExp(in); // Read second mixed expression.
switch(symbol)
{
case '+': res = op1.add(op2);
break;
case '-': res = op1.subtract(op2);
break;
case '*': res = op1.multiply(op2);
break;
case '/': res = op1.divide(op2);
break;
}
op1.printData(out); // Print the first mixed expression.
out << " " << symbol << " "; // Print the symbol.
op2.printData(out); // Print the second mixed expression.
out << " = ";
res.printData(out); // Print the result.
out << endl;
}
// Close the input file.
in.close();
// Close the output file.
out.close();
}
}
return 0;
}
CiNpbmNsdWRlICJNaXhlZEV4cHJlc3Npb24uaCIKI2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGZzdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqYXJndltdKQp7CglNaXhlZEV4cHJlc3Npb24gcmVzOwoJTWl4ZWRFeHByZXNzaW9uIG9wMTsKCU1peGVkRXhwcmVzc2lvbiBvcDI7IAoJY2hhciBzeW1ib2w7Cglsb25nIHgseTsKCWlmc3RyZWFtIGluOwoJb2ZzdHJlYW0gb3V0OwoKICAJaWYoYXJnYyA+IDEpCgl7CgkJaW4ub3Blbihhcmd2WzFdKTsgLy8gT3BlbiBpbnB1dCBmaWxlIG9uIGNvbW1hbmQgbGluZS4KCQlpZihpbikKCQl7CgkJCW91dC5vcGVuKGFyZ3ZbMl0pOyAvLyBPcGVuIG91dHB1dCBmaWxlIG9uIGNvbW1hbmQgbGluZS4KCQkJd2hpbGUoIWluLmVvZigpKQoJCQl7CSAKCQkJCW9wMS5SZWFkTWl4ZWRFeH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