#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
struct Detail
{
char FirstName[30];
char LastName[30];
int AccNum;
int pinNum;
float deposit;
float balance;
};
bool readDetail(ifstream& inFile, Detail& det);
void printDetail(const Detail& det);
int main()
{
constint size = 4;
Detail data[size];
ifstream inFile("Data.txt");
// Read from input file into data array
int count = 0;
while (count < size && readDetail(inFile, data[count]))
++count;
// For testing purposes, display entire contents of array.
for (int i=0; i<count; ++i)
printDetail(data[i]);
// Here add code to ask user for Account Number and PIN
// and search the array for matching entry.
return 0;
}
bool readDetail(ifstream& inFile, Detail& det)
{
inFile >> det.pinNum >> det.AccNum
>> det.FirstName >> det.LastName >> det.balance;
det.deposit = 0; // initialise value not in file.
returnbool(inFile);
}
void printDetail(const Detail& det)
{
cout << det.pinNum << '\t'
<< det.AccNum << '\t'
<< det.FirstName << ' ' << det.LastName << '\t'
<< det.balance << '\n';
}
Notice function printDetail() processes just a single item from the array. This seems like the way the other functions should work as well (remove const if the values should be modified, such as deposit or withdrawal).
I used this data.txt for testing:
1234 123456789 NANA HANA 50000.00
4567 987654321 KIM NAMJOON 50000.00
1309 234567890 KIM TAEHYUNG 50000.00
1111 877546352 NANA YODA 50000.00