0% found this document useful (0 votes)
2 views

Assignment#3

The document contains multiple C++ classes demonstrating operator overloading for arithmetic, relational, logical, and assignment operations. Each class includes methods for input, performing operations, and displaying results. The main function in each class tests the overloaded operators with user input.

Uploaded by

ellglin89
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment#3

The document contains multiple C++ classes demonstrating operator overloading for arithmetic, relational, logical, and assignment operations. Each class includes methods for input, performing operations, and displaying results. The main function in each class tests the overloaded operators with user input.

Uploaded by

ellglin89
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

// #include<iostream>

// using namespace std;


// class overload_op{
// public:
// int num;

// overload_op():num(0){}

// void input(){
// cout << "Enter a number: "<< endl;
// cin >> num;
// }

// overload_op operator + (overload_op &obj){


// overload_op sum ;
// sum.num = num + obj.num;
// return sum;
// }

// void operator + (int val){


// num = num + val;
// }

// void display_sum(){
// cout << "Addition = " << num << endl;
// }

// overload_op operator - (overload_op &obj){


// overload_op sub;
// sub.num = num - obj.num;
// return sub;
// }

// void display_sub(){
// cout << "Subtraction = " << num << endl;
// }

// overload_op operator * (overload_op &obj){


// overload_op mul ;
// mul.num = num * obj.num;
// return mul;
// }

// void display_mul(){
// cout << "Multiplication = " << num << endl;
// }

// overload_op operator / (overload_op &obj){


// overload_op div ;
// div.num = num / obj.num;
// return div;
// }

// void display_div(){
// cout << "Division = " << num << endl;
// }

// overload_op operator % (overload_op &obj){


// overload_op mod ;
// mod.num = num / obj.num;
// return mod;
// }

// void display_mod(){
// cout << "Modulus = " << num << endl;
// }
// };

// int main(){
// overload_op obj1,obj2,obj3;

// obj1.input();
// obj2.input();
// obj3 = obj1 + obj2;
// obj3.display_sum();

// obj1.input();
// obj2.input();
// obj3 = obj1 - obj2;
// obj3.display_sub();

// obj1.input();
// obj2.input();
// obj3 = obj1 * obj2;
// obj3.display_mul();

// obj1.input();
// obj2.input();
// obj3 = obj1 / obj2;
// obj3.display_div();

// obj1.input();
// obj2.input();
// obj3 = obj1 % obj2;
// obj3.display_mod();
// }

// #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 == (overloading_op &obj){


// if (num == obj.num){
// return true;
// }
// else{
// return false;
// }

// }

// bool operator > (overloading_op &obj){


// if (num > obj.num){
// return true;
// }
// else{
// return false;
// }

// }

// bool operator < (overloading_op &obj){


// if (num < obj.num){
// return true;
// }
// else{
// return false;
// }

// }

// bool operator >= (overloading_op &obj){


// if (num >= obj.num){
// return true;
// }
// else{
// return false;
// }

// }

// bool operator <= (overloading_op &obj){


// if (num <= obj.num){
// return true;
// }
// else{
// return false;
// }

// }

// bool operator != (overloading_op &obj){


// if (num != obj.num){
// return true;
// }
// else{
// return false;
// }

// }

// };

// 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 && (overloading_op &obj){


// if(num == true && obj.num == true){
// return true;
// }
// else{
// return false;
// }
// }

// bool operator || (overloading_op &obj){


// if(num == true && obj.num == true || num == true && obj.num == false ||
num == false && obj.num == true){
// return true;
// }
// else{
// return false;
// }
// }

// bool operator == (overloading_op &obj){


// if (num == obj.num){
// return true;
// }
// else{
// return false;
// }

// }

// bool operator > (overloading_op &obj){


// if (num > obj.num){
// return true;
// }
// else{
// return false;
// }

// }

// };

// 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 << "condititon 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 = (overloading_op &obj){


// num = obj.num;
// }
// void operator = (int val){
// num = val;
// }

// void operator += (overloading_op &obj){


// num += obj.num;
// }
// void operator += (int val){
// num += val;
// }
// void operator -= (overloading_op &obj){
// num -= obj.num;
// }
// void operator -= (int val){
// num -= val;
// }

// void operator *= (overloading_op &obj){


// num *= obj.num;
// }
// void operator *= (int val){
// num *= val;
// }

// void operator /= (overloading_op &obj){


// num /= obj.num;
// }
// void operator /= (int val){
// num /= val;
// }

// void operator %= (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