## ITprincess

I really need help with this problem. I created a text file with five bank customer records including integer account number(starting with account #1000), first name(max 10 char), last name(max 15 char), and a floating point account balance. Now I need to write a program that reads the records into four separate 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, the program should request a user-entered account number and display the corresponding name and account balance. I am so lost as to how to do this. Please help me.

## Agni 370

y do you have to write this program?

## Ancient Dragon 5,243

>>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).

Are you certain about that statement ? That would imply that all those account number integers are contained in one large character array, not an array of integers.

``````unsigned char accounts[2048]; // room for 512 account numbers

// to store an account number
int acctnr = 1015;
memcpy(&accounts[(accnr-1000)*sizeof(int)], (char*)&acctnr, sizeof(int));

// to retrieve an account number
memcpy(&acctnr, &accounts[(accnr-1000)*sizeof(int)], sizeof(int));``````

## ITprincess

I'm sure about that.

## Ancient Dragon 5,243

Well, that sure is a dumb way to write a problem unless the reason for it is to demonstrate how well you know arrays. No one in his/her right might would write a program llike that in the business world.

At any rate, I suppose the other three arrays are similar to that one ? Such as, the starting address of the name array can be calculated as the address of the first record in the array + (account number - 1000) * MAX_NAME_LENGTH.

The first thing you need to do is declare the arrays

``````unsigned char accounts[512*sizeof(int)]; // room for 512 account numbers
unsigned char firstnames[512*10]; // each first name is 10 characters
unsigned char lastnames[512*15]; // each last name is 15 characters
unsigned char money[512*sizeof(float)]; // 512 floats``````

To access the above just use the formulas I already posted in my previous post.

Next thing is to declare ifstream object and read the file into those arrays. Read your text book to see how to do it. There are also hundreds of examples right here on DaniWeb.