-
Notifications
You must be signed in to change notification settings - Fork 0
/
PortfolioTotalsStack.cpp
81 lines (67 loc) · 1.64 KB
/
PortfolioTotalsStack.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
#include "PortfolioTotalsStack.h"
#include <iostream>
#include <stack>
using namespace std;
PortfolioTotalsStack::PortfolioTotalsStack() {}
double PortfolioTotalsStack::getMax() {
if (s.empty()) {
cout << "Stack is empty" << endl;
return -1.00;
}
else {
// cout << "Maximum portfolio in the stack is: $" << maxPortfolio << endl;
return maxPortfolio;
}
}
double PortfolioTotalsStack::getMin() {
if (s.empty()) {
cout << "Stack is empty" << endl;
return -1;
}
else {
// cout << "Minimum portfolio in the stack is: $" << minPortfolio << endl;
return minPortfolio;
}
}
double PortfolioTotalsStack::peek() {
if (s.empty()) {
cout << "Stack is empty" << endl;
return -1;
}
// cout << "Last calculated portfolio is: $" << s.top();
return s.top();
}
double PortfolioTotalsStack::pop() {
if (s.empty()) {
cout << "Stack is empty" << endl;
return -1;
}
double last = s.top();
if (last == minPortfolio)
minPortfolio = 0;
// cout << "Last portfolio $" << last << "removed from the stack" << endl;
s.pop();
return last;
}
void PortfolioTotalsStack::push(double portfolioTotal) {
if (s.empty()) {
maxPortfolio = portfolioTotal;
minPortfolio = portfolioTotal;
s.push(portfolioTotal);
// cout << "Number inserted: " << portfolioTotal << endl;
return;
}
else
if (maxPortfolio < portfolioTotal)
maxPortfolio = portfolioTotal;
if (minPortfolio > portfolioTotal)
minPortfolio = portfolioTotal;
s.push(portfolioTotal);
// Calculate rolling average of portfolioTotals and update in private variable
// Will probably need an accumulator as well
}
// Driver Code
void drive() {
PortfolioTotalsStack pts;
pts.getMax();
}