I need to write a code that perfoms all the main operations (+ - * /) on inputed fractions. I need to do this using a class. I can't get it to run. This is the code I have so far.
#include <iostream>
#include "fraction.h"
usingnamespace std;
int main ()
{
fraction f1, f2, fresult;
f1.inputFrac(); //input the first fraction
f2.inputFrac(); //input the second fraction
cout << "The result of a * b is: ";
fresult = f1.fracMult(f2); // calculate a * b
fresult.printFrac(); // print out the result
cout << "The result of a / b is: ";
fresult = f1.fracDiv(f2); // calculate a / b
fresult.printFrac();
cout << endl;
cout << "The result of a + b is: ";
fresult = f1.fracAdd(f2); // calculate a + b
fresult.printFrac();
cout << endl;
cout << "The result of a - b is: ";
fresult = f1.fracSub(f2); // calculate a - b
fresult.printFrac();
cout << endl;
return 0;
}
'bool fraction::positive' is private (fraction.h--line 9)
'int fraction::denom' is private (fraction.h--line 8)
'int fraction::numerator' is private (fraction.h--line 7)
within this context (fraction.cpp-- line 82, 85, 92, 96)
The error message says quite clearly. You're trying to access private members from a non-method to the class. If you want to access those members, write an interface or make them public.