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

The largest value that C + + can store in an int variable is 2, 147, 483, 647. T

ID: 3559581 • Letter: T

Question

The largest value that C + + can store in an int variable is 2, 147, 483, 647. Therefore, any integer larger than this number cannot be stored and processed. Similarly, if the result of two integers calculation (e.g., sum or product) is greater than 2, 147, 483, 647, the result will be incorrect. One way to solve this problem is by creating your own large number that can store and manipulate large integers. The large number can be used to store each integer in array (i.e., each digit of the large number in an array element). In this project, you are asked to design and implement a class called LargeIntegerNumber such that an object of this class can store an integer number of size, at most, 20 digits. Your class should have, at least, the overload of the following operators to deal with LargeIntegerNumber objects:

1. Mathematical operators: addition, subtraction and multiplication;

2. Logical operators: compare two objects (<, >, <=, >=, == and ! =);

3. Input/output stream operators: >>, <<; It should include constructors to properly initialize objects, and member functions to set, retrieve, and print the value of objects. In the mathematical operation, if the result of the numbers has more than 20 digits, output the result with an appropriate message. Write a driver function (i.e., main) to test all of your class members with a menu driven interface that gives the user the option to choose among the different options and repeat the operations as often as the user wishes. All of your project inputs/outputs should be printed into both the computer screen and output (e.g., "operations log.txt").

Explanation / Answer

Now find the updated code..its working..i have spend a couple of hours to solve it so Pls reward the Points.

#include <iostream>
#include <sstream>
#include <cstring>

using namespace std;

class LargeIntegerNumber
{
public:
   void setArray( string num);
int* getArray();
   void printArray();
   LargeIntegerNumber();
  
   LargeIntegerNumber operator+(const LargeIntegerNumber& b){
       LargeIntegerNumber largeInt;
      
       long long int a1=0,b1=0,c;
       for(int i=0;i<20;i++){
           if(this->array[i] != -1)a1*=10, a1+=this->array[i];
           if(b.array[i] != -1)b1*=10, b1+=b.array[i];
       }          
       c=a1+b1;
       ostringstream ss;
       ss << c ;
       string s = ss.str();
       if (s.size()>20) cout <<"Added values integer is greater than 20 digits ";
       for(int i=0;i<s.size();i++){
           largeInt.array[i]=s[i]-'0';
       }
       return largeInt;
   }

   LargeIntegerNumber operator-(const LargeIntegerNumber& b){
       LargeIntegerNumber largeInt;
      
       long long int a1=0,b1=0,c;
       for(int i=0;i<20;i++){
           if(this->array[i] != -1)a1*=10, a1+=this->array[i];
           if(b.array[i] != -1)b1*=10, b1+=b.array[i];
       }          
       c=a1-b1;
       if (c<0){
       cout<<"subtract result value is negative ";
       c = c*(-1);
       }
       ostringstream ss;
       ss << c ;
       string s = ss.str();
       if (s.size()>20) cout <<"Added values integer is greater than 20 digits ";
       for(int i=0;i<s.size();i++){
           largeInt.array[i]=s[i]-'0';
       }
        return largeInt;
   }

   LargeIntegerNumber operator*(const LargeIntegerNumber& b){
       LargeIntegerNumber largeInt;      
       long long int a1=0,b1=0,c;
       for(int i=0;i<20;i++){
           if(this->array[i] != -1)a1*=10, a1+=this->array[i];
           if(b.array[i] != -1)b1*=10, b1+=b.array[i];
       }          
       c=a1*b1;
       cout<< c<<" "<<a1 <<" "<<b1 <<' ' ;
       ostringstream ss;
       ss << c ;
       string s = ss.str();
       if (s.size()>20) cout <<"Added values integer is greater than 20 digits ";
       for(int i=0;i<s.size();i++){
           largeInt.array[i]=s[i]-'0';
       }
        return largeInt;
       return largeInt;
   }


   bool operator< (const LargeIntegerNumber& b){
      
       long long int a1=0,b1=0,c;
       for(int i=0;i<20;i++){
           if(this->array[i] != -1)a1*=10, a1+=this->array[i];
           if(b.array[i] != -1)b1*=10, b1+=b.array[i];
       }          
       if (a1 < b1)return true;
       return false;
   }


   bool operator>( const LargeIntegerNumber& b){
      
      
       long long int a1=0,b1=0,c;
       for(int i=0;i<20;i++){
           if(this->array[i] != -1)a1*=10, a1+=this->array[i];
           if(b.array[i] != -1)b1*=10, b1+=b.array[i];
       }          
       if (a1 > b1)return true;
       return false;
   }
  
   bool operator<=( const LargeIntegerNumber& b){
      
      
       long long int a1=0,b1=0,c;
       for(int i=0;i<20;i++){
           if(this->array[i] != -1)a1*=10, a1+=this->array[i];
           if(b.array[i] != -1)b1*=10, b1+=b.array[i];
       }          
       if (a1 <= b1)return true;
       return false;
   }

