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

class Fraction लिखें जिसमें दो fractions जोड़ने और GCD से परिणाम को सरल करने वाला operator+ हो, और "a/b" print करने वाला operator<<। 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.