example or tutorial for array of classes

I have been looking for the past 3 hours trying to find a comprehensive example or tutorial for assigning classes to an array. I have found the clocktype video on youtube by Joseph Tomlin but without the code, it is hard to get it to work with what I need it to do. I need to take a bank account class and assign it to an array. I am getting a little frustrated as I have been looking for 2.5 hours now.
Made a little progress. Please help me to PrintCustomerData. Not sure exactly how to access it with my function. Also, My menu isn't exiting quite right....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
 #include <cstdlib>
 #include "Assignment2.h"
 #include <string>
 
 using namespace std;
 int index = 0;
 //CreateAccount()
 void CreateAccount()
 {
      
	  BankAccount MyBankData;
	  BankAccount MyBankArray[100];
	  int AccountNumber = 0, index = 0;
	  long double Balance = 50.0;
	  string AccountHolder;
 cout << "Enter Account Holders Name" << endl;
 cin >> AccountHolder;
 cout << "Congratulations....Your NEW Pro-Bank Extreme account has been successfully created..." << endl;
 cout << "As a bonus for opening a new account, a $50.00 credit has been automatically deposited into your new account!!" << endl;
 cout << "Your Pro-Bank Extreme account number is : " << AccountNumber << endl;
 MyBankArray[index].StoreData (AccountHolder, AccountNumber, Balance);
// MyAccountInfo[index] = MyBankData;
//MyBankArray[0].PrintCustomerData();
  };//end CreateAccount
// void FillBankArray (BankAccount MyBankArray[]) 
//{
//	for (int index = 0; index < 20; ++index)
//	MyBankArray[index]MyBankData.StoreData (AccountHolder, AccountHolder, Balance);
//}//end FillBankArray
 int CreateAccountNumber()
 {
 	static int AccountNumber = 0;
 	return ++AccountNumber;
 }//end CreateAccountNumber
  void BankAccount::StoreData(string AccountHolder, int AccountNumber, long double Balance)
   {
    long double InterestRate = 10.0;
    int index = 0;
    AccountHolder = AccountHolder;
    AccountNumber = AccountNumber;
    Balance = Balance;
	BankAccount MyBankData;	
	MainMenu();   
   }//end StoreData
  void BankAccount::PrintCustomerData (string AccountHolder, int AccountNumber, long double Balance, long double InterestRate)
  {
  	cout << "Primary Account Holder Name :" << AccountHolder << endl;
  	cout << "Pro-Bank Extreme Account Number :" << AccountNumber << endl;
  	cout << "Current Ballance :" << Balance << endl;
  	cout << "Interest Rate :" << InterestRate << endl;
  }//end PrintCustomerData 
  void BankAccount::Deposit()
  {
  	long double DepositAmount;
  cout << "Enter Primary Account Holder Name :" << endl;
  cout << "Enter Deposit Ammount :" << endl;
  cin >> DepositAmount;
  	
  }//end Deposit
  void BankAccount::Withdrawal()
  {
  	long double WithdrawalAmount;
  cout << "Enter Primary Account Holder Name :" << endl;
  cout << "Enter Withdrawal Ammount :" << endl;
  cin >> WithdrawalAmount;		
  }//end Withdrawal


Menu .cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 #include <iostream>
 #include <cstdlib>
 #include "Assignment2.h"
 
 void MainMenu()
{
    //=====Variable declarations
    BankAccount MyBankArray[20];
	int Choice;
    bool quit = false;
	while (!quit)
	{
	
	//=====body
    cout << "== MAIN MENU ==" << endl;
    cout << "1. ADD a customer" << endl;
    cout << "2. Print ALL customer data for ALL customers" << endl;
    cout << "3. UPDATE existing customer DATA" << endl;
    cout << "4. EXIT" << endl;
    
	cout << "Enter a menu choice: " << endl;
    cin >> Choice;
    cout << endl;
    
    
    switch(Choice)
    {
        case 1: CreateAccount(); //replace "Add a customer with CreateAccountNumber Function here
                  
            break;
        case 2: cout << "Print All customer DATA" << endl; //replace "Print ALL customer DATA" with PrintCustomerData function here
            break;
        case 3: cout << "UPDATE existing customer DATA: " << endl;
                cout << "a) Make a Deposit: " << endl;
                //(Deposit) 
                cout << "b) Withdrawal: " << endl;
                //(Withdrawal)
                cout << "c) Print Account Balance: " << endl;
                //(PrintAccountBallance)
                cout << "d) Update Account Balance WITH interest: " << endl;
                //(UpdateAccountBalance)
                cout << "e) Exit to Main Menu" << endl;
                //(ExitToMainMenu)
            break;
        case 4: cout << "EXIT" << endl;
                quit = true;
            break;
    }        
    //return(Choice);
}//end while
}//end MainMenu 


Header file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  using namespace std;
   //Constructors
   //Function Declarations
   
  void MainMenu();
  void CreateAccount();
  void PrintCustomerData();
 // void FillBankArray(BankAccount[]);
  //void StoreData(string, int, long double, int);
  //int CreateAccountNumber(int);
   //Classes
   class BankAccount
   {
   	private:
   		
   		string AccountHolder;
   		int AccountNumber;
   		long double Balance;
   		long double InterestRate;
   	//	BankAccount();
   	public:
   		//Member Functions
   		//BankAccount MyAccountInfo[100];
   		void CreateAccount();
        void StoreData(string, int, long double);
        void PrintCustomerData (string, int, long double, long double);
        void Deposit();
        void Withdrawal();
     //   BankAccount MyBankArray[];
   };//end class 
It is the same as any other array.

1
2
int myIntArray [5];
bank_account myClassArray [5];
but, If an Array is declared as an int, how can it hold anything else other than ints? ie....classes?
look at vectors.
no use' de vectors.......:(
but, If an Array is declared as an int, how can it hold anything else other than ints?

An Array of ints will hold ints. An array of some class will hold that class. You can combine the two in an array, but that would mean making another class, or struct, and using that type of array.
You posted while I was typing, it look like. And look like you figured it out.
Topic archived. No new replies allowed.