Homework 8 Solution UCR CS10: Introduction to Computer Science Winter Quarter 2004, Lecturer: Kris Miller Due Wednesday, March 3 before 8:00pm by web turnin. YOU MUST TURN THIS IN AS A .CPP, .CC, OR .C FILE. The turnin system will no longer accept other types of files. Your file names should not have spaces or non-alphanumeric characters. A good file name to use is hw7.cpp. ------------------------------------------------------------------------------- Note: Collaboration policy for this homework assignment Collaboration on this homework is strongly ENCOURAGED. The homework is intended for practice, not assessment -- most people who turn in decent work should get most if not all points for this assignment. Forming study groups is strongly encouraged. You shouldn't simply copy answers from any source -- each other, the book, the web, other books, previous solutions, etc. But you can certainly discuss how to solve the problems, look over each others solutions and help "debug" them, compare answers and redo problems if you determine your answer is wrong, and most importantly, explain concepts related to the problems and solutions. ------------------------------------------------------------------------------- 1. Self-test Exercise #7-1 (Chapter 7, #1) 2. Self-test Exercise #7-6 3. Self-test Exercise #7-16 4. Self-test Exercise #7-19 5. Self-test Exercise #7-21 6. Self-test Exercise #7-25 7. Self-test Exercise #7-26 8. Self-test Exercise #7-29 9. Self-test Exercise #7-33 Self-test Exercises have solutions at the end of the chapter. 10. Programming Project #1 - Chapter 7 (CodeMate) // -------------------------------- // ----- ENTER YOUR CODE HERE ----- // -------------------------------- // The outer if structure takes care of all player1Choice possibilities. // The nested if structures take care of all player2Choice possibilities // for each of player1Choice possibilities. // The getPlayerChoice function ensures that the characters 'P', 'p', // 'R', 'r', 'S', and 's' are the only possible values of player1Choice // and player2Choice. if (player1Choice == 'P' || player1Choice == 'p') { if (player2Choice == 'P' || player2Choice == 'p') { cout << "Nobody wins\n"; } else if (player2Choice == 'R' || player2Choice == 'r') { cout << "Player 1 wins: paper covers rock\n"; } else // player2Choice is 'S' or 's' { cout << "Player 2 wins: scissors cut paper\n"; } } else if (player1Choice == 'R' || player1Choice == 'r') { if (player2Choice == 'P' || player2Choice == 'p') { cout << "Player 2 wins: paper covers rock\n"; } else if (player2Choice == 'R' || player2Choice == 'r') { cout << "Nobody wins\n"; } else // player2Choice is 'S' or 's' { cout << "Player 1 wins: rock breaks scissors\n"; } } else // player1Choice is 'S' or 's' { if (player2Choice == 'P' || player2Choice == 'p') { cout << "Player 1 wins: scissors cut paper\n"; } else if (player2Choice == 'R' || player2Choice == 'r') { cout << "Player 2 wins: rock breaks scissors\n"; } else // player2Choice is 'S' or 's' { cout << "Nobody wins\n"; } } // -------------------------------- // --------- END USER CODE -------- // --------------------------------