in c++ language
Take what you did for lab 5 and replace the vector with a dynamic array. You will probably have to add a size variable to the class as well. Also write a copy constructor, operator and destructor for the big_num class. vocstartsoft:~/environment/Lab6 $ ./BigNum Enter a number: 98347901287 Enter a number: 38120383 98347901287 + 38120383 = 98386021670 vocstartsoft:-/environment/Lab6 $ ./BigNum Enter a number: 99999 Enter a number: 1 99999 + 1 = 100000 vocstartsoft:-/environment/Lab6 $ ./BigNum Enter a number: 321 Enter a number: 38120383 98347901287 + + 38120383 = 98386021670 vocstartsoft:-/environment/Lab6 $ ./BigNum Enter a number: 99999 Enter a number: 1 99999 + 1 = 100000 vocstartsoft:~/environment/Lab6 $ ./BigNum Enter a number: 321 Enter a number: 82344234789 321 82344234789 = 82344235110 vocstartsoft:-/environment/Labo $ + When you are finished submit you big_num.h file Using the above header and driver files big_num.cpp #include "big_num.h" using namespace std; / constructor to initialize the big_num to given number as string big_num:: big_num(std::string num) // loop over the string for(size_t i=0;i
/overloaded insertion operator to output bn to out std::ostream& operator= 0 && i >= 0) { result[i] = result[] + n201 // add ith digit of result to th digit of n2 if(carry) // carry flag is true, add 1 to ith digit of result result[i] = result[i] + 1; if(result[i] > 9) // there is an overflow carry = true; // set carry to true else // no overflow, set carry to false carry = false; // set ith digit of result to modulus of 10 so that digit remains between (0,9) result[i] = result[]%10; // decrement i andi } int n; Il if has not reached the end of n2 while(j >=0) { n = n260; // set n to jth digit of n2 if(carry) // carry flag is set, add 1 ton { false } Il n > 9, set carry flag to true else set it to if(n > 9) carry = true; else carry = false; n=n%10; // reduce n between 10,9) I insert n as the first digit of result result. digits.insert(result.digits.begin(),n); il decrement by 1 } // loop that continues until i has reached end or carry 10:4 n++ lln> 9, set carry flag to true else set it to false if(n > 9) carry = true; else carry = false; n=n%10; // reduce n between (0,9) I insert n as the first digit of result result digits.insert(result digits.begin(),n); -- // decrement j by 1 > // loop that continues until i has reached end or carry flag is not set while(i >= 0 && carry) result[i] = result[i] +1; // add 1 to ith digit of result if(result[] > 9) // overflow, set carry flag { carry = true; result[i] = result[]%10; // reduce ith digit of result between 10,9) Jelse // no overflow carry = false; // decrement i by 1 } Il carry is still set, insert 1 as the first digit of result if (carry) result.digits.insert(result.digits.begin(),1); llend of big_num.cpp return result; } Output: Enter a number: 98347901287 Enter a number: 38120383 98347901287 + 38128383 - 98386821670 Enter a number: 99999 Enter a number: 1 99999 + 1 = 100000 Enter a number: 321 Enter a number: 82344234789 321 +82344234789 = 82344235110 #include #include #include #incl/de "big_num.h" int main() { std::string str; std::cout /overloaded insertion operator to output bn to out std::ostream& operator= 0 && i >= 0) { result[i] = result[] + n201 // add ith digit of result to th digit of n2 if(carry) // carry flag is true, add 1 to ith digit of result result[i] = result[i] + 1; if(result[i] > 9) // there is an overflow carry = true; // set carry to true else // no overflow, set carry to false carry = false; // set ith digit of result to modulus of 10 so that digit remains between (0,9) result[i] = result[]%10; // decrement i andi } int n; Il if has not reached the end of n2 while(j >=0) { n = n260; // set n to jth digit of n2 if(carry) // carry flag is set, add 1 ton { false } Il n > 9, set carry flag to true else set it to if(n > 9) carry = true; else carry = false; n=n%10; // reduce n between 10,9) I insert n as the first digit of result result. digits.insert(result.digits.begin(),n); il decrement by 1 } // loop that continues until i has reached end or carry 10:4 n++ lln> 9, set carry flag to true else set it to false if(n > 9) carry = true; else carry = false; n=n%10; // reduce n between (0,9) I insert n as the first digit of result result digits.insert(result digits.begin(),n); -- // decrement j by 1 > // loop that continues until i has reached end or carry flag is not set while(i >= 0 && carry) result[i] = result[i] +1; // add 1 to ith digit of result if(result[] > 9) // overflow, set carry flag { carry = true; result[i] = result[]%10; // reduce ith digit of result between 10,9) Jelse // no overflow carry = false; // decrement i by 1 } Il carry is still set, insert 1 as the first digit of result if (carry) result.digits.insert(result.digits.begin(),1); llend of big_num.cpp return result; } Output: Enter a number: 98347901287 Enter a number: 38120383 98347901287 + 38128383 - 98386821670 Enter a number: 99999 Enter a number: 1 99999 + 1 = 100000 Enter a number: 321 Enter a number: 82344234789 321 +82344234789 = 82344235110 #include #include #include #incl/de "big_num.h" int main() { std::string str; std::cout