Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <stdlib.h>
- #include <iomanip>
- using namespace std;
- class singleStock {
- public:
- int open;
- int close;
- int width = 10;
- string symbol;
- int shareSold;
- void display() {
- cout << setw(width) << symbol << ", " << setw(width) << open << ", " << setw(width) << close << ", " << setw(width) << shareSold << endl;
- }
- };
- singleStock fillStock(singleStock userInput) {
- userInput.close = rand() % 100;
- userInput.open = rand() % 100;
- userInput.shareSold = rand() % 100000;
- userInput.symbol = rand() % 80 + 50;
- return userInput;
- }
- vector<singleStock> randomStocks(int userInput) {
- vector<singleStock> returnObject;
- singleStock tempStock;
- for (int i = 0; i < userInput; i++) {
- returnObject.push_back(fillStock(tempStock));
- }
- return returnObject;
- }
- void displayStockVector(vector<singleStock> userInput) {
- cout << setw(10) << "symbol" << ", " << setw(10) << "close" << ", " << setw(10) << "open" << ", " << setw(10) << "shareSold" << endl;
- for (int i = 0; i < userInput.size(); i++) {
- singleStock tempPointer;
- tempPointer = userInput[i];
- tempPointer.display();
- }
- }
- void main() {
- vector<vector <singleStock>> thisWeek;
- for (int i = 0; i < 7; i++) {
- vector<singleStock> tempStock = randomStocks(100);
- thisWeek.push_back(tempStock);
- cout << i << endl;
- displayStockVector(tempStock);
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment