By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,191 Members | 825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,191 IT Pros & Developers. It's quick & easy.

Searching Multiple Arrays

P: n/a
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[i];
input >first[i];
input >last[i];
input >balance[i];
}

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.

Nov 1 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
VJ
BlackJackal wrote:
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[i];
input >first[i];
input >last[i];
input >balance[i];
}

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.

Try using map or list from STL
Nov 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.