Question

3. (Dynamic Array) In C++, the largest int value is 2147483647. So. an integer larger than this cannot be stored and processe

0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

solution

ode //header file #include <iostream> //librabry file #include <Cctype> //string library #include <cstring> using namespace sint large integervalues: :operator=( ïarge integervalues oper2 int i; if (lenvalue<oper2.lenvalue) return -1; if (oper2.lenvalarge_integervalues large_integervalues::operator-( large_integervalues oper2) large_integervalues temp_value; int c if (lenvtemp value.integervalue [k+11 temp-value. int egervalue(k+1]+ temp-value. integervalue [k] / 10; temp-value . integervalue [kcase -1: cout<< is lower than break; case 0: cout< equal to break; case 1: cout<< is higher than ; break; num2. Output

//output

Enter a number (10 DIGITS maximum) :23145 Enter a number (10 DIGITS maximum) :12345 23145 + 12345 35490 23145 -1234511899 231

//copyable code

Code

//header file

#include <iostream>

//librabry file

#include <cctype>

//string library

#include <cstring>

using namespace std;

#define Num_DIGITS 10

class large_integervalues

{

public:

large_integervalues();

void Inputvalue();

void Outputvalue();

large_integervalues operator+( large_integervalues );

large_integervalues operator-( large_integervalues );

large_integervalues operator*( large_integervalues );

int operator==( large_integervalues);

private:

int integervalue[ Num_DIGITS ];

int lenvalue;

};

void large_integervalues::Outputvalue()

{

int i1;

for (i1=lenvalue-1;i1 >= 0; i1-- )

cout<<integervalue[i1];

}

void large_integervalues::Inputvalue()

{

string in;

int i1,j1,k1;

cout<<"Enter a number("<<Num_DIGITS<<" DIGITS maximum):";

cin>>in;

for(i1=0;in[i1]!='\0';i1++);

lenvalue=i1;

k1=0;

for(j1=i1-1;j1>=0;j1--)

    integervalue[j1]=in[k1++]-48;

}

large_integervalues::large_integervalues( )

{

for ( int i1 = 0; i1 <Num_DIGITS; i1++ )

      integervalue[ i1 ] = 0;

lenvalue=Num_DIGITS-1;

}

int large_integervalues::operator==( large_integervalues oper2 )

{

int i;

if(lenvalue<oper2.lenvalue)

      return -1;

if(oper2.lenvalue<lenvalue)

      return 1;

for(i=lenvalue-1;i>=0;i--)

      if(integervalue[i]<oper2.integervalue[i])

           return -1;

       else if(oper2.integervalue[i]<integervalue[i])

             return 1;

return 0;

}

large_integervalues large_integervalues::operator+( large_integervalues oper2 )

{large_integervalues temp_value;

int carry_value = 0;

int c1,i;

if(lenvalue>oper2.lenvalue)

    c1=lenvalue;

else

    c1=oper2.lenvalue;

for ( i=0; i<c1; i++ )

     {temp_value.integervalue[ i ] =integervalue[ i ] + oper2.integervalue[ i ] + carry_value;

     if ( temp_value.integervalue[ i ] > 9 )

         {temp_value.integervalue[ i ] %= 10;

          carry_value = 1;

         }

     else

          carry_value = 0;

     }

if(carry_value==1)

    {temp_value.lenvalue=c1+1;

    if(temp_value.lenvalue>=Num_DIGITS)

          cout<<"***OVERFLOW*****\n";

    else

         temp_value.integervalue[i]=carry_value;

  

    }

else   

   temp_value.lenvalue=c1;

return temp_value;

}

large_integervalues large_integervalues::operator-( large_integervalues oper2 )

{

large_integervalues temp_value;

int c;

if(lenvalue>oper2.lenvalue)

    c=lenvalue;

else

    c=oper2.lenvalue;

int borrow_value = 0;

for( int i = c;i >= 0;i--)

if(borrow_value==0)

    {if(integervalue[i]>=oper2.integervalue[i])

           temp_value.integervalue[i]=integervalue[i]-oper2.integervalue[i];

    else

          {borrow_value=1;

          temp_value.integervalue[i]=integervalue[i]+10-oper2.integervalue[i];

          }

    }

else

    {borrow_value=0;

    if(integervalue[i]-1>=oper2.integervalue[i])

           temp_value.integervalue[i]=integervalue[i]-1-oper2.integervalue[i];

      else

          {borrow_value=1;

          temp_value.integervalue[i]=integervalue[i]-1+10-oper2.integervalue[i];

          }

      }

temp_value.lenvalue=c;

return temp_value;

}  

large_integervalues large_integervalues::operator*( large_integervalues oper2 )

    {

      large_integervalues temp_value;

      int i,j,k,tmp_value,m1=0;

       for (int i=0; i<oper2.lenvalue; i++)

        { k=i;

        for (j=0; j< lenvalue; j++)

           {

             tmp_value = integervalue[ j ] * oper2.integervalue[i];

            temp_value.integervalue[k] =temp_value.integervalue[k]+tmp_value;

            temp_value.integervalue[k+1] =temp_value.integervalue[k+1]+ temp_value.integervalue[k]/10;

            temp_value.integervalue[k] %=10;

            k++;

            if(k>m1)

                m1=k;

                }

        }

        temp_value.lenvalue=m1;

         if(temp_value.lenvalue>Num_DIGITS)

          cout<<"***OVERFLOW*****\n";

        return temp_value;

    }

