I have to create a program that uses a class that adds, subtracts, multiplies, and divides fractions....and then reduces them....I did the program to make sure calculations worked and they did....I just began trying to reduce the fraction but I'm stomped. I have many errors concerning my get and set functions..could someone help please....
header file
#include <iostream>
using namespace std;
class FrAction
{
private:
int num, den, j, k, numer, denom, x, y;
public:
FrAction (int numerator, int denomenator)
{
num= numerator;
den=denomenator;
}
FrAction operator+(FrAction f)
{
FrAction temp(num * f.den + f.num * den, den * f.den);
return temp;
}
FrAction operator-(FrAction f)
{
FrAction temp(num * f.den - f.num * den, den * f.den);
return temp;
}
FrAction operator*(FrAction f)
{
FrAction temp((num * f.num),(den * f.den));
return temp;
}
FrAction operator/(FrAction f)
{
FrAction temp((num * f.den), (f.num * den));
return temp;
}
FrAction reduce()
{
x = getNumerator();
int a;
x = a;
y = getDenominator();
int b;
y = b;
int i;
while (i = (a % b))
{
a = b;
b = i;
}
x /= b;
y /= b;
return(x,y)
}
void setNumerator(int num)
{
numer= num;
}
void setDenominator(int den)
{
denom=den;
}
getNumerator(int numer)
{
return numer;
}
getDenominator(int denom)
{
return denom;
}
void add_display()
{
if (den==1)
cout<<"These fractions added together equals "<<num<<endl;
else
{
cout <<"These fractions added together equals "<<num<<'/'<<den<<endl;
setNumerator(num);
setDenominator (den);
cout<<"This fraction reduced is "<<reduce();
}
}
void sub_display()
{
if (den==1)
cout<<"These fractions added together equals "<<num<<endl;
else
cout<<"These fractions subtracted together equals " <<num <<'/'<<den<<endl;
}
void mult_display()
{
if (den==1)
cout<<"These fractions added together equals "<<num<<endl;
else
cout<<"These fractions multiplied together equals " <<num <<'/'<<den<<endl;
}
void div_display()
{
if (den==1)
cout<<"These fractions added together equals "<<num<<endl;
else
cout<<"These fractions divided together equals " <<num <<'/'<<den<<endl;
}
};
Main file
#include <iostream>
#include "FrAction.h"
int main()
{
int num1, dem1, num2, dem2;
cout<<"Enter the numerator of fraction 1: ";
cin>>num1;
cout<<"Enter the denominator of fraction 1: ";
cin>>dem1;
FrAction fract(num1, dem1);
cout<<"Enter the numerator of fraction 1: ";
cin>>num2;
cout<<"Enter the denominator of fraction 1: ";
cin>>dem2;
FrAction fract2(num2, dem2);
FrAction fract3_add(fract + fract2);
fract3_add.add_display();
FrAction fract3_subtract(fract - fract2);
fract3_subtract.sub_display();
FrAction fract3_mult (fract * fract2);
fract3_mult.mult_display();
FrAction fract3_div(fract / fract2);
fract3_div.div_display();
return 0;
}