-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Stock and Order classes #4
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "Order.h" | ||
|
||
Order::Order( | ||
int orderId, | ||
int userId, | ||
std::string ticker, | ||
std::string companyName, | ||
bool isBuy, | ||
int price, | ||
int volume, | ||
int timestamp | ||
) { | ||
this->orderId = orderId; | ||
this->userId = userId; | ||
this->ticker = ticker; | ||
this->isBuy = isBuy; | ||
this->price = price; | ||
this->volume = volume; | ||
this->timestamp = timestamp; | ||
} | ||
|
||
int Order::getOrderId() { | ||
return this->orderId; | ||
} | ||
|
||
int Order::getUserId() { | ||
return this->userId; | ||
} | ||
|
||
std::string Order::getTicker() { | ||
return this->ticker; | ||
} | ||
|
||
bool Order::getIsBuy() { | ||
return this->isBuy; | ||
} | ||
|
||
int Order::getPrice() { | ||
return this->price; | ||
} | ||
|
||
int Order::getVolume() { | ||
return this->volume; | ||
} | ||
|
||
int Order::getTimestamp() { | ||
return this->timestamp; | ||
} | ||
|
||
void Order::setOrderId(int orderId) { | ||
this->orderId = orderId; | ||
} | ||
|
||
void Order::setUserId(int userId) { | ||
this->userId = userId; | ||
} | ||
|
||
void Order::setTicker(std::string ticker) { | ||
this->ticker = ticker; | ||
} | ||
|
||
|
||
|
||
|
||
int main() { | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
#include <string> | ||
|
||
class Order { | ||
private: | ||
int orderId; | ||
int userId; | ||
std::string ticker; | ||
bool isBuy; | ||
int price; | ||
int volume; | ||
int timestamp; | ||
|
||
public: | ||
// Constructor | ||
Order( | ||
int orderId, | ||
int userId, | ||
std::string ticker, | ||
std::string companyName, | ||
Comment on lines
+19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can pass a |
||
bool isBuy, | ||
int price, | ||
int volume, | ||
int timestamp | ||
); | ||
|
||
// Accessors | ||
int getOrderId(); | ||
int getUserId(); | ||
std::string getTicker(); | ||
bool getIsBuy(); | ||
int getPrice(); | ||
int getVolume(); | ||
int getTimestamp(); | ||
|
||
// Mutators | ||
void setOrderId(int orderId); | ||
void setUserId(int userId); | ||
void setTicker(std::string ticker); | ||
void setIsBuy(bool isBuy); | ||
void setPrice(int price); | ||
void setVolume(int volume); | ||
void setTimestamp(int timestamp); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#include <Stock.h> | ||
#include <iostream> | ||
|
||
// Constructor | ||
Stock::Stock( | ||
std::string ticker, | ||
std::string companyName, | ||
int currentPrice, | ||
int shares, | ||
int marketCap, | ||
std::map<std::string, int> priceLog | ||
) { | ||
this->ticker = ticker; | ||
this->companyName = companyName; | ||
this->currentPrice = currentPrice; | ||
this->shares = shares; | ||
this->marketCap = marketCap; | ||
this->priceLog = priceLog; | ||
} | ||
|
||
// Accessors | ||
std::string Stock::getTicker() { | ||
return this->ticker; | ||
} | ||
|
||
std::string Stock::getCompanyName() { | ||
return this->companyName; | ||
} | ||
|
||
int Stock::getCurrentPrice() { | ||
return this->currentPrice; | ||
} | ||
|
||
int Stock::getShares() { | ||
return this->shares; | ||
} | ||
|
||
int Stock::getMarketCap() { | ||
return this->marketCap; | ||
} | ||
|
||
std::map<std::string, int> Stock::getPriceLog() { | ||
return this->priceLog; | ||
} | ||
|
||
// Mutators | ||
void Stock::setTicker(std::string ticker) { | ||
this->ticker = ticker; | ||
} | ||
|
||
void Stock::setCompanyName(std::string companyName) { | ||
this->companyName = companyName; | ||
} | ||
|
||
void Stock::setCurrentPrice(int currentPrice) { | ||
this->currentPrice = currentPrice; | ||
} | ||
|
||
void Stock::setShares(int shares) { | ||
this->shares = shares; | ||
} | ||
|
||
void Stock::setMarketCap(int marketCap) { | ||
this->marketCap = marketCap; | ||
} | ||
|
||
void Stock::setPriceLog(std::string date, int price) { | ||
this->priceLog[date] = price; | ||
} | ||
|
||
// Display Methods | ||
void Stock::displayTicker() { | ||
std::cout << "Ticker: " << this->ticker << std::endl; | ||
} | ||
|
||
void Stock::displayCompanyName() { | ||
std::cout << "Company Name: " << this->companyName << std::endl; | ||
} | ||
|
||
void Stock::displayCurrentPrice() { | ||
std::cout << "Current Price: " << this->currentPrice << std::endl; | ||
} | ||
|
||
void Stock::displayShares() { | ||
std::cout << "Shares: " << this->shares << std::endl; | ||
} | ||
|
||
void Stock::displayMarketCap() { | ||
std::cout << "Market Cap: " << this->marketCap << std::endl; | ||
} | ||
|
||
void Stock::displayPriceLog() { | ||
std::cout << "Price Log: " << std::endl; | ||
for (auto const& x : this->priceLog) { | ||
std::cout << x.first << ": " << x.second << std::endl; | ||
} | ||
} | ||
|
||
void Stock::displayAll() { | ||
this->displayTicker(); | ||
this->displayCompanyName(); | ||
this->displayCurrentPrice(); | ||
this->displayShares(); | ||
this->displayMarketCap(); | ||
this->displayPriceLog(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
#include <string> | ||
#include <map> | ||
|
||
class Stock { | ||
public: | ||
// Constructor | ||
Stock( | ||
std::string ticker, | ||
std::string companyName, | ||
int currentPrice, | ||
int shares, | ||
int marketCap, | ||
Comment on lines
+11
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since these things are dynamic with time, I'm hesitant to include them inside of this class; however, we can leave them in for now given they provide some value. |
||
std::map<std::string, int> priceLog | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice addition! |
||
); | ||
|
||
// Accessors | ||
std::string getTicker(); | ||
std::string getCompanyName(); | ||
int getCurrentPrice(); | ||
int getShares(); | ||
int getMarketCap(); | ||
std::map<std::string, int> getPriceLog(); | ||
|
||
// Mutators | ||
void setTicker(std::string ticker); | ||
void setCompanyName(std::string companyName); | ||
void setCurrentPrice(int currentPrice); | ||
void setShares(int shares); | ||
void setMarketCap(int marketCap); | ||
void setPriceLog(std::string date, int price); | ||
|
||
// Display Methods | ||
void displayTicker(); | ||
void displayCompanyName(); | ||
void displayCurrentPrice(); | ||
void displayShares(); | ||
void displayMarketCap(); | ||
void displayPriceLog(); | ||
void displayAll(); | ||
|
||
private: | ||
std::string ticker; | ||
std::string companyName; | ||
int currentPrice; | ||
int shares; | ||
int marketCap; | ||
std::map<std::string, int> priceLog; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
int main() { | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a
bool
, let's use anenum
. This is so that we can include more information than just buy or sell such asLimitBuy
,LimitSell
, etc...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To specify, this is to replace the
bool isBuy