these are the instructions for the program.
Prepare the Fraction class as we discussed in the classroom. It should include three constructors -- one with no parameters and which creates the fraction 0/1, one with one parameter numer and which creates the fraction numer/1, and one with two parameters and which creates the fraction numer/denom, but which assures that the fraction will be in normalized form (that is, positive denominator and with the greatest common divisor removed from the numerator and denominator). Make sure that the store method also stores fractions in normalized form. Add two public methods (functions) to the class, called getNumerator and getDenominator, that return the values of the numerator and denominator of the fraction. The header file and implementation files should be separate files!!
Write a main program to test the fraction class. This main program should first create three fractions to test the three types of constructors. Have the fractions print themselves, but precede each with an explanatory remark so that a fraction doesn't appear by itself. Then prompt the user to enter a numerator and a denominator. Store that fraction in the fraction that you first created with no parameters. Have it print itself. Ask the user if he/she wants to enter another fraction. If N or n is answered, then quit this part of the program and go on to the final step (below). If Y or y is entered, then ask for another fraction, store it and print it. Repeat until the user answers N or n, and then move to the final step. (If the user enters a zero denominator, the constructor and the store method should detect this and take an exit from the program.) As a final step, create the three fractions fract1, fract2 and fract3, where fract1 contains 5/6, fract2 contains 7/2 and fract3 is just the default fraction. Use the getNumerator and getDenominator functions to obtain the numerators and denominators of fract1 and fract2, and store in fract3 the sum of fract1 and fract2. Note: a/b + c/d = (ad + cb) / (b*d). Then have fract3 print itself to make sure the correct result was stored.
[C++]
Main Program
#include <iostream>
#include "Fraction.hpp"
using namespace std;
int main()
{
Fraction fract4(5,-10);
cout<<"The Fraction Is ";
fract4.print();
Fraction fract6(8,4);
cout<<"The Fraction Is ";
fract6.print();
system("pause");
return 0;
}
Header File
#include <iostream>
using namespace std;
class Fraction {
private:
int numerator;
int denominator;
int GreatestComDiv(int n1, int n2);
public:
Fraction();
Fraction(int numer);
Fraction(int numer, int denom);
void store(int numer, int denom);
void print();
};//Fraction
implementation file
#include "Fraction.hpp"
#include <iostream>
#include <cstdlib>
Fraction::Fraction()
{
numerator = 0;
denominator = 1;
}//Fraction::Fraction()
Fraction::Fraction(int numer)
{
numerator = numer;
denominator = 1;
}//Fraction::Fraction(int numer)
Fraction::Fraction(int numer, int denom)
{
if(denom == 0)
{
cout << "Can not Divide By 0!" << endl;
exit(100);
}
if(denom < 0)
{
denom = -denom;
numer = -numer;
}
int gcd = GreatestComDiv (abs(numer), abs(denom));
numer = numer/gcd;
denom = denom/gcd;
store(numer, denom);
}//Fraction::Fraction(int numer, int denom)
void Fraction::store(int numer, int denom)
{
numerator = numer;
denominator = denom;
return;
}//Fraction::store
void Fraction::print()
{
cout<< numerator << "/" << denominator << "." << endl;
return;
}//Fraction::print
int Fraction::GreatestComDiv(int numer, int denom)
{
if (numer < denom)
{
int temp = numer;
numer = denom;
denom = temp;
}
if (denom == 0)
return numer;
else
return GreatestComDiv(denom, numer % denom);
}
[/C++]
could anybody help me out with what you see im missing. i am getting overwhelmed and maybe with a few good pointers i can get set right again thanks