-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain_zhou.cpp
278 lines (230 loc) · 8.17 KB
/
Main_zhou.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// Name: Lisheng Zhou
// Final Project: Account Management System
// Date: Dec 13, 2015
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <time.h>
#include <iomanip>
#include <ctime>
using std::cout;
using std::cin;
using std::endl;
using std::ifstream;
using std::ofstream;
using std::ios;
#include "Account_zhou.h"
#include "BankAccount_zhou.h"
#include "StockAccount_zhou.h"
#include "Node_zhou.h"
void instructionTop()
{
// instruction for main menu
cout << "\n\nPlease select an account to access:" << endl;
cout << "1. Stock Portfolio Account" << endl;
cout << "2. Bank Account" << endl;
cout << "3. Exit" << endl;
cout << "Option: ";
}
void stockInstruction()
{
// instruction for stock menu
cout << "\nPlease select an option:" << endl;
cout << "1. Display the price for a stock symbol" << endl;
cout << "2. Display the current portfolio" << endl;
cout << "3. Buy shares" << endl;
cout << "4. Sell shares" << endl;
cout << "5. View a graph for the portfolio value" << endl;
cout << "6. View transaction history" << endl;
cout << "7. Return to previous menu" << endl;
cout << "Option: ";
}
void bankInstruction()
{
// instruction for bank menu
cout << "\nPlease select an option:" << endl;
cout << "1. View account balance" << endl;
cout << "2. Deposit money" << endl;
cout << "3. Withdraw money" << endl;
cout << "4. Print out history" << endl;
cout << "5. Return to previous menu" << endl;
cout << "Option: ";
}
void mainMenu()
{
int mainChoice; // choice for top menu
// stockaccount object
StockAccount stockObj;
// bankaccount object
BankAccount bankObj;
// link two balance
bankObj.setBalance(stockObj.getBalance());
do {
instructionTop();
cin >> mainChoice;
while (cin.fail()){
cout << "\nPlease enter an integer value: ";
cin.clear();
cin.ignore();
cin >> mainChoice;
}
switch ( mainChoice ) {
case 1:
{
// stock menu
cout << "\nStock Portfolio Account" << endl;
// update balance
stockObj.setBalance(bankObj.getBalance());
int stockChoice; // choice for stock menu
string stockSymbol; // stock symbol
int numberShare; // number of shares
double maxPrice; // max price to buy shares
double minPrice; // min Price to sell shares
string time_start, time_end; // time period to view graph
do {
stockInstruction();
cin >> stockChoice;
while (cin.fail()){
cout << "\nPlease enter an integer value: ";
cin.clear();
cin.ignore();
cin >> stockChoice;
}
//StockAccount *stockPtr = &account;
switch ( stockChoice ) {
case 1:
// display price for stock
cout << "\nPlease enter the stock symbol: ";
cin >> stockSymbol;
stockObj.displayPrice( stockSymbol ); // WORKING ON IT
break;
case 2:
// display current portfolio
//cout << "display current portfolio" << endl;
stockObj.displayPortfolio();
break;
case 3:
// buy shares
cout << "Please enter the stock symbol you wish to purchase: ";
cin >> stockSymbol;
cout << "Please enter the number of shares: ";
cin >> numberShare;
while (cin.fail()){
cout << "\nPlease enter an integer value: ";
cin.clear();
cin.ignore();
cin >> numberShare;
}
cout << "Please enter the maximum amount you are willing to pay per share: $";
cin >> maxPrice;
while (cin.fail()){
cout << "\nPlease enter a double value: $";
cin.clear();
cin.ignore();
cin >> maxPrice;
}
stockObj.buyStock(&Node(stockSymbol, numberShare), maxPrice);
break;
case 4:
// sell shares
cout << "Please enter the stock symbol you wish to sell: ";
cin >> stockSymbol;
cout << "Please enter the number of shares: ";
cin >> numberShare;
while (cin.fail()){
cout << "\nPlease enter an integer value: ";
cin.clear();
cin.ignore();
cin >> numberShare;
}
cout << "Please enter the minimum amount you are willing to sell per share: $";
cin >> minPrice;
while (cin.fail()){
cout << "\nPlease enter a double value: $";
cin.clear();
cin.ignore();
cin >> minPrice;
}
stockObj.sellStock(&Node(stockSymbol, numberShare), minPrice);
break;
case 5:
// view matlab graph
cout << "\nPlease select the time period in the graph: " << endl;
cout << "Start Date (mm/dd/yyyy): ";
cin >> time_start;
cout << "\nEnd Date (mm/dd/yyyy): ";
cin >> time_end;
stockObj.viewGraph(time_start, time_end);
break;
case 6:
// view transaction history
stockObj.viewHistory();
break;
} // end stock switch
} while ( stockChoice != 7 );
break;
} // end case 1
case 2:
{
// bank menu
cout << "\nBank Account" << endl;
// update balance
bankObj.setBalance(stockObj.getBalance());
int bankChoice; // choice for bank menu
double amount; // amount of money to deposit or withdraw
do {
bankInstruction();
cin >> bankChoice;
while (cin.fail()){
cout << "\nPlease enter an integer value: ";
cin.clear();
cin.ignore();
cin >> bankChoice;
}
switch ( bankChoice ) {
case 1:
// view account balance
bankObj.viewBalance();
break;
case 2:
// deposit
cout << "Please select the amount you wish to deposit: $";
cin >> amount;
while (cin.fail()){
cout << "\nPlease enter a double value: $";
cin.clear();
cin.ignore();
cin >> amount;
}
bankObj.deposit(amount);
break;
case 3:
// withdraw
cout << "Please select the amount you wish to withdraw: $";
cin >> amount;
while (cin.fail()){
cout << "\nPlease enter a double value: $";
cin.clear();
cin.ignore();
cin >> amount;
}
bankObj.withdraw(amount);
break;
case 4:
// print history
bankObj.printHistory();
break;
} // end bank switch
} while ( bankChoice != 5 );
break;
} // end case 2
} // end main switch
} while ( mainChoice != 3 );
}
int main()
{
// main function
mainMenu();
return 0;
}