Need help creating functions .h file

I already have most of the code for this following program
Write a program that loads bank balance information from a file and then allows transactions
against those accounts. Finally, save the account info back out to the file.
o When the program starts, ask the user for the account file they want to
o Read the file the user indicated – it consists of ids, names and dollar amounts – you can
assume that all the names will be one word!
o Create three parallel arrays to store the account info (one of account id’s (int), one of
names (string) and one of account balance (float) ) – assume a maximum number of
entries of 50 (use a const variable to contain this number).
o Write a menuing system with the following options:
 (M)odify amount – ask the user for an id and an amount to modify by – report
back to the console the name and current balance after modification
 (R)eport – write out all account info for all accounts
 (E)xit and save – exit the menu loop and save the accounts back to the
accounts.txt file
o Make sure you can load that accounts.txt file again by running the program again.
o Write the following functions:
 int loadData( string filename, int ids[], string names[], float balances[] );
• load all data from file filename into the passed in arrays – return the
number of accounts read
 int getIndex( int theID, int ids[], int numAccounts );
• go through the passed in array of ids and find the index of passed in id.
Return that index. Return -1 if not found.
 void modifyBalance( int index, float balances[], float amount);
• modify the balance in balances at the index by the amount passed in
 void reportAccountInfo( int index, int ids[], string names[], float balances[] );
• write to the console the id, name, and balance for the given account
index
 void reportAllAccountInfo( int ids[], string names[], float balances[], int
numAccounts);
• write to console account info for all accounts
 void saveAccounts(string filename, int ids[], string names[], float balances[], int
numAccounts );
• write to filename file all account info
o Create a separate .cpp/.h pairing called functions.h/.cpp for all your functions and
prototypes.

Im just very stuck on the functions part of it my professor hasnt done very well at teaching us functions but this the code that I have so far..
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(){
int option;
fstream accountFile;
int id[50] = {0}, i = 0, size, flag;
string names[50];
char c;
float balances[50];
cout << "Which file would you like to access?" << endl;
cout << "1. accounts1.txt" << endl;
cout << "2. accounts2.txt" << endl;
cin >> option;
switch(option){
case 1: accountFile.open("accounts1.txt");
while(accountFile >> id[i]){
accountFile >> names[i];
accountFile >> balances[i];
++i;
}
size = i;
flag = 1;
while(flag){
cout << "Select an option: " << endl;
cout << "(M)odify amount" << endl;
cout << "(R)eport" << endl;
cout << "(E)xit and save" <<endl;
cin >> c;
switch(c){
case 'M': int userId;
float amount;
cout << "Enter the user id and amount: ";
cin >> userId >> amount;
for(int j = 0; j < size; ++j){
if(id[j] == userId){
balances[j] += amount;
cout << names[j] << " " << balances[j] << endl;
}
}
break;
case 'R': for(int j = 0; j < size; ++j){
cout << "Id: " << id[j] << " Name: " << names[j] << " Balance: " << balances[j] << endl;
}
break;
case 'E': for(int j = 0; j < size; ++j){
accountFile << id[j] << " " << names[j] << " " << balances[j] << endl;
}
flag = 0;
accountFile.close();
break;
default: cout << "Invalid option" << endl;
}
}
break;
case 2: accountFile.open("accounts2.txt");
while(accountFile >> id[i]){
accountFile >> names[i];
accountFile >> balances[i];
++i;
}
size = i;
flag = 1;
while(flag){
cout << "Select an option: " << endl;
cout << "(M)odify amount" << endl;
cout << "(R)eport" << endl;
cout << "(E)xit and save" <<endl;
cin >> c;
switch(c){
case 'M': int userId;
float amount;
cout << "Enter the user id and amount: ";
cin >> userId >> amount;
for(int j = 0; j < size; ++j){
if(id[j] == userId){
balances[j] += amount;
cout << names[j] << " " << balances[j] << endl;
}
}
break;
case 'R': for(int j = 0; j < size; ++j){
cout << "Id: " << id[j] << " Name: " << names[j] << " Balance: " << balances[j] << endl;
}
break;
case 'E': for(int j = 0; j < size; ++j){
accountFile << id[j] << " " << names[j] << " " << balances[j] << endl;
}
flag = 0;
accountFile.close();
break;
default: cout << "Invalid option" << endl;
}
}
break;
default: cout << "Invalid option" << endl;
}
return 0;
}
What's the problem / question ?
HOW DO I DO THIS PART OF THE CODE

o Write the following functions:
 int loadData( string filename, int ids[], string names[], float balances[] );
• load all data from file filename into the passed in arrays – return the
number of accounts read
 int getIndex( int theID, int ids[], int numAccounts );
• go through the passed in array of ids and find the index of passed in id.
Return that index. Return -1 if not found.
 void modifyBalance( int index, float balances[], float amount);
• modify the balance in balances at the index by the amount passed in
 void reportAccountInfo( int index, int ids[], string names[], float balances[] );
• write to the console the id, name, and balance for the given account
index
 void reportAllAccountInfo( int ids[], string names[], float balances[], int
numAccounts);
• write to console account info for all accounts
 void saveAccounts(string filename, int ids[], string names[], float balances[], int
numAccounts );
• write to filename file all account info
o Create a separate .cpp/.h pairing called functions.h/.cpp for all your functions and
prototypes.
1) Create a header file called functions.h, which contains the prototypes (i.e. declarations) of all the functions you need to write. This should be trivially easy.

2) Create a source file called functions.cpp, which contains the definitions of all those functions - i.e. the code for what they actually do.

3) Call those functions from your main function, as appropriate.
2.5) #include "functions.h" in both functions.cpp and your main file.
Topic archived. No new replies allowed.