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.