-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source_BaseClass_Kashyap.cpp
76 lines (70 loc) · 2.2 KB
/
Source_BaseClass_Kashyap.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*Created by KASHYAP PATEL
FINAL PROJECT FOR PROGRAMMING FINANCE
Submission Date:12/06/2013*/
#include"finalproject_kashyap.h"
double Account::current_balance = 10000;
void Account::update_current_balance() //updates balance after transaction
{
ofstream fout("current_balance.dat",ios::binary);
fout << current_balance;
fout.close();
}
void Account::read_current_balance_at_start() //updates current balance at start
{
ifstream fin("current_balance.dat", ios::binary);
fin >> current_balance;
fin.close();
}
unsigned short Account::get_instruction()
{
unsigned short op; //Operation
cout << "Please select an account to access:" << endl;
cout << "1. Stock Portfolio Account" << endl;
cout << "2. Bank Account" << endl;
cout << "3. Exit" << endl;
cout << "Option:";
cin >> op; //Select Option
return op;
}
void Account::do_instruction(unsigned short op,LinkedList* ll_ptr)
{
static bool var_stock = false;
StockAccount* stock_ptr = new StockAccount; //Account Pointer pointing at StockAccount obj
switch (op) //According to input obtained from Account::get_instruction(), will perform appropriate operation
{
case 1: //Stock Account
{
stock_ptr->update_linkedlist_at_start(ll_ptr, var_stock);
unsigned short stock_op; //Operation for Stock Account
do
{
stock_op = stock_ptr->get_instruction(); //Same logic as Base Class
stock_ptr->do_instruction(stock_op,ll_ptr);
var_stock = true;
} while (stock_op != 7); //Continue till '7' is pressed for going back
break;
}
case 2: //Bank Account
{
BankAccount* bank_ptr = new BankAccount; //Account Pointer pointing at BankAccount obj
unsigned short bank_op; //Operation for Bank Account
do
{
bank_op = bank_ptr->get_instruction();
bank_ptr->do_instruction(bank_op,ll_ptr);
} while (bank_op != 5); //Continue till '5' is pressed for going back
break;
}
case 3: //Exit
{
stock_ptr->get_graph(); //graph at end
cout << endl << "Thanks for using this service. Your session is saved" << endl;
break;
}
default: //Invalid Entry
{
cout << endl << "Please enter proper input" << endl;
break;
}
}
}