1 / 24

Accessor and Mutator Functions

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;

dalila
Download Presentation

Accessor and Mutator Functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Accessor and Mutator Functions

  2. 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; ...

  3. 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; ...

  4. 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; ...

  5. 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; };

  6. 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; }

  7. 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; }

  8. 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; }

  9. 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; }

  10. 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; }

  11. 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; }

  12. 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; }

  13. 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; }

  14. 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() { }

  15. 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 ...

  16. 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; • }

  17. 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; • }

  18. 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 ...

  19. 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; • }

  20. 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; • }

  21. 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; • }

  22. 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; • }

  23. 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; • }

  24. End of Session

More Related