Please use C++ to write this program and make sure to comment it as well. Thanks
ID: 3814789 • Letter: P
Question
Please use C++ to write this program and make sure to comment it as well. Thanks in advance!
Write a class (largeIntgers) that supports the following functionalities: For a given value for the length of a large integer, generates the digits of this large integer and stores them in a dynamic array. Suppose only positive values for this integer. Prints digits of this large integer on the console. Adds this "large integer" with another "large integer" that is already generated. Additional requirements and instructions: No use of global variables. Code is well commented. Submit all code files needed to compile and run this program, including a sample input file. Comply with syllabus policies .Explanation / Answer
#include<iostream.h>
class largeIntegers
{
int *a;
int size;
public:
largeIntegers(int n); //constructor
largeIntegers(int *x, int n); //parameterized constructor
~largeIntegers(void) //destructor
{
delete a;
}
largeIntegers add(const largeIntegers &num);
void display();
};
largeIntegers::largeIntegers(int n)
{
size=n;
a=new int[n];
for( int i=0;i<n;i++)
a[i]=0;
}
largeIntegers::largeIntegers(int *x, int n)
{
size=n;
a=new int[n];
for(int i=0;i<size;i++)
{
a[i]=x[i];
}
}
largeIntegers largeIntegers::add(const largeIntegers &num) //add two large Integers
{
largeIntegers Z(size);
for(int i=size;i>0;i--)
{
Z.a[i]+=a[i]+num.a[i];
if(Z.a[i]>9) //carry forward
{
Z.a[i-1]++;
}
}
return Z;
}
void largeIntegers ::display()
{
cout<<" The digits are:";
for(int i=0;i<size;i++)
{
cout<<a[i];
}
}
int main()
{
int X[10]={1,2,3,4,5,6,7,8,9,10};
int Y[10]={2,3,4,5,6,7,8,9,10,11};
largeIntegers A(X,10),B(Y,10),C(10);
C=A.add(B);
cout<<" A=";
A.display();
cout<<" B=";
B.display();
cout<<" The sum C=" ;
C.display();
}