Projects Inventory

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

Exit mobile version