Need help with fraction class

I desperately need help with constructing a fraction class which I can't seem to get correct. I'm wondering if anyone can help me with the fraction class. This is what I have so far.

#include <iostream>
using namespace std;
class fraction {
public:
int denom;
int numer;
void set (int denom, int numer);
void print();
fraction multipliedBy(fraction f2);
fraction dividedBy(fraction f2);
fraction addedTo(fraction f2);
fraction subtract(fraction f2);
bool isEqualTo(fraction f2);
};

These are the guidelines

Write a fraction class whose objects will represent fractions. For this assignment you aren't required to reduce your fractions. You should provide the following member functions:

A set() operation that takes two integer arguments, a numerator and a denominator, and sets the calling object accordingly.

Arithmetic operations that add, subtract, multiply, and divide fractions. These should be implemented as value returning functions that return a fraction object. They should be named addedTo, subtract, multipliedBy, and dividedBy. In these functions you will need to declare a local "fraction" variable, assign to it the result of the mathematical operation, and then return it.

A boolean operation named isEqualTo that compares two fraction objects for equality. Since you aren't reducing your fractions, you'll need to do this by cross-multiplying. A little review: if numerator1 * denominator2 equals denominator1 * numerator2, then the fractions are equal.

An output operation named print that displays the value of a fraction object on the screen in the form numerator/denominator.
Last edited on
closed account (48T7M4Gy)
So, can you show us what you have written so far? Maybe you have written a short program main() to create a fraction object ready to test your class as you develop it. Have you thought about a fraction constructor and destructor yet? :)
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/195002/
Topic archived. No new replies allowed.