Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Joseph Pantoliano
- // this is a programmer defined header file for the StockMarket Object Type.
- // when used in a program, this will be able to allocate and write a stock report
- #ifndef STOCK_MARKET_CLASS
- #define STOCK_MARKET_CLASS
- // system defined preprocessor statement for cin/cout operations
- #include <iostream.h>
- // programmer defined preprocessor statement for setreal operation
- #include "textlib.h"
- // programmer defined preprocessor statement for String
- #include "tstring.h"
- class StockMarket
- {
- private:
- String symbol; // identifies the company
- double startingPrice; // starting price of the stock
- double closingPrice; // closing price of the stock
- public:
- // Constructor initializes the attributes that are the symbol, the starting price of the stock, and
- // the closing price of the stock.
- StockMarket(String sym, double sPrice, double cPrice);
- // Takes the closing price of the stock and subtracts the starting price of the stock. Returns the
- // amount of change in the price of the stock.
- double change();
- // Returns the symbol.
- String getSymbol();
- // Returns the starting price of the stock.
- double getStartingPrice();
- // Returns the closing price of the stock.
- double getClosingPrice();
- // Outputs the following information that is listed below.
- // Stock Information for IBM: <=== where IBM is the symbol
- // Starting Price $XXX.XX
- // Closing Price $XXX.XX
- // -------------
- // Difference $XXX.XX
- void writeStockInfo();
- };
- //**********************************************************************
- // StockMarket Class Implementation
- //**********************************************************************
- // Constructor is passed arguments sym, sPrice, and cPrice
- // Implementation of the constructor
- StockMarket::StockMarket(String sym, double sPrice, double cPrice)
- {
- symbol = sym;
- startingPrice = sPrice;
- closingPrice = cPrice;
- }
- // Function which takes the closing price of the stock and subtracts the starting price of the stock. Returns the
- // amount of change in the price of the stock.
- double StockMarket::change()
- {
- double difference;
- difference = closingPrice - startingPrice;
- return difference;
- }
- // Function to return the symbol.
- String StockMarket::getSymbol()
- {
- return symbol;
- }
- // Function to return the starting price of the stock..
- double StockMarket::getStartingPrice()
- {
- return startingPrice;
- }
- // Function to return the closing price of the stock.
- double StockMarket::getClosingPrice()
- {
- return closingPrice;
- }
- // Function that outputs the following information that is listed below.
- // Stock Information for IBM: <=== where IBM is the symbol
- // Starting Price $XXX.XX
- // Closing Price $XXX.XX
- // -------------
- // Difference $XXX.XX
- void StockMarket::writeStockInfo()
- {
- cout << "Stock Information for " << symbol << endl
- << "Starting Price $" << setreal(1,2) << startingPrice << endl
- << "Closing Price $" << setreal(1,2) << closingPrice << endl
- << " -----------" << endl
- << "Diference $" << setreal(1,2) << (closingPrice - startingPrice) << endl;
- }
- #endif // STOCK_MARKET_CLASS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement