Lesson 19 of 24

Operator Overloading

10 min 35 XP

+ - == < వంటి operators కు మీ class కోసం అర్థం ఇవ్వవచ్చు. << ను overload చేస్తే cout << object అలాగే పనిచేస్తుంది.

Example: edit me and press Run

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.

Challenge

+35 XP

రెండు fractions ను కలిపి GCD తో ఫలితాన్ని సరళీకరించే operator+, "a/b" ను print చేసే operator<< ఉన్న class Fraction రాయండి. main() లో a b c d చదివి a/b + c/d print చేయండి. Input: 1 2 1 3 → Output: 5/6

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.