Answer to Question #269821 in C++ for Moeez

Question #269821

Huge Integers

Design a class that can handle arbitrarily large integers (using strings) that otherwise do not fit in a primitive type. A string will be treated as an integer if it contains all numeric type characters only. A sign indicating positive or negative integer may precede the string e.g. “-123456789009876543210”. Provide support for basic arithmetic and relational operations (using operator overloading) that include:


 addition: + and ++ (both pre and post increment versions)

 subtraction: - (binary as well as unary) and -- (both pre and post increment versions)

 multiplication

 division

 comparison operators: ==, <, >


1
Expert's answer
2021-11-22T07:09:11-0500
#include<iostream>
using namespace std;


class OperatorOverload {
private:
    int real, foo;
public:
    OperatorOverload(int r = 0, int i =0) {real = r; foo = i;}
    
    OperatorOverload operator + (OperatorOverload const &obj) {
        OperatorOverload bar;
        bar.real = real + obj.real;
        bar.foo = foo + obj.foo;
        return bar;
    }
    OperatorOverload operator * (OperatorOverload const &obj) {
        OperatorOverload bar;
        bar.real = real * obj.real;
        bar.foo = foo * obj.foo;
        return bar;
    }
    OperatorOverload operator / (OperatorOverload const &obj) {
        OperatorOverload bar;
        bar.real = real / obj.real;
        bar.foo = foo / obj.foo;
        return bar;
    }
    OperatorOverload operator - (OperatorOverload const &obj) {
        OperatorOverload bar;
        bar.real = real - obj.real;
        bar.foo = foo - obj.foo;
        return bar;
    }
};


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS