Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.25 KB | None | 0 0
  1. // Joseph Pantoliano
  2. // this is a programmer defined header file for the StockMarket Object Type.
  3. // when used in a program, this will be able to allocate and write a stock report
  4.  
  5. #ifndef STOCK_MARKET_CLASS
  6. #define STOCK_MARKET_CLASS
  7.  
  8. // system defined preprocessor statement for cin/cout operations
  9. #include <iostream.h>
  10.  
  11. // programmer defined preprocessor statement for setreal operation
  12. #include "textlib.h"
  13.  
  14. // programmer defined preprocessor statement for String
  15. #include "tstring.h"
  16.  
  17. class StockMarket
  18. {
  19.     private:
  20.     String symbol;              // identifies the company
  21.     double startingPrice;       // starting price of the stock
  22.     double closingPrice;        // closing price of the stock
  23.  
  24.     public:
  25.     // Constructor initializes the attributes that are the symbol, the starting price of the stock, and        
  26.     // the closing price of the stock.
  27.     StockMarket(String sym, double sPrice, double cPrice);
  28.        
  29.     // Takes the closing price of the stock and subtracts the starting price of the stock. Returns the
  30.     // amount of change in the price of the stock.
  31.     double change();
  32.    
  33.     // Returns the symbol.
  34.     String getSymbol();
  35.  
  36.     // Returns the starting price of the stock.
  37.     double getStartingPrice();
  38.  
  39.     // Returns the closing price of the stock.
  40.     double getClosingPrice();
  41.  
  42.     // Outputs the following information that is listed below.
  43.     // Stock Information for IBM:            <=== where IBM is the symbol
  44.     // Starting Price       $XXX.XX
  45.     // Closing Price        $XXX.XX
  46.     //                  -------------
  47.     // Difference           $XXX.XX
  48.     void writeStockInfo();
  49. };
  50.  
  51. //**********************************************************************
  52. //             StockMarket Class Implementation
  53. //**********************************************************************
  54.  
  55. // Constructor is passed arguments sym, sPrice, and cPrice
  56. // Implementation of the constructor
  57. StockMarket::StockMarket(String sym, double sPrice, double cPrice)
  58. {
  59.     symbol = sym;
  60.     startingPrice = sPrice;
  61.     closingPrice = cPrice;
  62. }
  63.  
  64. // Function which takes the closing price of the stock and subtracts the starting price of the stock. Returns the
  65. // amount of change in the price of the stock.
  66. double StockMarket::change()
  67. {
  68.     double difference;
  69.     difference = closingPrice - startingPrice;
  70.     return difference;
  71. }
  72.  
  73. // Function to return the symbol.
  74. String StockMarket::getSymbol()
  75. {
  76.     return symbol;
  77. }
  78.  
  79.  
  80. // Function to return the starting price of the stock..
  81. double StockMarket::getStartingPrice()
  82. {
  83.     return startingPrice;
  84. }
  85.  
  86.  
  87. // Function to return the closing price of the stock.
  88. double StockMarket::getClosingPrice()
  89. {
  90.     return closingPrice;
  91. }
  92.  
  93.  
  94. // Function that outputs the following information that is listed below.
  95. // Stock Information for IBM:            <=== where IBM is the symbol
  96. // Starting Price       $XXX.XX
  97. // Closing Price        $XXX.XX
  98. //                  -------------
  99. // Difference           $XXX.XX
  100. void StockMarket::writeStockInfo()
  101. {
  102.  
  103.            cout << "Stock Information for " << symbol                                          << endl
  104.                 << "Starting Price      $"  << setreal(1,2)  << startingPrice                  << endl
  105.                 << "Closing Price       $"  << setreal(1,2)  << closingPrice                   << endl
  106.                 << "                    -----------"                                           << endl
  107.                 << "Diference           $"  << setreal(1,2)  << (closingPrice - startingPrice) << endl;
  108. }
  109.  
  110. #endif                                          // STOCK_MARKET_CLASS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement