Ok, so I'm working with classes and its been a little while. I basically have to add a new private definition to a program I have already written and change the rest of the program to fit the new definition.

Here is the whole assignment for reference:http://cs.angelo.edu/~mmotl/2305/labs/lab02.pdf

Here is the private portion and the only thing I must add:

Code:

private:
long r[2] //r[0] represents numerator
//r[1] represents denominator

Everything else in the assignment is done correctly because i got 100% on it when I turned it in. I just need help on implementing the long r[2] in.

And here is what I have as of now:

Code:

#include <iostream>
#include <lab02.h>
using namespace std;
Rational::Rational()
{
SetNumerator(0);
SetDenominator(1);
}
Rational::Rational(long num, long denom)
{
SetNumerator(num);
SetDenominator(denom);
}
void Rational::SetNumerator(long num)
{
r[0]=num;
}
void Rational::SetDenominator(long denom)
{
if(denom==0)
r[1]=1;
else
r[1]=denom;
}
long Rational::GetNumerator() const
{
return r[0];
}
long Rational::GetDenominator() const
{
return r[1];
}
void Rational::Reduce()
{
if(GetDenominator()<0)
{
SetNumerator(-r[0]);
SetDenominator(-r[1]);
}
int gcd=GCD(GetNumerator(), GetDenominator());
SetNumerator(GetNumerator()/gcd);
SetDenominator(GetDenominator()/gcd);
}
long Rational::r[2] //????
{ // <-error on this line (invalid function declaration)
numerator=r[0]; //????
denominator=r[1]; //????
}
long Rational::GCD(long m, long n) const
{
int rem;
if(m==0 && n==0)
return 0;
else if(m==0)
return labs(n);
else if(n==0)
return labs(m);
else
{
m=labs(m);
n=labs(n);
rem=m%n;
if(rem==0)
return n;
else
{
while(rem!=0)
{
m=n;
n=rem;
rem=m%n;
if(rem==0)
return n;
}
}
}
return 1;
}

This was a program that I had already written and you can see that I changed all the instances that used to say numerator to r[0] and all the instances of denominator to r[1]. I don't know where I'm going wrong and why I'm getting that error. There are no tutors here right now either so any help would be appreciated.