Question: Please Help, I prefer to keep it in C++ if possible Improve the LargeInt (you can use the sample solution) class to include the following
Please Help, I prefer to keep it in C++ if possible Improve the LargeInt (you can use the sample solution) class to include the following functions: -A constructor that construct a Large Integer from a string LargeInt(string s) -A function that returns the large integer as a string string toString() const -A function that computes the power of a LargeInt LargeInt 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() { LargeInt a(1234567891234567890); LargeInt b=a.power(10); cout << b.toString() << endl; return 0; } Previous written code: #include using namespace std; string sum(string num1, string num2){ int overage =0,sum; string min=num1, max=num2, total = ""; if (num1.length()>num2.length()){ max = num1; min = num2; } else { max = num2; min = num1; } int i; for (i = min.length()-1; i>=0; i--){ sum = min[i] + max[i + max.length() - min.length()] + overage - 2*'0'; overage = sum/10; sum %=10; total = (char)(sum + '0') + total; } if (overage!=0){ total = (char)(overage + '0') + total; } return total; } string multiply(string num1, string num2){ string totalLength= sum(num1, num2); int total = stoi(totalLength); int totalLen = total*total; int product; for(int i =1; i> i; string j; cout << "Please enter another large integer value: "; cin >> j; string add1; add1= sum(i, j); string product1; product1 = multiply(i, j); cout << "The sum of your large integers is: " << add1 <
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
