0% found this document useful (0 votes)
21 views7 pages

Assignment No 3

The document contains C++ code demonstrating operator overloading through various classes. It includes implementations for arithmetic operations, increment/decrement operations, comparison operators, and logical operators. The main function in each class allows user input and displays the results of the overloaded operations.

Uploaded by

ellglin89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views7 pages

Assignment No 3

The document contains C++ code demonstrating operator overloading through various classes. It includes implementations for arithmetic operations, increment/decrement operations, comparison operators, and logical operators. The main function in each class allows user input and displays the results of the overloaded operations.

Uploaded by

ellglin89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

Assignment no 3

Nam : Adeel Fazil


SAP ID: 70110717
Submit to : Mariya Bibi

//#include <iostream>
//using namespace std;
//
//class different_overload_op {
//public:
// int num;
//
// different_overload_op(int n = 0) {
// num = n;
// }
//
// void input() {
// cout << "Enter a number: " << endl;
// cin >> num;
// }
//
// different_overload_op operator+(different_overload_op obj) {
// return different_overload_op(num + obj.num);
// }
//
// void operator+=(int val) {
// num += val;
// }
//
// void display_sum() {
// cout << "Addition = " << num << endl;
// }
//
// different_overload_op operator-(different_overload_op obj) {
// return different_overload_op(num - obj.num);
// }
//
// void display_sub() {
// cout << "Subtraction = " << num << endl;
// }
//
// different_overload_op operator*(different_overload_op obj) {
// return different_overload_op(num * obj.num);
// }
//
// void display_mul() {
// cout << "Multiplication = " << num << endl;
// }
//
// different_overload_op operator/(different_overload_op obj) {
// return different_overload_op(num / obj.num);
// }
//
// void display_div() {
// cout << "Division = " << num << endl;
// }
//
// different_overload_op operator%(different_overload_op obj) {
// return different_overload_op(num % obj.num);
// }
//
// void display_mod() {
// cout << "Modulus = " << num << endl;
// }
//};
//
//int main() {
// different_overload_op obj4, obj5, obj6;
//
// obj4.input();
// obj5.input();
// obj6 = obj4 + obj5;
// obj6.display_sum();
//
// obj4.input();
// obj5.input();
// obj6 = obj4 - obj5;
// obj6.display_sub();
//
// obj4.input();
// obj5.input();
// obj6 = obj4 * obj5;
// obj6.display_mul();
//
// obj4.input();
// obj5.input();
// obj6 = obj4 / obj5;
// obj6.display_div();
//
// obj4.input();
// obj5.input();
// obj6 = obj4 % obj5;
// obj6.display_mod();
//
// return 0;
//}

