/*
* Copyright ©2026 Soham Pardeshi. All rights reserved.
* Permission is hereby granted to students registered for University of
* Washington CSE 333 for use solely during Summer Quarter 2026 for
* purposes of the course. No other use, copying, distribution, or
* modification is permitted without prior written consent. Copyrights
* for third-party components of this work must be honored. Instructors
* interested in reusing these course materials should contact the author.
*/
#ifndef STOCK_H_
#define STOCK_H_
#include <string>
#include "Asset.h"
namespace cse333 {
// A holding of shares in a single company. Stock is-a Asset.
class Stock : public Asset {
public:
Stock(const std::string& symbol, int total_shares, double total_cost,
double current_price)
: Asset(symbol),
total_shares_(total_shares),
total_cost_(total_cost),
current_price_(current_price) {}
// Buy `shares` more at `price` each.
void Buy(int shares, double price);
// virtual (slide 20): dynamic dispatch picks the most-derived version.
double GetMarketValue() const override;
// Inherited by DividendStock unchanged. Its call to GetMarketValue()
// still dispatches dynamically to the derived version (slide 20).
double GetProfit() const;
protected: // visible to derived classes (slide 17)
int total_shares_;
double total_cost_;
double current_price_;
};
} // namespace cse333
#endif // STOCK_H_