I. Improve the Largelnt (you can use the sample solution) class to include the f
ID: 3861299 • Letter: I
Question
I. Improve the Largelnt (you can use the sample solution) class to include the following functions: A constructor that construct a Large Integer from a string (10pts) o Large Int(string s) A function that returns the large integer as a string o string toString() const A function that computes the power of a Largelnt (30 pts) o Large Int power (int n) Your program will be tested with the following code in main (this should be your main function when you submit the code): int main Large Int. a "1234567891234567890") LargeInt b a .power (10); cout b. toString endl; return 0;Explanation / Answer
Answer
#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;
class LargeInt
{
public:
long long number;
LargeInt()
{
}
LargeInt(string st)
{
number=0;
for (unsigned int i=0; i<st.length(); i++)
{
number=(number*10)+(st[i]-'0');
}
}
string toString() const
{
string str = to_string(this->number);
return str;
}
LargeInt power(int n)
{
LargeInt obj;
obj.number=pow(this->number,n);
return obj;
}
};
int main()
{
LargeInt a("1234567891234567890");
LargeInt b=a.power(10);
cout<<b.toString()<<endl;
return 0;
}