Random.h #include #include using namespace std; class Random { public: int next(); int next(int n); int next(int m, int n); }; Random.cpp #include "Random.h" int Random::next() { return rand(); } int Random::next(int n) { return rand() % n; } int Random::next(int m, int n) { return rand() % (n - m + 1) + m; } main.cpp #include "Random.h" int main() { srand(time(NULL)); Random rng; //Generate random integer number cout << rng.next() << endl; //Generate random integer number from 0 to 9 cout << rng.next(10) << endl; //Generate random integer number from 11 to 20 cout << rng.next(11, 20) << endl; return 1; } =================================== Dice.h #include #include #include "../Random/Random.h" using namespace std; class Dice { private: Random _rng; int _rollCount; int _value[7]; int _sum; public: Dice() { _rollCount = _sum = 0; for (int i = 1; i < 7; i++) _value[i] = 0; _value[0] = -1; } int roll(); int rollCount(); float AverageRollValue(); void Print(); }; Dice.cpp #include "Dice.h" int Random::next(int m, int n) { return rand() % (n - m + 1) + m; } int Dice::roll() { return _rng.next(1, 6); } int Dice::rollCount() { int choice; while (true) { cout << "Continue - Press 1" << endl; cout << "Stop - Press 0" << endl; cout << "Input your choice: "; cin >> choice; if (choice == 1) { int result = roll(); cout << "Result = " << result << endl; _value[result]++; _rollCount++; _sum += result; } else break; } return _rollCount; } float Dice::AverageRollValue() { return (float)_sum / this->_rollCount; } void Dice::Print() { for (int i = 1; i < 7; i++) cout << i << ":" << _value[i] << " times" << endl; } main.cpp #include "Dice.h" int main() { Dice dice; cout << dice.roll() << endl; //the number of times a dice has been rolled cout << dice.rollCount() << endl; //the average number that we get from all the rolls cout << dice.AverageRollValue() << endl; //Print out all the counts for all the values of one dice dice.Print(); return 1; } ================================== Tokenizer.h #include #include #include using namespace std; class Tokenizer { public: static vector parse(string haystack, string separator); }; void Sort(vector& a); Tokenizer.cpp #include "Tokenizer.h" vector Tokenizer::parse(string haystack, string separator) { vectorresult; int startPos = 0; int lastFoundPos = -1; while (true) { size_t foundPos = haystack.find(separator, startPos); if (foundPos != string::npos) { string token = haystack.substr(startPos, foundPos - startPos); startPos = foundPos + separator.length(); result.push_back(token); lastFoundPos = foundPos; } else { startPos = lastFoundPos + separator.length(); string token = haystack.substr(startPos, haystack.size() - startPos); result.push_back(token); break; } } return result; } void Sort(vector& a) { for (int i = 0; i < a.size() - 1; i++) { for (int j = i + 1; j < a.size(); j++) { if (a[i] > a[j]) swap(a[i], a[j]); } } } main.cpp #include "Tokenizer.h" int main() { int choice; while (true) { cout << "========================================MENU=================================================" << endl; cout << "0. Exit." << endl; cout << "1. Split a string(haystack) into multiple sub strings(tokens)." << endl; cout << "2. Convert a string of multiple integers, separated by space, into vector." << endl; cout << "=============================================================================================" << endl; cout << "Input your choice: "; cin >> choice; cin.ignore(); if (choice == 1) { string haystack, separator; cout << "Input haystack string: "; getline(cin, haystack); cout << "Input separator string: "; getline(cin, separator); vectorresult = Tokenizer::parse(haystack, separator); cout << "Sub strings:" << endl; for (int i = 0; i < result.size(); i++) cout << result[i] << endl; } else if (choice == 2) { string integers; cout << "Input a string of multiple integers: "; getline(cin, integers); vectorresult = Tokenizer::parse(integers, " "); vectorkq; for (int i = 0; i < result.size(); i++) kq.push_back(stoi(result[i])); Sort(kq); cout << " the smallest number in the vector: " << kq[0] << endl; int x = kq.size(); cout << " the first 3 biggest number in the vector: " << kq[x - 1] << " " << kq[x - 2] << " " << kq[x - 3] << endl; } else { cout << "Exiting. . ." << endl; break; } system("pause"); system("cls"); } return 0; } ==================