Hi there,I'm having a problem with calling an object member function of a class 'Fraction'. Particularly the Fraction addTwoFraction,mult.div,etc.I've included the code i've worked on and in it you'll see i've put 3 instances of where i'd like atleast your thoughts on it. The first is in callingEnviron(defined right after main in this code) and works itself up from there. Thanks for any help guys.

#include <iostream>
using namespace std;
void callingEnviron();
class Fraction
 int iNum;
 int iDenom;
  cout << " construtor called " << endl;
  iNum = 0;
  iDenom = 1;
 Fraction(int, int)
  cout << "constructor 2 called " << endl;
 I've created a constructor before with Fraction(const, const) but it did nothing
 With the way it calls those binary operator functions, is Fraction(int , int) sufficient
 or should there be another constructor for those four binary Fraction functions.
 void assign(int, int);
 void printf(void);
 void increment(void);
 void addTo(const Fraction &);
void Fraction::assign(int iTemp1, int iTemp2)
 iNum = iTemp1;
 iDenom = iTemp2;
 cout << " " << iNum << " " << iDenom << endl;
void Fraction::printf(void)
 cout <<" " << iNum 
   <<" " << iDenom 
   << endl;
Fraction addTwoFraction(const Fraction &frOld1, const Fraction &Old2)
 Fraction iAdd = frOld1;
 (2) This is an area I need help with, once i pass the adress of the first fraction
 How would i get acess to those private members. The way i have it setup those private
 members are accessible through the function calls defined in the class,assign and printf.
 So i'm just a little bit lost as to whether when i pass the first fraction i have to 
 assign those variables and values to a new fraction that can be worked with.
 The general algorithm I've worked on for finding the sum of two fractions is this.
 iAdd.iNum= ((firstFraction.iNum) * (secondFraction.iDenom)) + ((firstFraction.iDenom2) * (secondFraction.iNum));
 iAdd.iDenom= ((firstFraction.iDenom) * (secondFraction.iDenom));
 return iAdd;
Fraction addTwoFraction(const Fraction &frOld1, const Fraction &Old2);
Fraction subtractTwoFraction(const Fraction &frOld1, const Fraction &Old2);
Fraction multiplyTwoFraction(const Fraction &frOld1, const Fraction &Old2);
Fraction divideTwoFraction(const Fraction &frOld1, const Fraction &Old2);
Fraction firstFraction;
Fraction secondFraction;
int main()
 return 0;
void callingEnviron()
 int ifirstnum;
 int ifirstdenom;
 int isecondnum;
 int iseconddenom;
 cout << "Enter the numerator of 1st fraction" << endl;
 cin >> ifirstnum;
 cout << "Enter the denominator of 1st fraction" << endl;
 cin >> ifirstdenom;
 firstFraction.assign(ifirstnum, ifirstdenom);
 cout << "Enter the numerator of 2nd fraction" << endl;
 cin >> isecondnum;
 cout << "Enter the denominator of 2nd fraction" << endl;
 cin >> iseconddenom;
 firstFraction.assign(isecondnum, iseconddenom);
 cout<<" " << &firstFraction << endl;
 cout<<" " << &secondFraction << endl;
 Fraction addTwoFraction(Fraction firstFraction,Fraction secondFraction);
 (1) This is the first part i have some uncertainty about. How to call this function.
 Should it be simply -
 Do you think the function call should even be here and not somewhere such as in the assign
 and printf functions defined in class where the iNum and iDenom private members are more so

14 Years
Discussion Span
Last Post by infamous

1)what u should do is have a member function called add_fract(Fraction ftoadd). this function would be used as follows:

Fraction fract(3,4), other_fract(5,6);

then this would add other_fract to fract. you also need to add a 'get' method to your class, something that will return the two private members num and denom.

2)get/set methods!

3)i dont understand what you mean?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.