240 likes | 538 Views
Accessor and Mutator Functions. Private Access Woes. // fraction.h ... class Fraction { ... private: int m_Numerator ; int m_Denominator ; };. //fraction.cpp ... Fraction mult_fracs (const Fraction & lhs, const Fraction & rhs ) { Fraction temp;
E N D
Private Access Woes //fraction.h ... class Fraction { ... private: intm_Numerator; intm_Denominator; }; //fraction.cpp ... Fractionmult_fracs(const Fraction & lhs, const Fraction & rhs) { Fraction temp; temp.m_Numerator = lhs.m_Numerator * rhs.m_Numerator; ...
Private Access Woes //fraction.h ... class Fraction { ... private: intm_Numerator; intm_Denominator; }; //fraction.cpp ... Fractionmult_fracs(const Fraction & lhs, const Fraction & rhs) { Fraction temp; • temp.m_Numerator= lhs.m_Numerator * rhs.m_Numerator; ...
Private Access Woes //fraction.h ... class Fraction { ... private: intm_Numerator; intm_Denominator; }; //fraction.cpp ... Fractionmult_fracs(const Fraction & lhs, const Fraction & rhs) { Fraction temp; • temp.m_Numerator = lhs.m_Numerator * rhs.m_Numerator; ...
Accessor and Mutator Functions //fraction.h ... class Fraction { public: void readin(); void print(); Fraction reciprocal(); void unreduce(const int m); intgetNum(); intgetDen(); void setNumer(const intnumer); boolsetDenom(const intdenom); private: intm_Numerator; intm_Denominator; };
Accessor and Mutator Functions //fraction.h ... class Fraction { public: void readin(); void print(); Fraction reciprocal(); void unreduce(const int m); intgetNum(); intgetDen(); void setNumer(const intnumer); boolsetDenom(const intdenom); private: intm_Numerator; intm_Denominator; }; //fraction.cpp ... int Fraction::getNum() { return m_Numerator; }
Accessor and Mutator Functions //fraction.h ... class Fraction { public: void readin(); void print(); Fraction reciprocal(); void unreduce(const int m); intgetNum(); intgetDen(); void setNumer(const intnumer); boolsetDenom(const intdenom); private: intm_Numerator; intm_Denominator; }; //fraction.cpp ... int Fraction::getDen() { return m_Denominator; }
Accessor and Mutator Functions //fraction.h ... class Fraction { public: void readin(); void print(); Fraction reciprocal(); void unreduce(const int m); intgetNum(); intgetDen(); void setNumer(const intnumer); boolsetDenom(const intdenom); private: intm_Numerator; intm_Denominator; }; //fraction.cpp ... void Fraction::setNumer(const intnumer) { m_Numerator = numer; return; }
Accessor and Mutator Functions //fraction.h ... class Fraction { public: void readin(); void print(); Fraction reciprocal(); void unreduce(const int m); intgetNum(); intgetDen(); void setNumer(const intnumer); boolsetDenom(const intdenom); private: intm_Numerator; intm_Denominator; }; //fraction.cpp ... bool Fraction::setDenom(const intdenom) { bool set = false; if(denom != 0) { set = true; m_Denominator = denom; } return set; }
Inlining //fraction.h ... class Fraction { public: void readin(); void print(); Fraction reciprocal(); void unreduce(const int m); intgetNum(); intgetDen(); void setNumer(const intnumer); boolsetDenom(const intdenom); private: intm_Numerator; intm_Denominator; }; //fraction.cpp ... int Fraction::getNum() { return m_Numerator; }
Inlining //fraction.h ... class Fraction { public: void readin(); void print(); Fraction reciprocal(); void unreduce(const int m); intgetNum(); intgetDen(); void setNumer(const intnumer); boolsetDenom(const intdenom); private: intm_Numerator; intm_Denominator; }; //fraction.cpp ... int Fraction::getNum() { return m_Numerator; }
Inlining //fraction.h ... class Fraction { public: void readin(); void print(); Fraction reciprocal(); void unreduce(const int m); intgetNum() { } intgetDen(); void setNumer(const intnumer); boolsetDenom(const intdenom); private: intm_Numerator; intm_Denominator; }; //fraction.cpp ... int Fraction::getNum() { return m_Numerator; }
Inlining //fraction.h ... class Fraction { public: void readin(); void print(); Fraction reciprocal(); void unreduce(const int m); intgetNum() { } intgetDen(); void setNumer(const intnumer); boolsetDenom(const intdenom); private: intm_Numerator; intm_Denominator; }; //fraction.cpp ... int Fraction::getNum() { return m_Numerator; }
Inlining //fraction.h ... class Fraction { public: void readin(); void print(); Fraction reciprocal(); void unreduce(const int m); intgetNum() { return m_Numerator; } intgetDen(); void setNumer(const intnumer); boolsetDenom(const intdenom); private: intm_Numerator; intm_Denominator; }; //fraction.cpp ... int Fraction::getNum() { }
Inlining //fraction.h ... class Fraction { public: void readin(); void print(); Fraction reciprocal(); void unreduce(const int m); intgetNum() { return m_Numerator; } intgetDen(); void setNumer(const intnumer); boolsetDenom(const intdenom); private: intm_Numerator; intm_Denominator; }; //fraction.cpp ...
Inlining //fraction.h ... class Fraction { public: void readin(); void print(); Fraction reciprocal(); void unreduce(const int m); intgetNum() { return m_Numerator; } intgetDen(); void setNumer(const intnumer); boolsetDenom(const intdenom); private: intm_Numerator; intm_Denominator; }; //fraction.cpp ... • int Fraction::getDen() • { • return m_Denominator; • }
Inlining //fraction.h ... class Fraction { public: void readin(); void print(); Fraction reciprocal(); void unreduce(const int m); intgetNum() { return m_Numerator; } intgetDen() { return m_Denominator; } void setNumer(const intnumer); boolsetDenom(const intdenom); private: intm_Numerator; intm_Denominator; }; //fraction.cpp ... • int Fraction::getDen() • { • return m_Denominator; • }
Inlining //fraction.h ... class Fraction { public: void readin(); void print(); Fraction reciprocal(); void unreduce(const int m); intgetNum() { return m_Numerator; } intgetDen() { return m_Denominator; } void setNumer(const intnumer); boolsetDenom(const intdenom); private: intm_Numerator; intm_Denominator; }; //fraction.cpp ...
Private Access Woes • // in the Fractions.cpp file • Fraction mult_fracs(const Fraction & lhs, const Fraction & rhs) • { • Fraction temp; • temp.setNumer(lhs.getNumer() * rhs.getNumer()); • if (! (temp.setDenom(lhs.getDenom() * rhs.getDenom())) • { • cout<<"ERROR: denominator is 0 "<<endl; • exit(2); • } • return temp; • }
Private Access Woes • // in the Fractions.cpp file • Fraction mult_fracs(const Fraction & lhs, const Fraction & rhs) • { • Fraction temp; • temp.setNumer(lhs.getNumer() * rhs.getNumer()); • if (! (temp.setDenom(lhs.getDenom() * rhs.getDenom())) • { • cout<<"ERROR: denominator is 0 "<<endl; • exit(2); • } • return temp; • }
Private Access Woes • // in the Fractions.cpp file • Fraction mult_fracs(const Fraction & lhs, const Fraction & rhs) • { • Fraction temp; • temp.setNumer(lhs.getNumer() * rhs.getNumer()); • if (! (temp.setDenom(lhs.getDenom() * rhs.getDenom())) • { • cout<<"ERROR: denominator is 0 "<<endl; • exit(2); • } • return temp; • }
Private Access Woes • // in the Fractions.cpp file • Fraction mult_fracs(const Fraction & lhs, const Fraction & rhs) • { • Fraction temp; • temp.setNumer(lhs.getNumer() * rhs.getNumer()); • if (! (temp.setDenom(lhs.getDenom() * rhs.getDenom())) • { • cout<<"ERROR: denominator is 0 "<<endl; • exit(2); • } • return temp; • }
Private Access Woes • // in the Fractions.cpp file • Fraction mult_fracs(const Fraction & lhs, const Fraction & rhs) • { • Fraction temp; • temp.setNumer(lhs.getNumer() * rhs.getNumer()); • if (! (temp.setDenom(lhs.getDenom() * rhs.getDenom())) • { • cout<<"ERROR: denominator is 0 "<<endl; • exit(2); • } • return temp; • }