/* * Place identifying information here. */ #include #include #include #include using namespace std; // string ToUpperString(string word); // ColorT RandomColor(void); // void DoFrequencyTest(void); // void DoNameTest(void); const int MAX_TRIALS = 100000; int main() { /* uncomment here in step 6 DoFrequencyTest(); cout << endl << endl; DoNameTest(); uncomment to here in step 6*/ return 0; } /* uncomment here in step 6 void TestColor(string good, string changed, string bad) { if (good != bad){ cout << "Error: "; cout << changed << " became " << bad; cout << ". It should have been " << good << "." << endl; } return; } string MixString(string word) { size_t i; for(i =0; i < word.size(); i++) { if (rand() % 2 == 0) { word[i] = static_cast(toupper(word[i])); } } return word; } void BaseNameTest(vector colors) { size_t i; string result; for(i =0; i < colors.size(); i++) { result = ColorTToString(StringToColorT(colors[i])); TestColor(colors[i], colors[i], result); } return; } void RandomNameTest(vector & colors) { string result; string messed; size_t item; size_t i; for(i =0; i < MAX_TRIALS; i++) { item = static_cast(rand()) % COLOR_COUNT; messed = MixString(colors[item]); result = ColorTToString(StringToColorT(messed)); TestColor(colors[item], messed, result); } return; } void DoNameTest(void) { vector colors{"red", "green", "blue"}; vector moreColors{"cyan", "magenta","yellow"}; if (COLOR_COUNT > 3) { colors.insert(end(colors), begin(moreColors), end(moreColors)); } BaseNameTest(colors); RandomNameTest(colors); return; } void DoFrequencyTest(void){ int counts[COLOR_COUNT]{0}; int trial; double pct; ColorT color; for (trial = 0; trial < MAX_TRIALS; trial++) { color = RandomColor(); counts[static_cast(color)]++; } cout << endl; cout << "In " << MAX_TRIALS << " trials, the following colors occurred" << endl; cout << setw(10) << "Color"; cout << setw(10) << "Occurred"; cout << setw(10) << "PCT" << endl; for(color = FIRST_COLOR; color != ColorT::NO_COLOR; color = NextColorT(color)) { pct = static_cast(counts[static_cast(color)]) / static_cast(MAX_TRIALS) * 100.0; cout << setw(10) << ColorTToString(color) << setw(10) << counts[static_cast(color)] << setw(10) << pct << "%" << endl; } return; } ColorT RandomColor(){ ColorT result; result = static_cast(rand() % COLOR_COUNT ); return result; } uncomment to here in step 6 */ string ToUpperString(string word){ size_t i; for(i = 0; i < word.size(); i++) { word[i] = static_cast(toupper(word[i])); } return word; }