Hi,
I am c++ beginner and i need some help with a problem.
Made a Rational class who allows you to work with rational numbers. Class Construct will have two arguments : numerator and denominator. You must made a copy constructor.
It will provide member functions :
Access to the numerator, denominator that rational number.
redefining operators + =, - =, * =, / = for addition, subtraction, multiplication and division with another rational number rational number given as an argument.
It will redefine operator >> as a friend function to read a rational number from the keypad.
It will provide member functions:
test of equality of two rational numbers (redefining operator ==).
writing a rational number to stdout (redefining operator <<).
redefining operators +, -, *, / to allow operation with two arguments rational numbers.
redefining the assignment operator.
Write a main function that reads n rational fractions and calculates their sum.
The code is pretty good. After trying to compile it I found a couple of minor problems.
The argument to the copy constructor should be const: Rational(const Rational & r)
In main(), cin << t should be cin >> t
Two other comments:
simplifica should be a method of Rational:
1 2 3 4 5 6
void Rational::simplifica()
{
int c cmmdc(numarator, numitor);
numarator /= c;
numitor /= c;
}
Also notice that cmmdc() doesn't access any members of Rational, so it doesn't need to be a member, or at least it could be a static member. Since it isn't really needed as part of the interface, I'd remove it from the Rational class completely and make it a static function instead: staticint cmmdc(int a, int b)