#include "AcctListList.h" #include "AcctListNode.h" int PickRand(int max) { int random = rand() % max; return random; } void wait() { char wait; clog << "Waiting for you - type char and return> " << flush; cin >> wait; return; } int main() { // part for assignment - testing new operators // create empty lists and show them cout << "create empty lists and show them" << endl; AcctList myList; cout << "myList has " << myList.size() << " elements " << endl; myList.ShowList(); AcctList myOtherList; cout << "myOtherList has " << myOtherList.size() << " elements " << endl; myOtherList.ShowList(); wait(); int cnt; // add five accounts to both lists, depositing a random amount between 0 and 1999 in each for (cnt = 0; cnt < 5; cnt++) { Account newOne; int amount = PickRand(2000); newOne.Deposit(amount); myList.push_back(newOne); Account newTwo; amount = PickRand(2000); newTwo.Deposit(amount); myOtherList.push_back(newTwo); } // show the lists then wait cout << "show two lists with random acct#s and random deposits" << endl; cout << "myList has " << myList.size() << " elements " << endl; myList.ShowList();; cout << "myOtherList has " << myOtherList.size() << " elements " << endl; myOtherList.ShowList(); wait(); //AcctList myList; cout << "myList has " << myList.size() << " elements " << endl; myList.ShowList(); //int cnt; cout << "Add three default accounts to end of myList" << endl; for (cnt = 0; cnt < 3; cnt++) { Account newOne; myList.push_back(newOne); cout << "myList has " << myList.size() << " elements " << endl; myList.ShowList(); } wait(); // try depositing random amount between 0 and 2000 // dont have iterators - must deal with pointers to nodes (called AccountLink s) cout << "Depositing more money to accounts in myList" << endl; AcctNode * acctPtr; for (acctPtr = myList.begin(); acctPtr != 0; acctPtr = acctPtr->NextNode() ) { int amount = PickRand(2000); acctPtr->GetValue().Deposit(amount); } cout << "myList has " << myList.size() << " elements " << endl; myList.ShowList(); wait(); // save a copy of the list of accounts for safe keeping cout << "save a copy of the list of accounts for safe keeping" << endl; AcctList listCopy(myList); // now add some to the front cout << "now add three default accounts to the front of myList" << endl; for (cnt = 0; cnt < 3; cnt++) { Account newOne; myList.push_front(newOne); cout << "myList has " << myList.size() << " elements " << endl; myList.ShowList(); } wait(); cout << "Removing " << myList.back() << " from list " << endl; myList.pop_back(); cout << "myList has " << myList.size() << " elements " << endl; myList.ShowList(); wait(); cout << "listCopy has " << listCopy.size() << " elements " << endl; listCopy.ShowList(); return 0; }