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 লিখুন যাতে দুটি fraction যোগ করে 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.