I have an inheritance heirarchy and I need to use polymorphism.
I have some questions because i don't really understand it fully.
What i have to do is create a vector of pointers (account) to 2 of my derived class objects, SavingsAccount and CheckingAccount.
Then for each account in my vector I need to determine its type so i can use member functions to perform actions
I don't know if i need to and which functions in my classes i need to make virtual and how i create the vector of account pointers.
I have included my classes that I have for my heirarchy and the code for my test program which i know won't work yet.
I just need to fill the gaps which creates the vector with the pointers and to find out how to add to the vector for the number of accounts.
here is my test program
//#include "SavingsAccount.hpp"
//#include "CheckingAccount.hpp"
#include <iomanip>
#include <vector>
#include <iostream>
using namespace std;
int main() {
//vector<Account> accounts;
//Account *sAccount = new SavingsAccount;
//Account *cAccount = new CheckingAccount;
double getWithdrawal;
double getDeposit;
int num_accounts;
cout << "Number of accounts to be processed: ";
cin >> num_accounts;
//accounts.resize(num_accounts);
for(int i=0; i < num_accounts; i++) {
cout << "Account " << i+1 << " balance: " << endl;
cout << "Enter an amount to withdraw from Account " << i+1 << ": ";
cin >> getWithdrawal;
cout << "Enter an amount to deposit into Account " << i+1 << ": ";
cin >> getDeposit;
}
return 0;
}
I think i can do the bits between the for loop which performs the actions but i just need to determine the account type