My assignment is
Develop rational number class that can
• add
• subtract
• multiply
• divide
• reduce to simplest form
Your class must be able to handle rational numbers of different denominators
Any help will be greatly appreciated!
This is the errors I am getting
error C4716: 'Rational::addition' : must return a value
error C4716: 'Rational::multiplication' : must return a value
error C4716: 'Rational::division' : must return a value
error C4716: 'Rational::subtraction' : must return a value
The error messages are clear enough. You have for example c.addition(d) in your test, but this function does not return anything, so z=c.addition(d); makes no sense. You need to return a rational number. You can put for example return *this; at the end of the functions. See the following example
#include<iostream>
usingnamespace std;
class R{
public:
R(int a=0);
R add(R b);
int internal;
};
R::R(int a)
{
internal=a;
}
R R::add(R b)
{
internal+=b.internal;
return *this;
}
int main()
{
R a(1),b(2),c;
cout<<a.internal<<endl;
cout<<b.internal<<endl;
cout<<c.internal<<endl;
c=a.add(b);
cout<<c.internal<<endl;
}
Also, your addition/subtraction is not what other people might expect. For example 1/2+1/3 in your functions will be 2/5 instead of 5/6