This is the code for a fractions program that is to add and subtract(i know it does not subtract yet)
I am having error messages that I dont understand.
// File Fraction.h
#ifndef FRACTION_H
#define hbg_cmpsc122
#include <iostream>
using namespace std;
namespace hbg_cmpsc122
{
class Fraction
{
private:
int num;
int denom;
public:
Fraction();
Fraction(int n, int d);
int setNum(int n);
int setDenom(int d);
void print();
Fraction add_func (Fraction a);
Fraction sub_func (Fraction b);
};
}
#endif
// File fraction.cxx
#include "fraction.h"
#include <iostream>
#include <cstdlib>
#include <cassert>
using namespace std;
namespace hbg_cmpsc122
{
Fraction::Fraction()
{
num = 0;
denom = 1;
}
Fraction::Fraction(int n, int d)
{
num = n;
denom = d;
}
int Fraction::setNum(int )
{
return num;
}
int Fraction::setDenom(int )
{
return denom;
}
void Fraction::print()
{
// displays fraction on screen
cout << "Fraction: " << num << "/" << denom << endl;
}
Fraction Fraction::add_func(Fraction a)
{
Fraction answer;
if (a.denom =! a.setDenom())
{
answer.denom = a.denom * a.setDenom() + (a.setNum() * a.denom);
answer.num = (a.num * a.setNum())+(a.setNum() * a.denom);
a.denom = answer.denom;
a.num = answer.num;
}
else
{
answer.denom = a.denom;
answer.num = a.num + a.setNum();
}
return answer;
}
}
// File Main.cpp
#include <iostream>
#include <cstdlib>
#include "fraction.h"
using namespace std;
using hbg_cmpsc122::Fractions;
int main()
{
fraction f1(3,2), f2(4,5), f3, f4;
cout <<endl << "Fraction f1 is: ";
f1.print();
cout <<endl << "Fraction f2 is: ";
f2.print();
f3 = f1.add_func(f2);
cout << endl << endl << "The sum of the fractions is ";
f3.print;
return 0;
}
This is the code for a fractions program that is to add and subtract.
I am having error messages that I dont understand.
fraction.cxx: In member function `<unnamed>::Fraction <unnamed>::Fraction::add_func(<unnamed>::Fraction)':
fraction.cxx:40: error: `((<unnamed>::Fraction*)this)-><unnamed>::Fraction::denom' cannot be used as a function
fraction.cxx:42: error: no matching function for call to `<unnamed>::Fraction::setDenom()'
fraction.h:25: note: candidates are: int <unnamed>::Fraction::setDenom(int)
fraction.cxx:42: error: no matching function for call to `<unnamed>::Fraction::setNum()'
fraction.h:24: note: candidates are: int <unnamed>::Fraction::setNum(int)
fraction.cxx:43: error: no matching function for call to `<unnamed>::Fraction::setNum()'
fraction.h:24: note: candidates are: int <unnamed>::Fraction::setNum(int)
fraction.cxx:43: error: no matching function for call to `<unnamed>::Fraction::setNum()'
fraction.h:24: note: candidates are: int <unnamed>::Fraction::setNum(int)
fraction.cxx:50: error: no matching function for call to `<unnamed>::Fraction::setNum()'