hello all! i am working on a bank account type program where the user can add accounts delete accounts make deposits and so on. i have most of the code working but i am getting an error and i cant figure out whats wrong. if someone could steer me in the right direction on how i could fix it that would greatly appreciated.
the error im getting is:
C:\Users\kevin jack\Desktop\hume\prog1>g++ -o prog1.exe acctListMain.cpp
acctListMain.cpp: In function `int main()':
acctListMain.cpp:69: error: expected primary-expression before '.' token
acctListMain.cpp file:
/**********************************************
* Prog 1
Kevin Jack
*
*
**********************************************/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cctype>
#include "acctList.H"
using namespace std;
void displayMenu();
int main()
{
bool menuActive = true;
char menuChoice;
AcctList acctList;
while (menuActive)
{
displayMenu (); // call displayMenu function
cin >> menuChoice; cin.ignore(80,'\n');
cout << endl;
switch (menuChoice)
{
case '1': case 'A': case 'a':
{
int acctNumInput; int acctBalanceInput=0; string acctNameInput;
cout << "Enter account number: ";
cin >> acctNumInput; cin.ignore(80,'\n');
cout << "Enter account name: ";
getline(cin, acctNameInput);
cout << "Enter account Balance: ";
cin >> acctBalanceInput; cin.ignore(80,'\n');
bool success = acctList.addNode(acctNumInput, acctBalanceInput, acctNameInput);
if (success == false)
cout << "\n *** Addition fails: duplicate account number ***" << endl;
}
break;
case '2': case 'D': case 'd':
if (acctList.listEmpty())
cout << "\n List empty: no deletions possible \n\n";
else
{
int acctNumInput;
cout << "Enter account number: ";
cin >> acctNumInput; cin.ignore (80,'\n');
bool success = acctList.deleteNode(acctNumInput);
if (success == false)
cout << "\n *** Deletion fails: account number not found ***" << endl;
}
break;
case '3': case 'P': case 'p':
acctList.printListByAcctNum();
break;
case '4': case 'M' : case 'm':
{
int acctNumInput;
cout<<"Enter account number: ";
cin>>acctNumInput; cin.ignore (80,'\n');
bool success = AcctList.makeDeposit(acctNumInput);
if (success == false)
cout << "\n *** Deposit fails: account number not found ***" << endl;
}
break;
case '5': case 'F': case 'f':
acctList.readFile();
break;
case '6': case 'Q': case 'q':
menuActive = false; // Finish this series of menu choices
break;
default:
cout << " Invalid menu choice: try again!" << endl << endl;
} // end switch statement
}
return 0;
}
void displayMenu ()
{
cout << " *************************************************" << endl;
cout << " * *" << endl;
cout << " * M A I N M E N U *" << endl;
cout << " * *" << endl;
cout << " * 1) (A)dd Account *" << endl;
cout << " * 2) (D)elete Account *" << endl;
cout << " * 3) (P)rint List by Account Number *" << endl;
cout << " * 4) (M)ake Deposit *" << endl;
cout << " * 4) (F)ile: read Input File *" << endl;
cout << " * 5) (Q)uit: Finish processing this array *" << endl;
cout << " * *" << endl;
cout << " *************************************************" << endl;
cout << " Enter choice: ";
} // end displayMenu function
the acctList.h file:
/***********************************************************************
* AcctList.h
*
* Author Kevin Jack
*
*
*
*
***********************************************************************/
#ifndef ACCT_LIST_H
#define ACCT_LIST_H
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cctype>
#include <string>
using namespace std;
struct ListNode
{
int acctNum;
string acctName;
int acctBalance;
ListNode *next;
};
typedef ListNode* nodePtr;
class AcctList
{
private:
AcctList (double balance, int acctBalance = 0, int acctNum, string acctName);
int numElements;
nodePtr head;
public:
AcctList ()
{ numElements = 0; head = NULL; }
bool listEmpty ()
{ return (numElements == 0); }
void printListByAcctNum ()
{
int count = 0;
cout << "\n List in Account Number Order \n\n";
nodePtr p = head;
while (p != NULL)
{
count++;
cout << setw(4) << right << count << ". ";
cout << "Account Number: " << setw(8) << right << p->acctNum;
cout << " Account Name: " << left << p->acctName;// << endl << endl;
cout<<" Account Balance: "<<p->acctBalance;
p = p->next;
}
if (numElements == 0)
cout << "\n List is empty \n\n";
}
bool searchListByAcctNum (int searchKey, nodePtr *prevOut)
{
bool found = false;
nodePtr p = head;
nodePtr prev = NULL;
while (p != NULL)
{
if (p->acctNum < searchKey)
{
prev = p;
p = p->next;
}
else
{
if (p->acctNum == searchKey)
found = true;
p = NULL; //stop the search. "prev" has its proper value
}
}
*prevOut = prev;
return found;
}
void linkNodeByAcctNum (ListNode* newNode, ListNode* prevNode)
{
if (prevNode == NULL) // insert as first node in acctNum linkage
{
newNode->next = head;
head = newNode;
}
else
{
newNode->next = prevNode->next;
prevNode->next = newNode;
}
}
bool addNode (int acctNumInput,int acctBalanceInput, string acctNameInput)
{
bool successfulAddition = false;
nodePtr p, prev;
p = new ListNode; // default constructor
p->acctNum = acctNumInput;
p->acctName = acctNameInput;
p->acctBalance = acctBalanceInput;
bool acctNumFound = searchListByAcctNum(acctNumInput,&prev);
if (acctNumFound)
{
cout<<endl<<"BANK ACCOUNT NUMBER "<<acctNumInput<< " COULD NOT BE";
cout<<" ADDED BECAUSE THE ACCOUNT ALREADY EXISTS!"<<endl;
return true;
};
if (!acctNumFound)
{
successfulAddition = true;
numElements++;
linkNodeByAcctNum(p, prev);
}
return successfulAddition;
}
bool makeDeposit(int acctNumInput, int acctBalance)
{
bool successfulDeposit = false;
nodePtr p, prev;
bool acctNumFound = searchListByAcctNum(acctNumInput, &prev);
if (acctNumFound)
{
successfulDeposit=true;
int amount=0;
cout<<"Enter deposit amount";
cin>>amount;
acctBalance = acctBalance + amount;
cout<< acctBalance;
}
return true;
}
bool deleteNode(int acctNumInput)
{
bool successfulDeletion = false;
nodePtr p, prev;
bool acctNumFound = searchListByAcctNum(acctNumInput, &prev);
if (acctNumFound)
{
successfulDeletion = true;
numElements--;
if (prev == NULL) // deleting first node in list
{
p = head;
head = p->next;
delete p;
}
else //deleting node after the first node
{
p = prev->next;
prev->next = p->next;
delete p;
}
}
return successfulDeletion;
}
void readFile()
{
char transactionCodeInput;
int acctNumInput;
string acctNameInput;
int acctBalanceInput;
char filename[50];
fstream accountFile;
do
{
cout << "Enter filename of account file: ";
cin.getline (filename,51);
accountFile.open(filename);
if (accountFile.fail())
cout << "File could not be opened" << endl;
accountFile.clear();
}
while (accountFile.fail());
accountFile.clear();
while (!accountFile.eof()) // file successfully opened at this point
{
accountFile >> transactionCodeInput >> acctNumInput; accountFile.ignore(10,';');
getline (accountFile, acctNameInput, ';');
accountFile >> acctBalanceInput; accountFile.ignore (80, '\n');
if (toupper(transactionCodeInput) == 'A') // add account
{
bool success = addNode(acctNumInput, acctBalanceInput, acctNameInput);
if (success == false)
cout << "\n *** Addition fails: duplicate account number ***" << endl;
}
if (toupper(transactionCodeInput) == 'D') // delete account
{
bool success = deleteNode(acctNumInput);
if (success == false)
cout << "\n *** Deletion fails: account number"<< acctNumInput<<" not found ***" << endl;
}
} // end of while loop
}
};
#endif