Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A problem that occurs with most high-level programming languages is that standar

ID: 3828870 • Letter: A

Question


A problem that occurs with most high-level programming languages is that standard numeric types int double... have a very limited range because the represented values are stored using a fixed number of bits. in this project, you will design and implement an integer type as a C++ class. called Largent, that will allow users to store and manipulate very large integers. Your implementation will use a dynamic array to store all the digits of an integer and will supply basic I/O, addition and equality operations. Your class should have 3 data members: a variable to store the maximum size of the array that holds the large integer a variable to store the actual length of the large integer an int array to hold the large integer (this is obviously a pointer, since the array will be dynamic). Your class should have the following functions: An appropriate constructor A Destructor A copy constructor assignment operator A function to overload the support of Largent values A function to overload the operator to addition A function to overload the comparison operator A function to load the operator over

Explanation / Answer

#include <iostream>
using namespace std;

class LargeInt
{
    private:
    long long number;
  
    public:
    LargeInt() //default constructor
    {
        number = 0;
    }
    LargeInt(long long number) //parameterized constructor
    {
        this->number = number;
    }
  
    ~LargeInt() //destructor
    {
        cout<<"destructor"<<endl;
    }
     LargeInt(const LargeInt& obj) //copy constructor
    {
        number = obj.number;
      
    }
  
    const LargeInt& operator=(const LargeInt& obj)// overloaded assignment operator
    {
     number = obj.number;
     return *this;
    }
  
    LargeInt operator+(LargeInt obj) //overloaded + operator
    {
        LargeInt temp;
        temp.number = number +obj.number;
        return temp;
    }
  
    void operator--(int) //decrement operator
    {
        number = number -1;
    }
    friend istream& operator>>(istream& is,LargeInt& obj)
    {
        is>>obj.number;
    }
    friend ostream& operator<<(ostream& os,LargeInt& obj)
    {
        os<<obj.number;
    }
  
};
int main()
{
    LargeInt l1(78568686);
    cout<<"l1 ="<<l1;
    LargeInt l2(45447485);
    cout<<"    l2 ="<<l2;
  
    LargeInt l3(l2);    //copy constructor
    cout<<"    l3="<<l3;
  
    LargeInt l4 ;
    l4 = l1 +l2;
    cout<<"l1+l2 = "<<l4;
  
    l4--;
    cout<<"   l4-- = "<<l4;
  
  
   return 0;
}


output:

l1 =78568686    l2 =45447485    l3=45447485destructor                                                                                                  

destructor                                                                                                                                             

l1+l2 = 124016171   l4--  = 124016170destructor                                                                                                        

destructor                                                                                                                                             

destructor                                                                                                                                             

destructor

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote