Question: Implement a fully working overloaded division and modulo operators of a LargeInteger class representing numbers as a DoublyLinkedList class. Assume you have a proper DoublyLinkedList
Implement a fully working overloaded division and modulo operators of a LargeInteger class representing numbers as a DoublyLinkedList class. Assume you have a proper DoublyLinkedList API available. Use the code of the LargeInt below. Current implementation of the division and modulo fails. Assume you have all other operators properly implemented, don't look at my current formatting as it might be bad due to me just pasting the code to fit the character limit:
class LargeInt
private:
DoublyLinkedList digits;
public:
Constructor
LargeIntconst std::string& str
for char c : str
if std::isdigitc
digits.insertBackc ;
LargeInt operatorconst LargeInt& a const LargeInt& b
if b LargeInt
throw std::runtimeerrorDivision by zero";
if a b
return LargeInt;
LargeInt quotient;
LargeInt remainder;
LargeInt dividend a;
int numdigits adigits.size bdigits.size;
for int i ; i numdigits; i
remainder.digits.insertBackdividenddigits.begin;
dividend.digits.deleteItemdividenddigits.begin;
int digit ;
while remainder b
remainder remainder b;
digit;
quotient.digits.insertBackdigit;
while quotient.digits.isEmpty && quotientdigits.begin
quotient.digits.deleteItemquotientdigits.begin;
if quotientdigits.isEmpty
quotient.digits.insertBack;
return quotient;
Modulo operator
LargeInt operatorconst LargeInt& a const LargeInt& b
if b LargeInt
throw std::runtimeerrorDivision by zero";
LargeInt remainder a;
while remainder b
LargeInt temp b;
int count ;
while remainder temp
temp.digits.insertBack;
count;
temp.digits.deleteItemtempdigits.size;
count;
remainder remainder temp;
return remainder;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
