Here is the website for the assignment I am working on:
http://view.samurajdata.se/rsc/5c1dd0b4/

Here is the website for my header file (MixedExpression.h):
http://ideone.com/oJ6mI8

Here is the website for my library source file (MixedExpression.cpp):
http://ideone.com/RSrshS

Here is the website for my calculator client file (Calculator.cpp):
http://ideone.com/U5F2O8

My question: I got the code in the header file correct. In the library source file, I got the default constructor, GCD(), and printData() functions correct. I am not sure if I got the reduce() and ReadMixedExp() functions correct. I am mostly having trouble with the normal constructor because my teacher wants me to reduce the expression in that which I can't figure out. I am also not sure if I am doing the calculations correctly. In the calculator client file, I don't know if I am using the switch statement correctly. Right now, all I am getting is this output: (0 + 0/1), which is going on in an infinite loop. What do I need to fix, add, or change?

Here is my updated source code for the calculator file if this is better:

#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())
            {
                res.ReadMixedExp(in);
                if(symbol == '+')
                {
                    res = op1.add(op2); // Get the sum.
                }
                else if(symbol == '-')
                {
                    res = op1.subtract(op2); // Get the difference.
                }
                else if(symbol == '*')
                {
                    res = op1.multiply(op2); // Get the product.
                }
                else if(symbol == '/')
                {
                    res = op1.divide(op2); // Get the quotient.
                }
                res.printData(out);
            }
        }
        // Close the input file.
        in.close();
        // Close the output file.
        out.close();
    }    
    return 0;
}

I got rid of the switch statement and used if-elseif statements, but I am still getting the infinite loop. Is there something else that needs to be changed?

Believe you misunderstood Ddanbe's point, I am afraid. The issue he was pointing out was not the use of the switch() statement; that was fine. The problem is that the variable you are testing, symbol, is never getting set to a usable value. You need to read in symbol after reading in the op1 (not res, as yo currently have it, BTW). So, going back to your original code, it would look like this:

    while(!in.eof())
    {
        op1.ReadMixedExp(in); 
        in >> symbol;

        switch(symbol)
        { //.. etc.
Comments
This question has already been answered. Start a new discussion instead.