Stock Market Simulator main e8c3612
A game that provides a realistic stock buying experience with unpredictable trends to test investment strategies.
Loading...
Searching...
No Matches
stock.h File Reference

Declaration of the Stock class. More...

#include "events.h"
#include "names.h"
#include <istream>
#include <list>
#include <map>
#include <string>
#include <vector>
Include dependency graph for stock.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Stock
 A class that represents a stock object in the game. More...
 

Enumerations

enum  SortingDirections { ascending , descending }
 
enum  SortingMethods {
  by_name , by_price , by_category , by_quantity ,
  by_upper_limit , by_lower_limit , by_mean , by_sd
}
 

Functions

void sortStocksList (std::vector< Stock > &stocks_list, SortingMethods sortMethod=by_category, SortingDirections sortDirection=ascending)
 Sorts the stocks.
 

Variables

const int initial_stock_count = 20
 Initial stock count.
 
const float STOCK_PRICE_LIMIT = 1000.0f
 The upper limit of the stock price.
 

Detailed Description

Declaration of the Stock class.

Definition in file stock.h.

Enumeration Type Documentation

◆ SortingDirections

Enumerator
ascending 
descending 

Definition at line 319 of file stock.h.

@ ascending
Definition stock.h:319
@ descending
Definition stock.h:319

◆ SortingMethods

Enumerator
by_name 
by_price 
by_category 
by_quantity 
by_upper_limit 
by_lower_limit 
by_mean 
by_sd 

Definition at line 308 of file stock.h.

308 {
309 by_name,
310 by_price,
315 by_mean,
316 by_sd
317};
@ by_upper_limit
Definition stock.h:313
@ by_mean
Definition stock.h:315
@ by_price
Definition stock.h:310
@ by_quantity
Definition stock.h:312
@ by_category
Definition stock.h:311
@ by_lower_limit
Definition stock.h:314
@ by_sd
Definition stock.h:316
@ by_name
Definition stock.h:309

Function Documentation

◆ sortStocksList()

void sortStocksList ( std::vector< Stock > & stocks_list,
SortingMethods sortMethod = by_category,
SortingDirections sortDirection = ascending )

Sorts the stocks.

Parameters
stocks_listA vector of stocks. Pass by reference to modify the stocks.
sortMethodSorting method. Default is by_category.
sortDirectionSorting direction. True for ascending, false for descending. Default is ascending.

Definition at line 321 of file stock.cpp.

322 {
323 switch (sortMethod) {
324 case by_name:
325 std::sort(stocks_list.begin(), stocks_list.end(),
326 [](Stock a, Stock b) { return a.get_name() < b.get_name(); });
327 break;
328 case by_category:
329 std::sort(stocks_list.begin(), stocks_list.end(),
330 [](Stock a, Stock b) { return a.get_category() < b.get_category(); });
331 break;
332 case by_price:
333 std::sort(stocks_list.begin(), stocks_list.end(),
334 [](Stock a, Stock b) { return a.get_price() < b.get_price(); });
335 break;
336 case by_quantity:
337 std::sort(stocks_list.begin(), stocks_list.end(),
338 [](Stock a, Stock b) { return a.get_quantity() < b.get_quantity(); });
339 break;
340 case by_sd:
341 std::sort(stocks_list.begin(), stocks_list.end(), [](Stock a, Stock b) {
342 return a.get_total_attribute(standard_deviation) <
343 b.get_total_attribute(standard_deviation);
344 });
345 break;
346 case by_mean:
347 std::sort(stocks_list.begin(), stocks_list.end(), [](Stock a, Stock b) {
348 return a.get_total_attribute(mean) < b.get_total_attribute(mean);
349 });
350 break;
351 case by_lower_limit:
352 std::sort(stocks_list.begin(), stocks_list.end(), [](Stock a, Stock b) {
353 return a.get_total_attribute(lower_limit) <
354 b.get_total_attribute(lower_limit);
355 });
356 break;
357 case by_upper_limit:
358 std::sort(stocks_list.begin(), stocks_list.end(), [](Stock a, Stock b) {
359 return a.get_total_attribute(upper_limit) <
360 b.get_total_attribute(upper_limit);
361 });
362 break;
363 default:
364 break;
365 }
366 if (sortDirection == descending) {
367 std::reverse(stocks_list.begin(), stocks_list.end());
368 }
369}
A class that represents a stock object in the game.
Definition stock.h:55

References by_category, by_lower_limit, by_mean, by_name, by_price, by_quantity, by_sd, by_upper_limit, and descending.

Referenced by main().

Here is the caller graph for this function:

Variable Documentation

◆ initial_stock_count

const int initial_stock_count = 20

Initial stock count.

Definition at line 28 of file stock.h.

Referenced by loadstatus(), and main().

◆ STOCK_PRICE_LIMIT

const float STOCK_PRICE_LIMIT = 1000.0f

The upper limit of the stock price.

See also
Stock::next_round for the "stock split" event.

Definition at line 34 of file stock.h.

Referenced by Stock::load(), and Stock::next_round().