Lesson 19 of 24

Operator Overloading

10 min 35 XP

உங்கள் class-க்கு + - == < போன்ற operators-க்கு அர்த்தம் கொடுக்கலாம். << operator-ஐ 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

Fraction class: numerator, denominator; operator+ இரண்டு பின்னங்களைக் கூட்டி சுருக்கிய (GCD) விடையைத் தரும்; operator<< "a/b" என்று காட்டும். 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.