Simulation of Stock Market Trends Gaming Project in C++

Explanation

  1. Stock Class:
    • Attributes:
      • name: Name of the stock.
      • price: Current price of the stock.
    • Methods:
      • updatePrice(): Updates the stock price with a random percentage change between -5% and +5%. Ensures the price does not go below zero.
      • printInfo(): Prints the current stock name and price, formatted to two decimal places.
  2. Main Function:
    • Random Number Generation: srand(time(0)) seeds the random number generator to ensure different results each run.
    • Stocks Initialization: Creates a list of Stock objects with initial prices.
    • Simulation Loop: Runs for a set number of steps (10 in this case). For each step:
      • Updates the price of each stock.
      • Prints the updated stock information.
      • Waits for 1 second to simulate time passing.

Usage

  • Stock Simulation: The program simulates price changes for stocks, providing a basic model of stock market trends.
  • Price Fluctuations: The updatePrice() method applies random changes to simulate market fluctuations.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top