We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,612 Members — Technology Publication meets Social Media

Need help with fraction calculator

By blamp on Nov 9th, 2009 1:16 am

I have add the two functions the add and subtract I have to now add the multiply and divsion functions can someone help

[code]
#include<iostream>
using namespace std;

class fractions
{
public:
fractions fractions :: operator+(fractions f);
fractions subFraction(fractions);
fractions();
fractions(int, int);
void printFraction();
private:
int numerator;
int denominator;
};

{
fractions temp;
temp.denominator = denominator * f.denominator;
temp.numerator = numerator * f.denominator + denominator * f.numerator;
return temp;
}
//method to subtract two fractions
fractions fractions :: subFraction(fractions f)
{
fractions temp;
temp.denominator = denominator * f.denominator;
temp.numerator = numerator * f.denominator - denominator * f.numerator;
return temp;
}

fractions fractions :: operator+(fractions f)
{
fractions temp;
temp.denominator = denominator * f.denominator;
temp.numerator = numerator * f.denominator + denominator * f.numerator;
return temp;
}
//method to subtract two fractions
fractions fractions :: operator+(fractions f)
{
fractions temp;
temp.denominator = denominator * f.denominator;
temp.numerator = numerator * f.denominator - denominator * f.numerator;
return temp;
}

fractions::fractions()
{
numerator = 0;
denominator = 1;
}

fractions::fractions(int n, int d)
{
numerator = n;
denominator = d;
}

void fractions::printFraction()
{
cout <<numerator<<'/'<<denominator<<endl;
}

void getFraction(int &numerator, int &denominator)
{
cin >>numerator;
cin >>denominator;
}

int main()
{
int n,d;
fractions f1(1,2);
fractions f2(3,4);
fractions f3;
fractions f4;
getfraction(n,d);
fractions f5(n,d);

f4 = f3 + f1;
f3.printFraction();
f4.printFraction();
system("pause");

}
[/code]
Post: Markdown Syntax: Formatting Help

You