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.