Bank Teller Program - Linear Search Error

I am to write an interactive program in which the user is prompted to create a bank account and able to make transactions to such account. Some requirements are:

When your program begins running, if the files acinfo.dbf and acbal.dbf
exist, it reads data from them and stores the data in parallel arrays.
acinfo.dbf consists of the fields account number, last name, fi rst name,
and middle initial. acbal.dbf consists of two fields: account number
and balance. As the data is read from the acinfo.dbf file, your main
function should count the number of records in the fi le. Note that the
number of records in the fi le corresponds to the number of account
holders (customers). Your program then closes the files. If the files
do not exist, your program simply sets the count of the number of
customers to 0. All of this should be done in the main function.



-The bank is to have no more than 1000 customers
-$25 minimum to open account
-Account balance must be zero in order to close account
-$35 over-draft fee for withdraws greater than account balance

The program must contain the following functions:

1
2
3
4
5
6
7
8
9
10
11
void openAccount(string acno, string fName, string lName, char midInit, double initBal, AccountInfo bankRecord[], int& numAccs)

void closeAccount(string acno,AccountInfo bankRecord[], int& numAccs)

void deposit(string acno, double amount, AccountInfo bankRecord[], int numAccs)

void withdraw(string acno, double amount, AccountInfo bankRecord[], int numAccs)

void inquiry(string acno, const AccountInfo bankRecord[], int numAccs)

void customersList(const AccountInfo bankRecord[], int numAccs)


At the moment, I am returning this error for my desposit and withdraw functions, as well as similar errors regarding the linearSearch function.

In function `void deposit(std::string, double, std::string*, double*, int)': 103 cannot convert `std::string*' to `const AccountInfo*' for argument `2' to `int linearSearch(std::string, const AccountInfo*, int)'

However, in the skeleton code provided by my professor, the linearSearch code was already defined as :
1
2
3
4
5
6
7
8
9
10
 int linearSearch(string acno, const AccountInfo bankRecord[], int numAccs)
 {
    int i;
	for (i=0; i<numAccs; i++)
	{
	   if (acno == bankRecord[i].acNum)
	      return i;
	}
	return -1;
}


I know I still have a lot of work to do but am stumpted for the time being. Any words of wisdom would be greatly appreciated. Thanks.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* @geauxbank.cpp filename
* @Zimmermann, Daniel C.
*/


// put appropriate include directives here

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>

using namespace std;

const int MAX_CUSTOMERS = 1000;
const int OVERDRAFT_FEE = 35;

//define AccountInfo structured type here

struct AccountInfo
{
	string acNum;
	string firstName;
	string midInitial;
	double balance;
};
 
int linearSearch(string acno, const AccountInfo bankRecord[], int numAccs)
{
	int i;
	for (i=0; i<numAccs; i++)
	{
	if (acno == bankRecord[i].acNum)
	return i;
	}
	return -1;
}

void menu()
{
	cout<<setw(22)<<"Geaux Tigers Bank ATM"<<endl;
	cout<<setw(24)<<left;
	cout<<"========================"<<endl;
	cout<<"OPEN AN ACCOUNT......[1]"<<endl;
	cout<<"CLOSE AN ACCOUNT.....[2]"<<endl;
	cout<<"DEPOSIT..............[3]"<<endl;
	cout<<"WITHDRAW.............[4]"<<endl;
	cout<<"BALANCE INQUIRY......[5]"<<endl;
	cout<<"CUSTOMERS LISTING....[6]"<<endl;
	cout<<"EXIT.................[0]"<<endl;
}

void openAccount(string acno,string fName,string lName, char midInit,double initBal,string acNums[], string fNames[],string lNames[],char midInitials[], double balances[],int& numAccs)
{
  	for(int i= numAccs; i<MAX_CUSTOMERS; i++)
  	{
    		acNums[i]= acno;
    		fNames[i]= fName;
    		lNames[i]= lName;
    		midInitials[i]= midInit;
    		balances[i]= initBal;
  	}
  	numAccs++;
}

void closeAccount(string acno,string acNums[],string fNames[], string lNames[],char midInitials[], double balances[],int& numAccs)
{
  	for(int i=numAccs; i<=MAX_CUSTOMERS ;i++)
  	{
    		acNums[i]= acNums[i+1];
    		fNames[i]= fNames[i+1];
    		lNames[i]= lNames[i+1];
    		midInitials[i]=midInitials[i+1];
    		balances[i]= balances[i+1];
  	}
  	numAccs--;
}

void deposit(string acno,double amount,string acNums[],double balances[],int numAccs)
	{
  		int i = linearSearch(acno, acNums, numAccs);
		balances[i]= balances[i]+ amount;
	}

void withdraw(string acno,double amount,const string acNums[],double balances[],int numAccs)
{
	int i=linearSearch(acno, acNums, numAccs);
	if (amount>balances[i])
	{
	balances[i]= balances[i]-amount-OVERDRAFT_FEE;
	}
	else
	balances[i]= balances[i]-amount;
}

