470,594 Members | 1,523 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

Searching Multiple Arrays

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
1 1670
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.

Similar topics

2 posts views Thread by Bryce Maschino | last post: by
4 posts views Thread by Andrew | last post: by
1 post views Thread by Scott Handojo | last post: by
3 posts views Thread by cs_hart | last post: by
5 posts views Thread by vj | last post: by
5 posts views Thread by Jerim79 | last post: by
5 posts views Thread by lemlimlee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.