-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12.13_main.cpp
More file actions
43 lines (37 loc) · 1.15 KB
/
12.13_main.cpp
File metadata and controls
43 lines (37 loc) · 1.15 KB
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
#include "Account.h"
#include "CheckingAccount.h"
#include "SavingsAccount.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <typeinfo>
using namespace std;
double withdraw;
double deposit;
int main() {
// create class objects
CheckingAccount checkingaccount{ 2000, 100 };
SavingsAccount savingsaccount{ 1500, 0.01 };
// create and initialize vector of three base-class pointers
vector<Account*> accounts{ &savingsaccount, &checkingaccount };
for (Account* accountPtr : accounts) {
cout << fixed << setprecision(2);
cout << "Account has been created.\n"
<< "\nInput an amount of money to withdraw : ";
cin >> withdraw;
accountPtr->Debit(withdraw);
cout << "\nInput an amount of money to deposit : ";
cin >> deposit;
accountPtr->Credit(deposit);
SavingsAccount* derivedPtr = dynamic_cast<SavingsAccount*>(accountPtr);
if (derivedPtr != nullptr) {
cout << "\nThis account is savingsaccount.";
accountPtr->Credit(derivedPtr->CalculateInterest());
}
else {
cout << "\nThis account is checkingaccount.";
}
cout << "\n\nThis account's current balance is : " << accountPtr->getBalance() << "\n\n";
}
}