using namespace std;

int main()

{

int c;

large_integervalues num1,num2,res;

num1.Inputvalue();

num2.Inputvalue();

num1.Outputvalue();

cout <<" + ";

num2.Outputvalue();

res=num1+num2;

cout<< " = " ;

res.Outputvalue();

cout << "\n\n";

num1.Outputvalue();

cout <<" - ";

num2.Outputvalue();

res=num1-num2;

cout<< " = " ;

res.Outputvalue();

cout << "\n\n";

num1.Outputvalue();

cout <<" * ";

num2.Outputvalue();

res=num1*num2;

cout<< " = " ;

res.Outputvalue();

cout << "\n\n";

c=num1==num2;

num1.Outputvalue();

switch (c)

{case -1: cout<<" is lower than ";

            break;

   case 0: cout<<" is equal to ";

            break;

    case 1: cout<<" is higher than ";

            break;

    }

num2.Outputvalue();

cout << "\n\n";               

}


> The code is cumbersome and incomprehensible. I understand that the programmer who wrote this code understood what he was doing, but without detailed comments, this code is useless. Since this is homework and it should teach something to beginners, but the problem is that a beginner will not understand anything in this code.

zipfaster Mon, Feb 14, 2022 12:11 PM

Add a comment
Know the answer?
Add Answer to:
3. (Dynamic Array) In C++, the largest int value is 2147483647. So. an integer larger than this cannot be stored and pr...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • C++ pleasr Extra Credit: Large Integer (25 points) In C++, the largest int value is 2147483647....

    C++ pleasr Extra Credit: Large Integer (25 points) In C++, the largest int value is 2147483647. So, an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an array. Write a program that inputs two positive integers of, at most,...

  • please use c++ programming and single dimensional arrays to solve this problem thank you Problem 02:...

    please use c++ programming and single dimensional arrays to solve this problem thank you Problem 02: Large Integer (20 points) In CH, the largest int value is 2147483647. So, an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an...

  • Java Project 1. The largest positive integer of type int is 2,147,483,647. Another integer type, long,...

    Java Project 1. The largest positive integer of type int is 2,147,483,647. Another integer type, long, represents integers up to 9,223,372,036,854,775,807. Imagine that you want to represent even larger integers. For example, cryptography uses integers having more than 100 digits. Design and implement a class Huge of very large nonnegative integers. The largest integer should contain at least 30 digits. Use a deque to represent the value of an integer. Provide operations for the class that * Set the value...

  • Dynamic Implementation of Stack - The purpose is to use our dynamic implementation of stack. The...

    Dynamic Implementation of Stack - The purpose is to use our dynamic implementation of stack. The application will be to add large numbers. Review adding large numbers Remember that we can use stacks to safely add integer values that overflow the int data type g. in Java, the maximum possible int value Integer.MAX_VALUE is: 2147483647 so any int addition larger than this will overflow and fail Using stacks to add large numbers safely Will actually represent the large integers to...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

  • This is programming project 1 chapter 9(Book ISBN:1292222824 (1-292-22282-4) Walter Savitch Problem Solving with C++: Global...

    This is programming project 1 chapter 9(Book ISBN:1292222824 (1-292-22282-4) Walter Savitch Problem Solving with C++: Global Edition, 10/E) Question Do Programming Project 7 in Chapter 7 using a dynamic array. In this version of the problem, use dynamic arrays to store the ditits in each large integer. Allow an arbitrary number of digits instead of capping the number of digits at 20. TER 7/ Arrays time. For example digit at a the integer 1234 could be stored in the array...

  • 8.9 Coding lab #5: create a dynamic array ADT and a singly linked list ADT. Honor Code...

    8.9 Coding lab #5: create a dynamic array ADT and a singly linked list ADT. Honor Code Your answers to this homework must be your own work.You are not allowed to share your solutions.You may not engage in any other activities that will dishonestly improve your results or dishonestly improve or damage the results of others. Plagiarism Plagiarism is when you copy words, ideas, or any other materials from another source without giving credit. Plagiarism is unacceptable in any academic environment....

  • Can anyone please write the code for this.

    Create a class Huge Integer that uses a40-elementarray of digits to Store integers as large as 40 digits each. Provide member functions input, output, add and subtract. For comparing Huge Integer objects, provide functions is Equal To, is Not Equal To, is Greater Than, Is Less Than, is Greater Than Or Equal To and is Less Than Or Equal To—each of these is a “predicate” function that simply returns true if the relationship holds between the two Huge Integers and...

  • Consider the following program that reads a number of nonnegative integers into an array and prints...

    Consider the following program that reads a number of nonnegative integers into an array and prints the contents of the array.   Complete the missing parts, add new function prototypes and function definitions, and test the program several times. Add the following to the program: Write a void function that prints the list of nonnegative integers in reverse. Write a void function that prints all the numbers stored in the list that are greater than 10. It will also print the...

  • DIRECTIONS FOR THE WHOLE PROJECT BELOW BigInt class The purpose of the BigInt class is to...

    DIRECTIONS FOR THE WHOLE PROJECT BELOW BigInt class The purpose of the BigInt class is to solve the problem using short methods that work together to solve the operations of add, subtract multiply and divide.   A constructor can call a method called setSignAndRemoveItIfItIsThere(). It receives the string that was sent to the constructor and sets a boolean variable positive to true or false and then returns a string without the sign that can then be processed by the constructor to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT