Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
please help me out in function coding. Thanks in advance.

C#
#include <iostream>
#include <cstring>
using namespace std;

class ListNode{
    private:
        int data;
        ListNode * next;
    public:
        ListNode(){}
        ListNode(int num){
            data=num;
            next = NULL;
        }
        int getData();
        void setData(int);
        void setNext(ListNode *);
        ListNode* getNext();
};
/*
*Implementation of Node Methods
*/
int ListNode::getData(){
        return data;
}
void ListNode::setData(int x){
        data = x;
}
ListNode * ListNode::getNext(){
        return next;
}
void ListNode::setNext(ListNode * P){
        next = P;
}
/***End Of Node Methods Implementation**/

class List{
    private:
        ListNode * Head;
    public:

        List(){
            Head=NULL;
        }
        ~List(){}
         /*Already Implemented Methods.You can use them in your
                 *functions
                 **/
        ListNode * getHead();
        void setHead(ListNode *);
        ListNode * last();
        void append(int);
        void prepend(int);
        void popBack();
        void print();
        void copy(List);
        void printReverse();    //prints the list from Tail to Head.

        /*Implement the follwing if required. Not mandatory*/

        ListNode * prevNode(ListNode* P);
        void popFront();

};
/*
****List Methods Implementaion***
*/
ListNode * List::getHead(){
        return Head;
}

ListNode * List::last(){
        ListNode * temp=Head;
        if(Head==NULL) return NULL;
        while(temp->getNext()!=NULL){
            temp=temp->getNext();
        }
        return temp;
}
void List::setHead(ListNode * P){
        Head = P;
}
void List::append(int num){
        ListNode * new_node = new ListNode(num);
        ListNode * temp=Head;
        if(temp==NULL){
            Head = new_node;
            return;
        }
        while(temp->getNext()!=NULL) temp=temp->getNext();
        temp->setNext(new_node);
}
void List::prepend(int num){
        ListNode * new_node = new ListNode(num);

        new_node->setNext(Head);
        Head = new_node;
}
/*
*Removes the Tail Node
*/
void List::popBack(){
        ListNode * temp=Head,*prev=NULL;
        //NULL list
        if(Head==NULL){cout<<"List is Empty\n";}
        //single element
        if(Head->getNext()==NULL){
            delete Head;
            Head=NULL;
            return;
        }
        while(temp->getNext()!=NULL){
            prev = temp;
            temp=temp->getNext();
        }
        delete temp;
        prev->setNext(NULL);
}
void List::print(){
        ListNode * temp=Head;
        while(temp!=NULL){
            cout<<temp->getData();
            temp=temp->getNext();
        }
}
//copy values of L into this list
void List::copy(List L){
        Head = NULL;
        ListNode * temp = L.Head;
        while(temp!=NULL){
            this->append(temp->getData());
            temp=temp->getNext();
        }
}

void List::printReverse(){
        ListNode * curr=Head;
        ListNode * prev_last=NULL;

        while(Head!=NULL && prev_last!=Head){
            curr = Head;
            while(curr->getNext()!=prev_last){
                curr = curr->getNext();
            }
            cout<<curr->getData();
            prev_last = curr;
        }
}

/*****End Of List Methods Implementation************************/

/* This is the data type you need to write the required methods*/
class BigInt{
   private:
        List L;
   public:
       BigInt(){}
       ~BigInt(){}
      /*Must write code for append(),prepend(), add(), print() Methods*/
       void append(int num);
       void prepend(int num);
       BigInt add(BigInt A);
       void print();//mandatory

       /*Helper Functions, not mandatory to implement
       *Hint: Implement removeZeroes(), call it in print().
       */
       void removeZeroes();
       void copy(BigInt B);

};



void populate(BigInt &A, char * str){
   //CODE
}
void BigInt::append(int num){
  //CODE
}
void BigInt::prepend(int num){
   //CODE
}

BigInt BigInt::add(BigInt A){
     //CODE
}

void BigInt::removeZeroes(){
     /**write your code here
      *Hint: Implement removeZeroes(), call it in print().
      */
}
void BigInt::print(){
    //CODE
}

int main(){

      char str[40];
      BigInt A,B;
      cin>>str;
      populate(A,str);

      cin>>str;
      populate(B,str);

      (A.add(B)).print();

      return 0;
}
Posted
Comments
Sergey Alexandrovich Kryukov 8-Apr-14 1:37am    
Help with what. Do you have any questions?
—SA
Member 10006194 8-Apr-14 3:23am    
I am not getting as to how I should go about coding the big int functions before main.

1 solution

We don't do your homework; it is set for a reason.

Try it yourself, it may be easier than you think!
 
Share this answer
 
Comments
Member 10006194 8-Apr-14 3:27am    
This is not my home work and with all the toiled efforts, I could not find a solution ,for the reason being I have posted it here. Anyways thanks for your comment. I know you are not here to do my home work that is the reason I built my whole code and when I could not proceed I asked for help.
OriginalGriff 8-Apr-14 4:02am    
You are trying to tell me they pay you to write code like that?
Wow! Maybe I should change jobs - yours is certainly easier than mine...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900