//#include <iostream>
//using namespace std;
//
//class overloading_op {
// public:
// int num;
//
// overloading_op():num(0){}
//
// void input() {
// cout << "Enter a number: " << endl;
// cin >> num;
// }
//
// void operator++() {
// ++num;
// }
//
// void operator++(int) {
// num++;
// }
//
// void display_incr_postfix() {
// cout << "Increment postfix = " << num << endl;
// }
//
// void display_incr_prefix() {
// cout << "Increment prefix = " << ++num << endl;
// }
//
// void operator--() {
// --num;
// }
//
// void operator--(int) {
// num--;
// }
//
// void display_decr_postfix() {
// cout << "Decrement postfix = " << num << endl;
// }
//
// void display_decr_prefix() {
// cout << "Decrement prefix = " << --num << endl;
// }
//
// void operator!() {
// num = !num;
// }
//
// void display_not() {
// cout << "Not opertor value = " << num << endl;
// }
//};
//
//int main() {
// overloading_op obj;
//
// obj.input();
// obj++;
// obj.display_incr_postfix();
//
// obj.input();
// ++obj;
// obj.display_incr_prefix();
//
// obj.input();
// obj--;
// obj.display_decr_postfix();
//
// obj.input();
// --obj;
// obj.display_decr_prefix();
//
// obj.input();
// !obj;
// obj.display_not();
//}
//#include <iostream>
//using namespace std;
//
//class overloading_op {
//public:
// int num;
//
// overloading_op():num(0){}
//
// void input() {
// cout << "Enter a number: " << endl;
// cin >> num;
// }
//
// bool operator==(const overloading_op& obj) {
// return num == obj.num;
// }
//
// bool operator>(const overloading_op& obj) {
// return num > obj.num;
// }
//
// bool operator<(const overloading_op& obj) {
// return num < obj.num;
// }
//
// bool operator>=(const overloading_op& obj) {
// return num >= obj.num;
// }
//
// bool operator<=(const overloading_op& obj) {
// return num <= obj.num;
// }
//
// bool operator!=(const overloading_op& obj) {
// return num != obj.num;
// }
//
//};
//
//int main() {
// overloading_op object1, object2;
//
// object1.input();
// object2.input();
// if (object1 == object2) {
// cout << "Equal" << endl;
// } else {
// cout << "Unequal" << endl;
// }
//
// object1.input();
// object2.input();
// if (object1 > object2) {
// cout << "object1 is greater" << endl;
// } else {
// cout << "object2 is greater" << endl;
// }
//
// object1.input();
// object2.input();
// if (object1 < object2) {
// cout << "object1 is lesser" << endl;
// } else {
// cout << "object2 is lesser" << endl;
// }
//
// object1.input();
// object2.input();
// if (object1 <= object2) {
// cout << "object1 is less or equal to object2" << endl;
// } else {
// cout << "object2 is less or equal to object1" << endl;
// }
//
// object1.input();
// object2.input();
// if (object1 >= object2) {
// cout << "object1 is greater or equal to object2" << endl;
// } else {
// cout << "object2 is greater or equal to object1" << endl;
// }
//
// object1.input();
// object2.input();
// if (object1 != object2) {
// cout << "object1 not equal to object2" << endl;
// } else {
// cout << "object1 equal to object2" << endl;
// }
//}

//#include <iostream>
//using namespace std;
//
//class overloading_op {
//public:
// int num;
//
// overloading_op():num(0){}
//
// void input() {
// cout << "Enter a number: " << endl;
// cin >> num;
// }
//
// bool operator&&(const overloading_op& obj) {
// return num && obj.num;
// }
//
// bool operator||(const overloading_op& obj) {
// return num || obj.num;
// }
//
// bool operator==(const overloading_op& obj) {
// return num == obj.num;
// }
//
// bool operator>(const overloading_op& obj) {
// return num > obj.num;
// }
//};
//
//int main() {
// overloading_op val1, val2, val3;
//
// val1.input();
// val2.input();
// val3.input();
//
// if (val1 > val2 && val2 == val3 || val1 > val3 && val3 > val2) {
// cout << "condition true" << endl;
// } else {
// cout << "condition false" << endl;
// }
//}

//#include <iostream>
//using namespace std;
//
//class overloading_op {
//public:
// int num;
//
// overloading_op():num(0){}
//
// void input() {
// cout << "Enter a number: " << endl;
// cin >> num;
// }
//
// void operator=(const overloading_op& obj) {
// num = obj.num;
// }
// void operator=(int val) {
// num = val;
// }
//
// void operator+=(const overloading_op& obj) {
// num += obj.num;
// }
// void operator+=(int val) {
// num += val;
// }
//
// void operator-=(const overloading_op& obj) {
// num -= obj.num;
// }
// void operator-=(int val) {
// num -= val;
// }
//
// void operator*=(const overloading_op& obj) {
// num *= obj.num;
// }
// void operator*=(int val) {
// num *= val;
// }
//
// void operator/=(const overloading_op& obj) {
// num /= obj.num;
// }
// void operator/=(int val) {
// num /= val;
// }
//
// void operator%=(const overloading_op& obj) {
// num %= obj.num;
// }
// void operator%=(int val) {
// num %= val;
// }
//};
//
//int main() {
// overloading_op value1, value2;
// value1 = 50;
// cout << "value = " << value1.num << endl;
//
// value1 += 21;
// cout << "value += " << value1.num << endl;
//
// value1 -= 21;
// cout << "value -= " << value1.num << endl;
//
// value1 *= 21;
// cout << "value *= " << value1.num << endl;
//
// value1 /= 2;
// cout << "value /= " << value1.num << endl;
//
// value1 %= 2;
// cout << "value %= " << value1.num << endl;
//}

You might also like