From 0cf7e0d3e1a3506533fa27ef712ee612e3fa8657 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Tue, 26 Feb 2019 14:00:34 -0600 Subject: MEANINGFUL CO M M EN TS Also making 3B a function cause why not. --- ee1301/wk3/hw3_directory/strap012_HW3A.cpp | 13 ++++++-- ee1301/wk3/hw3_directory/strap012_HW3B.cpp | 52 ++++++++++++++++++++++-------- ee1301/wk3/hw3_directory/strap012_HW3C.cpp | 7 +++- 3 files changed, 54 insertions(+), 18 deletions(-) (limited to 'ee1301') diff --git a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp index 453af2d..9aacf63 100644 --- a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp +++ b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp @@ -14,6 +14,13 @@ One-armed Bandit Simulator #include using namespace std; +// Function: spin_the_wheel +// --------------------------- +// Simulates the one-armed bandit from the previous HW +// d: the number of options on the spinner +// w: the number of spinners +// returns: Either 1 for win or 0 for loss + int spin_the_wheel(int d, int w) { int spinOG=0, spinNew=0, win=0; spinOG = ( (rand() % d) + 1); //Original spin is always the same @@ -24,15 +31,15 @@ int spin_the_wheel(int d, int w) { } } if (win==w) { //The only win condition is if every wheel matches - return 1; //"win" + return 1; } else { - return 0; //"loss" + return 0; } } int main () { srand(88888888); //Seeds the RNG of the program to a constant of eight 8s - int w, d, m, winTest; //'w' is for spinner count, 'd' is the number of options on the spinner + int w, d, m, winTest; for (w=3; w<=6; w++) { m=0; for (d=9; d<=27; d++) { diff --git a/ee1301/wk3/hw3_directory/strap012_HW3B.cpp b/ee1301/wk3/hw3_directory/strap012_HW3B.cpp index 8a23e24..ffb669e 100644 --- a/ee1301/wk3/hw3_directory/strap012_HW3B.cpp +++ b/ee1301/wk3/hw3_directory/strap012_HW3B.cpp @@ -14,27 +14,51 @@ Character Detection #include using namespace std; -int main () { - char character; - bool isNotAlphaNumeric=false; - while (!isNotAlphaNumeric) { - cout << "Enter a single digit or an alphabetic character: "; - cin >> character; - cout << "You entered " << character; - if (character >= '0' && character <= '9') +// Function: charTest +// --------------------------- +// Tests to see what kind of character was inputted +// character: Self-explanatory +// returns: 1 if number, 2 if lower case, 3 if upper case, 0 if not any of the previous + +int charTest (char character) { + if (character >= '0' && character <= '9') { - cout << ", which is a number." << endl; + return 1; } else { if (character>='a' && character<='z') { - cout << ", which is a lower case letter." << endl; + return 2; } else { if (character>= 'A' && character<='Z') { - cout << ", which is an upper case letter." << endl; + return 3; } else { - isNotAlphaNumeric=true; - cout << ", which is not a letter or a number." << endl; + return 0; } } - } + } +} + +int main () { + int test; + char character; + bool isNotAlphaNumeric=false; + while (!isNotAlphaNumeric) { + cout << "Enter a single digit or an alphabetic character: "; + cin >> character; + cout << "You entered " << character << ", "; + test = charTest(character); + if (test==0) { + isNotAlphaNumeric=true; + cout << "which is not a letter or a number."; + } + if (test==1) { + cout << "which is a number."; + } + if (test==2) { + cout << "which is a lower case letter."; + } + if (test==3) { + cout << "which is an upper case letter."; + } + cout << endl; } } diff --git a/ee1301/wk3/hw3_directory/strap012_HW3C.cpp b/ee1301/wk3/hw3_directory/strap012_HW3C.cpp index 69eb51f..5270241 100644 --- a/ee1301/wk3/hw3_directory/strap012_HW3C.cpp +++ b/ee1301/wk3/hw3_directory/strap012_HW3C.cpp @@ -14,7 +14,12 @@ Character Detection #include using namespace std; -char swapCase(char s) { +// Function: swapCase +// --------------------------- +// Swaps the case of a latin ASCII character and prints an error if not one +// s: the character + +void swapCase(char s) { char New; cout << "You entered " << s; if (s >= 'a' && s <= 'z') { -- cgit v1.2.3