void inquiry(string acno,const string acNums[], const string fNames[], const 
		string lNames[], const char midInitials[], const double balances[], 
		int numAccs)
{
	int i = numAccs;
	cout << "------------------------------"<<endl;
	cout << "customer: " << fNames[i] << " " << midInitials[i] << ". " << lNames[i ]<< endl;
	cout << "A/C #: " << acNums[i] << endl;
	cout << "Balance: $" << setprecision(2) << fixed << balances[i] << endl;
	cout << "------------------------------" << endl;
}

void customersList(const string acNums[],const string fNames[], const string lNames[],const double balances[], int numAccs)
{
  	if(numAccs==0)
  	{
    	cout << " *** THERE ARE NO ACTIVE ACCOUNTS ***" << endl;
	}
  	else
  	{
    		cout << " Geaux Tiger Bank, Louisiana LTD" << endl;
    		cout << " Customers Listing" << endl;
    		cout << " 100 Les Miles Dr., Baton Rouge, Louisiana 70802" << endl;
    		cout << "===========================================================" << endl;
    		cout << setw(14) << left << "a/c # " << setw(14) << left;
		cout << "First Name " << setw(14) << left<< "Last Name " << setw(14 )<< "Balance" << endl;
    		cout << "-----------------------------------------------------------" << endl;
  		
		for(int i=0; i<numAccs;i++)
  		{
    			cout << setw(14) << left << acNums[i] << setw(14) << left;
			cout << fNames[i] << setw(14) << left << lNames[i] << setw(14);
			cout << setprecision(2) << fixed << "$" << balances[i] << endl;
  		}
		cout<<"==========================================================="<<endl;
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
int main()
{
	AccountInfo bankRecord[MAX_CUSTOMERS];
	string acno, lName, fName;
	double initBal, amount;
	char midInit;
	int numAccs, pos,option;

	// write code to read data from acinfo.dbf and acbal.dbf. The data
	// should be put in the bankRecord array defined above. The records
	// should be counted as the files are read

	fstream inStrInfo;
	fstream inStrBal;
	fstream outStrInfo;
	fstream outStrBal;
	string fileNameInfo ="acinfo.dbf";
	string fileNameBal = "acbal.dbf";
	string acNums[MAX_CUSTOMERS];
	string lNames[MAX_CUSTOMERS];
	string fNames[MAX_CUSTOMERS];
	char midInitials[MAX_CUSTOMERS];
	double balances[MAX_CUSTOMERS];

	inStrInfo.open(fileNameInfo.c_str(), ios::in);
	inStrBal.open(fileNameBal.c_str(), ios::in);

	if(ifstream("acbal.dbf")&&ifstream("acinfo.dbf"))
	{
		numAccs=0;
		for(int i=0;i>MAX_CUSTOMERS;i++)
		{
			inStrInfo>>acno[i];
			inStrInfo>>lNames[i];
			inStrInfo>>fNames[i];
			inStrInfo>>midInitials[i];
			inStrBal>>acno[i];
			inStrBal>>balances[i];
			numAccs++;
		}
	}
	else
		numAccs=0;
		inStrInfo.close();
		inStrBal.close();

	do 
	{
	menu();
	cout<<endl;
	cout<<"Select an option->";
	cin>>option;
	cout<<endl;
	switch(option)
	{
		case 1:
                cout<<"Enter a 10-character long account number->";
                cin>>acno;
				if (acno.length() != 10)
				{
				   cout<<acno<<" must be 10-character long."<<endl;
				}
				else if (linearSearch(acno,bankRecord,numAccs) > 0)
				{
				   cout<<acno<<" cannot be assigned to multiple customers."<<endl;
				}
				else
				{
				cout<<"Customer's first name ->";
				cin>>fName;
				cout<<"Customer's middle initial ->";
				cin>>midInit;
				cout<<"Customer's last name ->";
				cin>>lName;
				cout<<"Initial Deposit ->";
				cin>>initBal;  
                  
				if (initBal < 25.00)
			   	{
				      cout<<"The initial balance required for a new account must be at least $25.00."<<endl;
				}
				else
				      openAccount(acno,fName,lName,midInit,initBal,bankRecord,numAccs);
				}                       
                break;
            
		//write code to close an account
		  
		case 2:                      
			cout<<"Enter a ten digit account number>"<<endl;
			cin>>acno;
			if(acno.length()!=10)
				cout<<"Account number must be ten digits."<<endl;
			else if(linearSearch(acno,acNums,numAccs)<0)
				cout<<"Account number does not exist"<<endl;
			else
				closeAccount(acno,acNums,fNames,lNames,midInitials,balances,numAccs);
			break;
            
          //write code for a deposit transaction    
		
		case 3:
			cout<<"Enter a ten digit account number>"<<endl;
			cin>>acno;
			if(acno.length()!=10)
				cout<<"Account number must be ten digits."<<endl;
			else if(linearSearch(acno,acNums,numAccs)<0)
				cout<<"Account number does not exist"<<endl;
			else
			{
				cout<<"Enter deposit amount>"<<endl;
				cin>>amount;
			}
			if(amount<=0.00)
				cout<<"Amount must be at least $0.01."<<endl;
			else
				deposit(acno,amount,acNums,balances,numAccs);
			break;             
                
		//write code for a withdrawal transaction
	
		case 4:
			cout<<"Enter a ten digit account number>"<<endl;
			cin>>acno;
			if(acno.length()!=10)
				cout<<"Account number must be ten digits.";
			else if(linearSearch(acno,acNums,numAccs)<0)
				cout<<"Account number does not exist"<<endl;
			else
				cout<<"Enter withdrawal amount>"<<endl;
				cin>>amount;
			if(amount<=0.00)
				cout<<"Amount must be at least $0.01."<<endl;
			else
				withdraw(acno, amount, acNums,balances,numAccs);
			break;
	           
	
		//write code for balance inquiry   
	
		case 5:
			cout<<"Enter a ten digit account number>"<<endl;
			cin>>acno;
			if(acno.length()!=10)
				cout<<"Account number must be ten digits."<<endl;
			else if(linearSearch(acno,acNums,numAccs)<0)
				cout<<"Account number does not exist"<<endl;
			else
				inquiry(acno,acNums,fNames,lNames,midInitials,balances,numAccs);
			break;
	            
		//write code to generate customers list  

		case 6:
			customersList(acNums,fNames,lNames,balances,numAccs);
			break;
		
		case 0:
			break;
			default:
				cout<<"Invalid menu option"<<endl; 
			exit(1);
			break;                   
	}                                                                  
}while (option != 0);
    
	//Write code to overwrite acinfo.dbf and acbal.dbf

	outStrInfo.open(fileNameInfo.c_str(), ios::out);
	outStrBal.open(fileNameBal.c_str(), ios::out);

	if(outStrBal.fail())
		cout<<"File acbal.dbf failed to open."<<endl;
	if(outStrInfo.fail())
		cout<<"File acinfo.dbf failed to open."<<endl;
	else
	{
		numAccs=0;
		for(int i=0;i>MAX_CUSTOMERS;i++)
		{
			outStrInfo>>acno[i];
			outStrInfo>>lNames[i];
			outStrInfo>>fNames[i];
			outStrInfo>>midInitials[i];
			outStrBal>>acno[i];
			outStrBal>>balances[i];
			numAccs++;
		}
	}

	outStrInfo.close();
	outStrBal.close();


return 0;
}

[/code]
In lines 94, 107, 127, 146 you call the linearsearch() with the second argument being acNums, which is a std::string[], not AccountInfo[]! change it!
As I was entering my initial post, I realized I was defining functions other than what is required by the assignment. I am rewriting my code accordingly, but am hitting some roadblocks. I understand the concept behind functions, but still have trouble using them.

Can you point me in the right direction with this one; I don't understand how I receive an error for not defining terms firstName, lastName, midInitial, and balance eventhough they were declared in my struct.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>

using namespace std;

const int MAX_CUSTOMERS = 1000;
const int OVERDRAFT_FEE = 35;

struct AccountInfo
{
	string acNum;
	string firstName;
	string lastName;
	char midInitial;
	double balance;
	string bankRecord[MAX_CUSTOMERS];
};

int linearSearch(string acno, const AccountInfo bankRecord[], int numAccs)
{
	int i;
	for (i=0; i<numAccs; i++)
	{
		if (acno == bankRecord[i].acNum)
			return i;
	}
	return -1;
}

void openAccount(string acno, string fName, string lName, char midInit,
double initBal, AccountInfo bankRecord[], int& numAccs)
{
	for(int i = numAccs; i < MAX_CUSTOMERS; i++)
	{
		acNum[i] = acno;
		firstName[i] = fName;
		lastName[i] = lName;
		midInitial[i] = midInit;
		balance[i] = initBal;
	}
	numAccs++;
}

remember that acNum, firstName, etc are all data members of class AccountInfo. So to access firstName, you need to specify which AccountInfo object you are looking at. In your openAccount(...) function, you are trying to do 'acNum[i] = acno'. Where is the AccountInfo object?? When you called this function, you passed in an array of AccountInfo objects, in the variable bankRecord[]. You need to use that to access each AccountInfo. The logic here seems a little odd to me, but may be correct. For syntax, change
 
acNum[i] = acno;


to

 
bankRecord[i].acNum = acno;


and you should be good!
I think I understand what you're saying. I want to access the information declared in the AccountInfo struct, but have it stored in the bankRecord array. Does that mean I would define the bankRecord array as a member of the AccountInfo struct that calls upon the variables within the AccountInfo struct as well?
No...you may need to review how arrays work.
Topic archived. No new replies allowed.