Issues with Constructor

I have the code below to run several basic calculations and then output the results in the main function. However, the program compiles but doesn't return correct results. and will stop running after the call to the "display" function. I think that's causing it is the way I'm calling the functions in the Fraction Class but I don't know how us to do it.

#include <iostream>
#include <iomanip>

using namespace std;

class Fraction
{

public:



Fraction()
{


}// Constructor


int multiply(int numer, int denom)
{
int theProduct = numer*denom;
return theProduct;
}

int divide(int numer, int denom)
{
int theResult = numer/denom;
return theResult;
}

int add(int numer, int denom)
{
int theResult = numer+denom;
return theResult;
}

int subtract(int numer, int denom)
{
int theResult = numer-denom;
return theResult;
}


int isEqual(int numer, int denom)
{
if(numer == denom)
return true;
else
return false;
}

string display(int numer, int denom)
{
string theResult = numer+","+denom;
return theResult;
}


};


int main(int argc, const char * argv[])
{

int first=0;
int second=0;


cout<<"Enter the 1st number"<<endl;
cin>>first;
cout<<"Enter the 2nd number"<<endl;
cin>>second;


cout<<"Display Input Values:\n";
cout<<Fraction().display(first,second);


cout<<"Equal?:";
cout<<Fraction().isEqual(first,second);


cout<<"\nMultiplied:";
cout<<Fraction().multiply(first,second);


cout<<"\nDivided:";
cout<<Fraction().divide(first,second);


cout<<"\nSum:";
cout<<Fraction().add(first,second);


cout<<"\nDifference:";
cout<<Fraction().subtract(first,second);


return 0;
}


numer+","+denom;

This appears top be an attempt to add an int (numer) to a char pointer and then to another int (denom). Adding int to char-pointer is pointer arithmetic. I doubt that's what you intended.
Last edited on
Topic archived. No new replies allowed.