   bool operator>=( const LargeIntegerNumber& b){
              
       long long int a1=0,b1=0,c;
       for(int i=0;i<20;i++){
           if(this->array[i] != -1)a1*=10, a1+=this->array[i];
           if(b.array[i] != -1)b1*=10, b1+=b.array[i];
       }          
       if (a1 >= b1)return true;
       return false;
   }
  
  
   bool operator==( const LargeIntegerNumber& b){
              
       long long int a1=0,b1=0,c;
       for(int i=0;i<20;i++){
           if(this->array[i] != -1)a1*=10, a1+=this->array[i];
           if(b.array[i] != -1)b1*=10, b1+=b.array[i];
       }          
       if (a1 == b1)return true;
       return false;
   }


   bool operator!=( const LargeIntegerNumber& b){
              
       long long int a1=0,b1=0,c;
       for(int i=0;i<20;i++){
           if(this->array[i] != -1)a1*=10, a1+=this->array[i];
           if(b.array[i] != -1)b1*=10, b1+=b.array[i];
       }          
       if (a1 != b1)return true;
       return false;
   }
  
   private:
   int array[20];
};

//constructor function
LargeIntegerNumber::LargeIntegerNumber(){
   for(int i=0;i<20;i++)array[i]=-1;
   //cout<<"object created";
  
}

void LargeIntegerNumber::setArray(string num){
   for(int i = 0; i < num.size() && i<20; i++)
           {
               array[i] = num[i] - '0';
       }  
}

int* LargeIntegerNumber::getArray(){
       return array;      
}

void LargeIntegerNumber::printArray(){
    for(int i=0;i<20;i++){
      if ( array[i] != -1)cout<<array[i] ;
  
   }
}
int main(){
  
   LargeIntegerNumber r;     
   bool c;
   int test = 1;
   while(test){
     
       cout<<"Enter operation choice number : ";
       cout<<"addition : 1 ";
       cout<<"subtracrton : 2 ";
       cout<<"multiplication : 3 ";
       cout<<"< : 4 ";
       cout<<"> : 5 ";
       cout<<"<= : 6 ";
       cout<<">= : 7 ";
       cout<<"== : 8 ";
       cout<<"!= : 9 ";
       char choice ;
       cin>>choice ;     
         
       string str ;
       cout<<"Enter a largeInteger ";
       cin >>str;
        if(str.size()>20) cout<<" Enterd largeInteger have more digits than 20 ";
       LargeIntegerNumber a;
       a.setArray(str);
        a.printArray() ;
      
      cout<<"Enter other largeInteger ";
       cin >>str;
       if(str.size()>20) cout<<" Enterd largeInteger have more digits than 20 ";
       LargeIntegerNumber b;
       b.setArray(str);
      
       switch(choice){
           case '1' :
               r = a+b ;
               a.printArray() ;
               cout<< " + " ;
               b.printArray();
               cout<<" = ";
               r.printArray();
               cout<<" ";
               break;  
              
           case '2' :
               r = a-b;
               a.printArray() ;
               cout<< " - " ;
               b.printArray();
               cout<<" = ";
               r.printArray();
               cout<<" ";      
               break;
              
           case '3' :
               r = a*b;
               a.printArray() ;
               cout<< " * " ;
               b.printArray();
               cout<<" = ";
               r.printArray();
               cout<<" ";
               break;
              
           case '4' :
               c=a<b;
               a.printArray() ;
               cout<< " < " ;
               b.printArray();
               cout<<" = ";
               if (c)cout<<"True ";
               else cout<< "False ";
               cout<<" ";
               break;
              
           case '5' :
               c = a>b;
               a.printArray() ;
               cout<< " > " ;
               b.printArray();
               cout<<" = "<<c;
               cout<<" ";
           break;
          
           case '6':
                c = a<=b;
               a.printArray() ;
               cout<< " <= " ;
               b.printArray();
               cout<<" = ";
               if (c)cout<<"True ";
               else cout<< "False ";
               cout<<" ";
           break;
          
           case '7' :
               c = a>=b;

               a.printArray() ;
               cout<< " >= " ;
               b.printArray();
               cout<<" = ";
               if (c)cout<<"True ";
               else cout<< "False ";
               cout<<" ";
           break;
          
           case '8' :
               c = a==b;
              
               a.printArray() ;
               cout<< " == " ;
               b.printArray();
               cout<<" = ";
               if (c)cout<<"True ";
               else cout<< "False ";
               cout<<" ";
           break;
          
           case '9' :
               c = a!=b;
               a.printArray() ;
               cout<< " != " ;
               b.printArray();
               cout<<" = ";
               if (c)cout<<"True ";
               else cout<< "False ";
               cout<<" ";
               break;
          
           }
          
       cout<<"Want to test more -- Enter 1 or 0 for Yes:1 and No:0 "   ;
       cin>>test;
       if(test != 1)test =0;
   }
  
   return 0;
}

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