From 4b59fe71c7bc4cb2d323d3f3da06a0715e550ef4 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Tue, 26 Feb 2019 14:56:18 -0600 Subject: Unbreak everything --- ee1301/wk3/hw3_directory/strap012_HW3A.cpp | 38 ++++++++++++------------ ee1301/wk3/hw3_directory/strap012_HW3B.cpp | 47 +++++++++++++++--------------- ee1301/wk3/hw3_directory/strap012_HW3C.cpp | 26 ++++++++--------- 3 files changed, 55 insertions(+), 56 deletions(-) diff --git a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp index c164829..b10c296 100644 --- a/ee1301/wk3/hw3_directory/strap012_HW3A.cpp +++ b/ee1301/wk3/hw3_directory/strap012_HW3A.cpp @@ -14,25 +14,6 @@ One-armed Bandit Simulator #include using namespace std; -int main () { - srand(88888888); //Seeds the RNG of the program to a constant of eight 8s - int w, d, winCount, winTest; - for (w=3; w<=6; w++) { - winCount=0; - for (d=9; d<=27; d++) { - winCount=0; - for (long n=1000000; n>0; n--) { - int winTest = spin_the_wheels(d, w); - winCount+=winTest; - } - cout << "w=" << w << ", d=" << d - << ": Simulated probability = m/n = " << (winCount / 1000000.0) * 100.0 << "%. " - << "Theoretical probability = " << (d / (pow(d, w))) * 100 << "%." << endl; - d+=2; - } - } -} - // Function: spin_the_wheels // --------------------------- // Simulates the one-armed bandit from the previous HW @@ -55,4 +36,23 @@ int spin_the_wheels(int d, int w) { } else { return 0; } +} + +int main () { + srand(88888888); //Seeds the RNG of the program to a constant of eight 8s + int w, d, winCount, winTest; + for (w=3; w<=6; w++) { + winCount=0; + for (d=9; d<=27; d++) { + winCount=0; + for (long n=1000000; n>0; n--) { + int winTest = spin_the_wheels(d, w); + winCount+=winTest; + } + cout << "w=" << w << ", d=" << d + << ": Simulated probability = m/n = " << (winCount / 1000000.0) * 100.0 << "%. " + << "Theoretical probability = " << (d / (pow(d, w))) * 100 << "%." << endl; + d+=2; + } + } } \ No newline at end of file diff --git a/ee1301/wk3/hw3_directory/strap012_HW3B.cpp b/ee1301/wk3/hw3_directory/strap012_HW3B.cpp index 1b3faed..128f5fa 100644 --- a/ee1301/wk3/hw3_directory/strap012_HW3B.cpp +++ b/ee1301/wk3/hw3_directory/strap012_HW3B.cpp @@ -14,6 +14,29 @@ Character Detection #include using namespace std; +// 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') + { + return 1; + } else { + if (character>='a' && character<='z') { + return 2; + } else { + if (character>= 'A' && character<='Z') { + return 3; + } else { + return 0; + } + } + } +} + int main () { int test; char character; @@ -39,27 +62,3 @@ int main () { cout << endl; } } - - -// 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') - { - return 1; - } else { - if (character>='a' && character<='z') { - return 2; - } else { - if (character>= 'A' && character<='Z') { - return 3; - } else { - return 0; - } - } - } -} \ No newline at end of file diff --git a/ee1301/wk3/hw3_directory/strap012_HW3C.cpp b/ee1301/wk3/hw3_directory/strap012_HW3C.cpp index 63d0686..e3fe714 100644 --- a/ee1301/wk3/hw3_directory/strap012_HW3C.cpp +++ b/ee1301/wk3/hw3_directory/strap012_HW3C.cpp @@ -14,18 +14,6 @@ Character Detection #include using namespace std; -int main() -{ - char character; - do { //This loops until '@' is entered - cout << "Please enter a character that is an ASCII letter in the range [A-Za-z]: "; - cin >> character; - if (character!='@') { - swapCase(character); - } - } while (character!='@'); -} - // Function: swapCase // --------------------------- // Swaps the case of a latin ASCII character and prints an error if not one @@ -46,4 +34,16 @@ void swapCase(char s) { } } cout << "." << endl; -} \ No newline at end of file +} + +int main() +{ + char character; + do { //This loops until '@' is entered + cout << "Please enter a character that is an ASCII letter in the range [A-Za-z]: "; + cin >> character; + if (character!='@') { + swapCase(character); + } + } while (character!='@'); +} -- cgit v1.2.3