Write your question here.
This is my first major assigment in OOP in c++.
for my header i have been given the following class definition
1 2 3 4 5 6 7 8 9 10
|
using namespace std;
class Fraction
{
public:
Fraction(void);
Fraction(int aN, int aD);
int getNumerator();
int getDenominator();
Fraction adder(Fraction aF);
~ Fraction(void);
|
The assigment says that the adder function is supposed to work in a way were the current object is the first operand and the parameter of the function is the second operand. ex. If the object is 1/6 and the parameter is 1/3 then adder is supposed to give 3/6.
My questions are following:
a) Both getNumertor() and getDenominator() are set to return a integer, but i have no idea what adder(Fraction aF) is supposed to return. It says that it is supposed to return an instant of the class Fraction. It can't be a integer even though my product is supposed to produce two, if we were to go by the parameters set in the constructor.
for instance this is the cpp. i have built so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include "fraction.h"
#include <string>
Fraction::Fraction()
{
}
Fraction::Fraction(int aN, int aD) {
numerator = aN;
denominator= aD;
}
int Fraction::getNumerator() {
return numerator;
}
int Fraction::getDenominator() {
return denominator;
}
Fraction Fractiom::adder(Fraction aF) {
aF = 1/3?
return ??
}
Fraction::~Fraction()
{
}
|
The issue isnt the arithemetics. I can figur those out. I just dont know what this function can return. I need the most simple example so just about anything compiles, just so i know which size i am dealing with(an iteger, a single string etc.)
Then if we look at the source i have made:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream>
#include "fraction.h"
using namespace std;
int main() {
Fraction f1(1, 6);
cout << f1.getNumerator() << "/" << f1.getDenominator() << endl;
cin.get();
return 0;
}
|
The first example just shows how i use getNumerator and getDenominator to produce a random Fraction.
b) I asume i can write f1.adder(aF) to produce my product when i get the arithemtics in the cpp right, or is that assumption wrong?