-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStock.cpp
104 lines (82 loc) · 1.91 KB
/
Stock.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
#include "Stock.h"
#include <iomanip>
using namespace std;
Stock::Stock(string n, string sym, int num, double pr):
name(n), ticker(sym), quantity(num), price(pr) { };
Stock::Stock(const Stock& s):
name(s.name), ticker(s.ticker), quantity(s.quantity), price(s.price) { };
const string Stock::getName() const{
return name;
}
const string Stock::getKey()const {
return ticker;
}
const string Stock::getTicker() const {
return ticker;
}
double Stock::getPrice() const{
return price;
};
int Stock::getQuantity() const{
return quantity;
};
void Stock::setName(string s){
name = s;
};
void Stock::setTicker(string s){
ticker = s;
};
void Stock::setPrice(double p){
price = p;
};
void Stock::setQuantity(int s){
quantity = s;
};
bool Stock::operator>(const Stock other) const{
return (getKey() > other.getKey());
};
bool Stock::operator<(const Stock other) const{
return (getKey() < other.getKey());
};
bool Stock::operator==(string key) const{
return (getKey() == key);
};
bool Stock::operator==(const Stock other) const{
return (getKey() == other.getKey());
};
bool Stock::operator>=(const Stock other) const{
return (getKey() >= other.getKey());
};
bool Stock::operator<=(const Stock other) const{
return (getKey() <= other.getKey());
};
ostream& operator<<(ostream& os, const Stock& st) {
os << std::left << std::setw(5)
<< st.ticker << ": "
<< std::setw(4)
<< std::right
<< st.quantity
<< " @ $ "
<< std::fixed
<< std::setprecision(2)
<< std::setw(7)
<< std::right
<< st.price
<< " (" << st.name << ")" ;
return os;
}
ostream& operator<<(ostream& os, const Stock* st) {
os << std::left << std::setw(5)
<< st->ticker << ": "
<< std::setw(4)
<< std::right
<< st->quantity
<< " @ $ "
<< std::fixed
<< std::setprecision(2)
<< std::setw(7)
<< std::right
<< st->price
<< " (" << st->name << ")" ;
return os;
}