are to write the code for the addLongInt function. Other parts of the program should not be changed. You should model your solution on the string adder program that you wrote for mp-0. Your changes will result from the fact that the string adder program uses strings to represent arbitrarily large integers and this program uses doubly linked lists and here you will be doing addition base ten.. MUST write the program by supplying the missing code to the partial program supplied. The only allowed change is that you

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

This program implements integer addition with arbitrarily large integers.
Integers are implemented as doubly linked lists where each link represents one
digit. You are to write the code for the addLongInt function. Other parts of
the program should not be changed. You should model your solution on the
string adder program that you wrote for mp-0. Your changes will result from
the fact that the string adder program uses strings to represent arbitrarily
large integers and this program uses doubly linked lists and here you will be
doing addition base ten.. MUST write the program by supplying the missing
code to the partial program supplied. The only allowed change is that you
may remove using namespace std;, replace cin with std::cin and replace
cout with std::cout.

Test data:
-> 99999999999999999999
-> 1

-> 1
-> 99999999999999999999


-> 123456789123456789

-> 111111111111111111


-> 88888888888888888888

-> 22222222222222222222


-> 9000000000000000000000009

-> 9999999999999999999999999


-> 9999999999999999999999999
-> 9999999999999999999999999

 

#include<iostream>
using namespace std;

class LongInt {
private:
    struct digit {
        int d_val;
        digit *more, *less;
    };

    struct Ibase {
     digit *most, *least;
    };

    Ibase _base;
   
    void zeroStrip( );

public:
    LongInt();
    friend void printLongInt( LongInt );
    friend LongInt inputLongInt( );
    friend LongInt addLongInt( LongInt, LongInt );
};

void LongInt::zeroStrip( ){
    LongInt::digit * dptr = _base.most;
    LongInt::digit * extra = 0;

    while( ( !dptr->d_val ) && dptr->less ) {
        extra = dptr;
        _base.most = dptr->less;
        dptr = dptr->less;
        dptr->more = 0;
        delete extra;
    }
}

LongInt::LongInt(){
    _base.most = _base.least = new digit;
    _base.most->d_val = 0;
    _base.most->more = _base.most->less = 0;
};

void printLongInt( LongInt LIval ){
    LongInt::digit * dptr = LIval._base.most;

    while ( dptr ) {
        cout << dptr->d_val;
        dptr = dptr->less;
    }
}

LongInt inputLongInt( ){
    LongInt returnValue;
    int inValue;
    LongInt::digit * dptr = 0;
    LongInt::digit * inputList = 0;
    inputList = returnValue._base.least;

    inValue = cin.get();

    while ( '0' <= inValue && inValue <= '9' ){
            dptr = new LongInt::digit;
            dptr->d_val = inValue - '0';
            dptr->less = 0;
            dptr->more = inputList;
            returnValue._base.least = dptr;
            inputList->less = dptr;
            inputList = dptr;
            inValue = cin.get();
    }

    returnValue.zeroStrip( );

return returnValue;
}

LongInt addLongInt( LongInt s1, LongInt s2) {
/*
Supply missing code for this function.
*/
 
}

int main(){
LongInt summand1, summand2, sum;
cout << "-> " << flush;
summand1 = inputLongInt();
cout << "-> " << flush;
summand2 = inputLongInt();
cout << "\n-----\n";
sum = addLongInt( summand1, summand2 );
printLongInt( sum );
cout << endl;
}


Expert Solution
steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education