Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

# include # include # include # include using namespace std; // Class prototype.

ID: 3528690 • Letter: #

Question

# include # include # include # include using namespace std; // Class prototype. class TripleString { // Private area for variables and methods. private: // Member data. string string_1; string string_2; string string_3; // Private helper method that mutators can use for testing legal string. bool validString (string str); // Public area for variables and methods. public: static const int MAX_LEN = 20; // Default constructor. TripleString (); TripleString (string str1, string str2, string str3); // Mutators for three different strings. bool SetString_1 (string string_1); bool SetString_2 (string string_2); bool SetString_3 (string string_3); // Accessors for three different strings. string GetString_1 (); string GetString_2 (); string GetString_3 (); };// End of making my own class. // Global-scope method prototype. // This method is used to introduce the program. void introduceProgram(); // This method is used to get input from the user and return the input as the bet amount. int getBet(); // This method instantiates and returns a TripleString object to the client. TripleString pull(); // This method produces and returns a single random string based on the required probabilities. string randString(); // This method is used to decide what the pay out will be: 5? 15? 100? 0? int getPayMultiplier (TripleString thePull); // This method displays the result which are whether the user wins or loses. void display (TripleString thePull, int winnings); // Main method. int main() { int user_input; int multiplier, prize; introduceProgram(); user_input = getBet(); while (user_input != 0) { TripleString test; test = pull(); multiplier = getPayMultiplier(test); prize = user_input * multiplier; display(test, prize); user_input = getBet(); } return 0; } // Define global-scope methods. // Introduce the program by using introduceProgram() method. void introduceProgram() { string introduce; introduce = " The prgram manipulates casino's game with Methods and Class. " "The program will loop, asking the user for a bet amount from 0 " "to 100.If the user types a 0 that means he/she wants to quit. " "Otherwise, accept the amount as their bet and simulate a slot " "machine pull. Your program will print out a line that looks like " "a slot machine result containing three strings. If the user did " "not win, tell him/her 'Sorry, you lose.' If he won, pay him by " "displaying his winnings. "; cout << "---------------------------------------------------------------"; cout << introduce; cout << "---------------------------------------------------------------"; cout << endl; } // Get the value from the user by using getBet() method. int getBet() { int input; cout << "How much money are you going to bet for this pull?" << endl; cout << "Enter the amount from 1 to 100 for the bet, or 0 to quit:"; cin >> input; while (input < 0 || input > 100) { cout << "Enter the amount from 1 to 100 for the bet, or 0 to quit:"; cin >> input; } if (input == 0) return 0; else return input; } // Simulate a random pull of the slot machine by using pull(). TripleString pull() { string string_1, string_2, string_3; string_1 = randString(); string_2 = randString(); string_3 = randString(); return TripleString(string_1,string_2,string_3); } // Determine the result after the users enter a value by using randString(). string randString() { int random_number; // Outputs will be between 0 and 100. random_number = rand() % 100 + 1 ; // Check where the random number is laying. if (random_number <= 50) return "BAR"; else if (random_number > 50 || random_number <=75) return "CHERRIES"; else if (random_number > 75 || random_number <= 87.5) return "SPACE"; else return "7"; } // Decide what the payout will be by using getPayMultiplier(TripleString thePull). int getPayMultiplier (TripleString thePull) { int payout; string string_1, string_2, string_3; string_1 = thePull.GetString_1(); string_2 = thePull.GetString_2(); string_3 = thePull.GetString_3(); if (string_1 == "CHERRIES" && string_2 != "CHERRIES") return payout = 5; else if (string_1 == "CHERRIES" && string_2 == "CHERRIES" && string_3 != "CHERRIES") return payout = 15; else if (string_1 == "CHERRIES" && string_2 == "CHERRIES" && string_3 == "CHERRIES") return payout = 30; else if (string_1 == "BAR" && string_2 == "BAR" && string_3 == "BAR") return payout = 50; else if (string_1 == "7" && string_2 == "7" && string_3 == "7") return payout = 100; else return payout = 0; } // Decide whether the user wins or loses by using display(TripleString thePull, int winnings). void display (TripleString thePull, int winnings) { string string_1, string_2, string_3; string_1 = thePull.GetString_1(); string_2 = thePull.GetString_2(); string_3 = thePull.GetString_3(); cout << "----------------------------------------------------------" << endl; cout << "Are you ready for the biggest prize? LET'S PULL THE STICK." << endl; cout << "Check it out with your pull: " << endl; cout << "[ " << string_1 << " | " << string_2 << " | " << string_3 << " ]" << endl; cout << "----------------------------------------------------------" << endl; if (winnings != 0) cout << "Congratulation! You won! Your prize will be: $" << winnings << endl; cout << "Sorry! You lost! Wish you the best luck next time." << endl; } // Define my own class methods. // Default constructor. TripleString::TripleString() { string_1 == ""; string_2 == ""; string_3 == ""; } // Parameter constructer. TripleString::TripleString(string str1, string str2, string str3) { if (!SetString_1(str1)) str1 == ""; if (!SetString_2(str2)) str2 == ""; if (!SetString_3(str3)) str3 == ""; } // Private method validString is used to help mutators. bool TripleString::validString (string str) { if (str.length() <= MAX_LEN) return true; else return false; } // These are the three mutators for each string. // Mutator for string_1. bool TripleString::SetString_1(string string_1) { if (!validString (string_1)) return string_1 == ""; else return true; } // Mutator for string_2. bool TripleString::SetString_2(string string_2) { if (!validString (string_2)) return string_2 == ""; else return true; } // Mutator for string_3. bool TripleString::SetString_3(string string_3) { if(!validString (string_3)) return string_3 == ""; else return true; } //These are the three accessors for each string. // Accessor for string_1. string TripleString::GetString_1 () { return string_1; } //Accessor for string_2. string TripleString::GetString_2 () { return string_2; } //Accessor for string_3. string TripleString::GetString_3 () { return string_3; }

Explanation / Answer

www.youtube.com/watch?v=3Lcac1MSXLQ Good example to watch