Hello everyone, Im writing a fraction program that will do some nifty stuff. To cut to the chase, here are my 3 files but Im having trouble compiling the test function, i keep getting a "no match for 'operator+'" error. Thanks for all and any help!
fraction.h
Code:
#ifndef Fraction
#define Fraction
class mixedfraction
{
public:
mixedfraction();
void read();
void display();
double evaluate();
mixedfraction add (mixedfraction, mixedfraction);
mixedfraction sub (mixedfraction);
mixedfraction mul (mixedfraction);
mixedfraction div (mixedfraction);
int whole;
int numerator;
int denominator;
};
#endif
fraction.cpp
Code:
#include <iostream>
#include <cmath>
#include "mixedfraction.h"
using namespace std;
mixedfraction::mixedfraction()
{
whole=0;
numerator=0;
denominator=1;
}
void mixedfraction::read()
{
cout << "Please enter whole number: " <<endl;
cin >> whole;
cout << "Please enter numerator: " <<endl;
cin >> numerator;
cout << "Please enter denominator: " <<endl;
cin >> denominator;
}
void mixedfraction::display()
{
cout << whole << numerator <<"/" << denominator << endl;
}
double mixedfraction::evaluate()
{
double temp;
temp = (double) whole + (double) numerator / (double) denominator;
return temp;
}
mixedfraction add (mixedfraction f1, mixedfraction f2)
{
mixedfraction sum;
sum.numerator = f1.numerator*f2.denominator + f2.numerator*f1.denominator;
sum.denominator = f1.denominator*f2.denominator;
return sum;
}
test.cpp
Code:
#include <iostream>
#include <cmath>
#include "mixedfraction.h"
using namespace std;
int main()
{
mixedfraction x,y,z;
double i;
x.read();
x.display();
i = x.evaluate();
cout << i << endl;
y.read();
y.display();
z= x+y;
cout << "The sum of ";
x.display();
cout << "and";
y.display();
cout << "is";
z.display();
}