Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions Order.cpp
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;
}
44 changes: 44 additions & 0 deletions Order.h
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;
Copy link
Collaborator

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 an enum. This is so that we can include more information than just buy or sell such as LimitBuy, LimitSell, etc...

Copy link
Collaborator

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

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can pass a Stock object here to avoid duplicate work, same as below

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);
};
106 changes: 106 additions & 0 deletions Stock.cpp
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();
}
49 changes: 49 additions & 0 deletions Stock.h
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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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;
};
3 changes: 3 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main() {
return 0;
}