B
BlackJackal
Alright here is the problem I have for homework. I understand most of
it but I am not exactly sure what the problem is asking me to do or how
to search the seperate arrays using the account number to return the
values. Any help would be appreciated I just don't think I understand
what is being asked of me. The problem is as follows
A bank's cusomer records are to be stored in a file and read into a set
of arrays so that an individuals records can be accessed randomly by
account number. Create the file by entering five customer records,
with each record consisting of an integer account number (starting with
account number 1000), a first name having a maximum of 10 characters, a
last name having a maximum of 15 characters, and a floating point
balance.
Once the file is created, write a C++ program that reads the records
into four seperate arrays. The starting address of any element in the
account array can then be calculated as the address of the first record
in the array + (account number - 1000) * sizeof(int). Using this
information, your program should request a user-entered account number
and display the corresponding name and account balance.
Alright I have created the file in question and named it bank.txt
1000 John Bobbit 0.0
1001 Elton John 10000.0
1002 John Lennon 50000.0
1003 Bruce Wayne 200.0
1004 Bob Doyle 0.50
I should be able to read in the information pretty easily using this
code:
ifstream input("bank.dat");
if (input.fail())
{
cout << "ERROR: Cannot open customer record file!" << endl;
exit(1);
}
// Read in the customer records from the file
for (i = 0; i < MAXCUSTOMERS; i++)
{
input >> acts;
input >> first;
input >> last;
input >> balance;
}
input.close();
What I don't understand is how I can link together 4 seperate arrays in
a manner that will allow me to display all four pieces of info just by
using the account number.
it but I am not exactly sure what the problem is asking me to do or how
to search the seperate arrays using the account number to return the
values. Any help would be appreciated I just don't think I understand
what is being asked of me. The problem is as follows
A bank's cusomer records are to be stored in a file and read into a set
of arrays so that an individuals records can be accessed randomly by
account number. Create the file by entering five customer records,
with each record consisting of an integer account number (starting with
account number 1000), a first name having a maximum of 10 characters, a
last name having a maximum of 15 characters, and a floating point
balance.
Once the file is created, write a C++ program that reads the records
into four seperate arrays. The starting address of any element in the
account array can then be calculated as the address of the first record
in the array + (account number - 1000) * sizeof(int). Using this
information, your program should request a user-entered account number
and display the corresponding name and account balance.
Alright I have created the file in question and named it bank.txt
1000 John Bobbit 0.0
1001 Elton John 10000.0
1002 John Lennon 50000.0
1003 Bruce Wayne 200.0
1004 Bob Doyle 0.50
I should be able to read in the information pretty easily using this
code:
ifstream input("bank.dat");
if (input.fail())
{
cout << "ERROR: Cannot open customer record file!" << endl;
exit(1);
}
// Read in the customer records from the file
for (i = 0; i < MAXCUSTOMERS; i++)
{
input >> acts;
input >> first;
input >> last;
input >> balance;
}
input.close();
What I don't understand is how I can link together 4 seperate arrays in
a manner that will allow me to display all four pieces of info just by
using the account number.