Not sure how much is needed but here is everything I've written so far.
Code:
void main()
{
string number;
cout << "Enter the first number\n";
cin >> number;
LongInt *firstnumber = storenumber(number);
cout << "Your number is ";
print_result(*firstnumber);
cout<<"and has "<< firstnumber->digits()<<" digits\n";
cout<<"Enter the second number\n";
cin >> number;
LongInt *secondnumber = storenumber(number);
LongInt result = firstnumber->add(*secondnumber);
print_result(result);
}
Code:
LongInt LongInt::add(const LongInt& otherInt)
{
LongInt result;
ADTList *otherList = otherInt.mlist;
ADTList *resultList = result.mlist;
node *myNode = mlist->first_right();
node *otherNode = otherList->first_right();
int addition = myNode->value + otherNode->value;
int carry = overFlow(addition);
resultList->insert_last(addition);
while(!mlist->isFirst(myNode) && !otherList->isFirst(otherNode))
{
myNode = mlist->next_left(myNode);
otherNode = otherList->next_left(otherNode);
addition = myNode->value + otherNode->value + carry;
carry = overFlow(addition);
resultList->insert_last(addition);
}
return result;
}
Code:
class LongInt {public:
int sign;
ADTList *mlist;
LongInt(){mlist = new ADTList();};
~LongInt(){delete mlist;};
int getsign(){return sign;};
void setsign(int i){if(i>0) sign=1; else sign = 0;};
LongInt add(const LongInt&);
void clear(){delete mlist; mlist = new ADTList();};
int digits(){ int i = 0; node *count = mlist->first_right(); if(!count) return 0; else{while(count->prev){count=count->prev;i=i+8;} int j=count->value;
while(j>0){ j=j/10;i++; }}return i;}
};
Code:
class ADTList
{
public:
node *head;
ADTList(){head = 0;};
~ADTList(){ cout<<"Why is this being called\n"; node *cp = first_right(); while(cp!=0){node *next = cp->next; delete cp; cp=next;}}
node *first_right(){ node *cp=head;
if(!cp) return 0;
if(!cp->next) return cp;
while(cp->next) cp=cp->next;
return cp;}
node *first_left(){ node *cp=head; if(!cp) return 0; if(!cp->prev) return cp; while(cp->prev) cp=cp->prev; return cp;}
node *next_right(node *cp){return cp->next;}
node *next_left(node *cp) {return cp->prev;}
int isFirst(node *cp){if(cp==first_left()) return 1; else return 0;}
int isLast(node *cp) {if(cp==first_right()) return 1; else return 0;}
void insert_first(int number){ if(!head){head=new node; head->prev=head->next = 0; head->value = number%100000000;}
else{ node *tp = first_right(); tp->next = new node; tp->next->prev = tp; tp->next->next = 0; tp->next->value = number%100000000;}}
void insert_last(int number) { if(!head){head=new node; head->prev=head->next = 0; head->value = number%100000000;}
else{node *tp = first_left(); tp->prev = new node; tp->prev->next = tp; tp->prev->prev = 0; tp->prev->value = number%100000000;}}
};