/* * Name: bankAccounNode.cpp * Function: implementation of the class bankAccountNode * Author: Hui Yang * Date: Oct. 2008 /* In plain English: Create a class in a class and start with *head newclasshere. That class is going to have the bank data and functions. Submission instruction: for this homework, you only need to submit the electronic copy, i.e., the zip file, on iLearn. Due by: 11:55PM, Friday, November 21 Problem description: The source code posted under Week #11 implements a linked list of bank accounts in its simplest form. However, this program only implements each individual node as an object of the class BankAccountNode. Instead of implementing a linked list as an abstract data type (i.e., class), this program declares a linked list as a pointer (i.e., the head pointer) and then uses standalone functions to manipulate such a linked list. In this homework, you are required to implement such a linked list as an abstract data type listBankAccount, which consists of the following functions: * Initialization: define at least one constructor to initialize a linked list. // seems to be okay * frontInsert(): insert a node to the front of a list. // renamed, uncertain about implementation * endInsert(): insert a node to the end of a list. // renamed, uncertain about implementation * isEmpty(): check whether a list is empty. // not implemented anywhere. * searchAccount(): search whether a node is on the list given an account ID. // renamed, uncertain about implementation * updateAccount(): given an account ID, first search whether it exists on the list. If yes, update its checking balance as specified by a parameter. // not implemented anywhere. * deleteAccount(): given an account ID, first search whether it exists on the list. If yes, delete this node. // deleteLink might be related. I'm unsure. * printList(): print all the nodes on a list. // not implemented anywhere * destructor: release a linked list to the freestore. // Not implemented anywhere. Write a test driver to test your code. Note: you can reuse the source code posted on iLearn. */ #include "BankAccountNode.h" BankAccountNode::BankAccountNode(int acctId, double amt1, double amt2, BankAccountNode *nextNode) { id = acctId; checking = amt1; saving = amt2; next = nextNode; }// BankAccountNode::BankAccountNode() { id = 0; checking = 0.0; saving = 0.0; next = NULL; }// void BankAccountNode::output() const { cout << "(id, checking, saving, last-node) = (" << id << ", " << checking << ", " << saving <<", "; if (next==NULL) cout << "yes )\n"; else cout << "no )\n"; }// int BankAccountNode::getId() const { return id; }// double BankAccountNode::getChecking() const { return checking; }// double BankAccountNode::getSaving() const { return saving; }// BankAccountNode* BankAccountNode::getNext() const { if (this == NULL ) return NULL; return next; }// void BankAccountNode::setAccount(int acctId, double amt1, double amt2, BankAccountNode *nextNode) { id = acctId; checking = amt1; saving = amt2; next = nextNode; }// void BankAccountNode::setId(int acctId) { id = acctId; }// void BankAccountNode::setChecking(double amt) { checking = amt; }// void BankAccountNode::setSaving(double amt) { saving = amt; }// void BankAccountNode::setAccount(double amt1, double amt2) { checking = amt1; saving = amt2; }// void BankAccountNode::setNext( BankAccountNode *nextNode) { (*this).next = nextNode; }// ostream& operator << (ostream& outputSrc, BankAccountNode& acct) { outputSrc << " Checking=$"<getId() == acctId ) return curr; curr = curr->getNext(); }// return NULL; }// //return: number of nodes or the length of a link int traverseLink( BankAccountNode *head ) { int cnt=0; BankAccountNode *curr=NULL; curr = head; while (curr!=NULL){ cnt += 1; cout << "Node " << cnt <<": "; curr->output(); curr = curr->getNext(); }// return cnt; }// //add a node to the front of the list BankAccountNode *frontInsert ( BankAccountNode *head, BankAccountNode *newNode) { newNode->setNext( head ); return newNode; }// //add a node to the end of the list BankAccountNode *endInsert( BankAccountNode *head, BankAccountNode *newNode) { BankAccountNode *last=NULL; if ( head->getNext() == NULL )//one node on the list last = head; else{ last = head->getNext(); while ( last->getNext() != NULL ) last = last->getNext(); } last->setNext( newNode ); return head; }// void deleteLink( BankAccountNode *head ) { BankAccountNode *toDelete=NULL, *next=NULL; toDelete = head; while ( toDelete!= NULL ){ next = toDelete->getNext(); delete toDelete; toDelete = NULL; toDelete = next; }//while }// BankAccountNode * lastNode( BankAccountNode *head) { BankAccountNode *last = NULL; if ( head->getNext() == NULL )//one node on the list last = head; else{ last = head->getNext(); while ( last->getNext() != NULL ) last = last->getNext(); } return last; }