1 / 24

IsEquals Operator

IsEquals Operator. Code Trace. // main.cpp ... int main() { if(f==g) ... // fraction.h ... class Fraction { friend bool operator==(const Fraction & lhs, const Fraction & rhs ); ... // fraction.cpp bool operator==(const Fraction & lhs, const Fraction & rhs )

kamran
Download Presentation

IsEquals Operator

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. IsEquals Operator

  2. Code Trace // main.cpp ... int main() { if(f==g) ... // fraction.h ... class Fraction { friend bool operator==(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator==(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator==rhs.m_Numerator*lhs.m_Denominator; • }

  3. Code Trace // main.cpp ... int main() { if(f==g) ... // fraction.h ... class Fraction { friend bool operator==(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator==(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator==rhs.m_Numerator*lhs.m_Denominator; • } f in main g in main m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32

  4. Code Trace f in main lhs in operator== g in main rhs in operator== // main.cpp ... int main() { if(f==g) ... // fraction.h ... class Fraction { friend bool operator==(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator==(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator==rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32

  5. Code Trace f in main lhs in operator== g in main rhs in operator== // main.cpp ... int main() { if(f==g) ... // fraction.h ... class Fraction { friend bool operator==(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator==(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator==rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32 64

  6. Code Trace f in main lhs in operator== g in main rhs in operator== // main.cpp ... int main() { if(f==g) ... // fraction.h ... class Fraction { friend bool operator==(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator==(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator==rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32 9 64

  7. Code Trace f in main lhs in operator== g in main rhs in operator== // main.cpp ... int main() { if(f==g) ... // fraction.h ... class Fraction { friend bool operator==(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator==(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator==rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32 576

  8. Code Trace f in main lhs in operator== g in main rhs in operator== // main.cpp ... int main() { if(f==g) ... // fraction.h ... class Fraction { friend bool operator==(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator==(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator==rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32 32 576

  9. Code Trace f in main lhs in operator== g in main rhs in operator== // main.cpp ... int main() { if(f==g) ... // fraction.h ... class Fraction { friend bool operator==(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator==(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator==rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32 9 32 576

  10. Code Trace f in main lhs in operator== g in main rhs in operator== // main.cpp ... int main() { if(f==g) ... // fraction.h ... class Fraction { friend bool operator==(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator==(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator==rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32 576 288

  11. Code Trace f in main lhs in operator== g in main rhs in operator== // main.cpp ... int main() { if(f==g) ... // fraction.h ... class Fraction { friend bool operator==(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator==(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator==rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32 576 288 false

  12. NotEquals Operator

  13. Code Trace // main.cpp ... int main() { if(f!=g) ... // fraction.h ... class Fraction { friend bool operator!=(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator!=(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator!=rhs.m_Numerator*lhs.m_Denominator; • }

  14. Code Trace // main.cpp ... int main() { if(f!=g) ... // fraction.h ... class Fraction { friend bool operator!=(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator!=(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator!=rhs.m_Numerator*lhs.m_Denominator; • } f in main g in main m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32

  15. Code Trace f in main lhs in operator!= g in main rhs in operator!= // main.cpp ... int main() { if(f!=g) ... // fraction.h ... class Fraction { friend bool operator!=(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator!=(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator!=rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32

  16. Code Trace f in main lhs in operator!= g in main rhs in operator!= // main.cpp ... int main() { if(f!=g) ... // fraction.h ... class Fraction { friend bool operator!=(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator!=(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator!=rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32 64

  17. Code Trace f in main lhs in operator!= g in main rhs in operator!= // main.cpp ... int main() { if(f!=g) ... // fraction.h ... class Fraction { friend bool operator!=(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator!=(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator!=rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32 9 64

  18. Code Trace f in main lhs in operator!= g in main rhs in operator!= // main.cpp ... int main() { if(f!=g) ... // fraction.h ... class Fraction { friend bool operator!=(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator!=(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator!=rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32 576

  19. Code Trace f in main lhs in operator!= g in main rhs in operato!r= // main.cpp ... int main() { if(f!=g) ... // fraction.h ... class Fraction { friend bool operator!=(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator!=(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator!=rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32 32 576

  20. Code Trace f in main lhs in operator!= g in main rhs in operator!= // main.cpp ... int main() { if(f!=g) ... // fraction.h ... class Fraction { friend bool operator!=(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator!=(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator!=rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32 9 32 576

  21. Code Trace f in main lhs in operator!= g in main rhs in operator!= // main.cpp ... int main() { if(f!=g) ... // fraction.h ... class Fraction { friend bool operator!=(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator!=(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator!=rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32 576 288

  22. Code Trace f in main lhs in operator!= g in main rhs in operator!= // main.cpp ... int main() { if(f!=g) ... // fraction.h ... class Fraction { friend bool operator!=(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator!=(const Fraction & lhs, const Fraction & rhs) • { • return lhs.m_Numerator*rhs.m_Denominator!=rhs.m_Numerator*lhs.m_Denominator; • } m_Numerator: 9 m_Denominator: 64 m_Numerator: 9 m_Denominator: 32 576 288 true

  23. Alternative Definition // main.cpp ... int main() { if(f!=g) ... // fraction.h ... class Fraction { friend bool operator!=(const Fraction & lhs, const Fraction & rhs); ... // fraction.cpp • bool operator==(const Fraction & lhs, const Fraction & rhs) • { • return !(lhs==rhs); • }

  24. End of Session

More Related