Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 3, Problem 9PP
Program Plan Intro
The Monty Hall Game
Program plan:
- Include necessary header files.
- Declare the namespace.
- Define the “main()” function.
- Declare and initialize the necessary variables.
- The “while” checks the condition.
- True, call the function “rand()” to check, car behind the door.
- Select the door using the function “rand()”.
- The “if” loop checks the condition, “door_car” is equal to “door_select”.
- True, open the non-car door.
- Increment the value of the variable “OriginalChoice” by “1”.
- Otherwise, open the non-car door which is not selected by the user.
- Increment the value of the variable “OriginalChoice” by “1”.
- Print the result.
- Return “0”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Control Loops:
A high school 1000 students and 1000 lockers. The principal plays the following game: She asks dthe first student to open all the lockers. Shen then asks the second student to close all the even-numbered lockers. The third student is asked to check every third locker. If it is open, the student closes it; if it is closed, the student opens it. The remaining students continue this game . In general, the nth student checks every nth locker. If the locker is open, the student closes it; if it is closed, the student opens it. After all the students have taken their turns, some of the lockers are open and some are closed. Write a program thatprompts the user to enter the number of lockers in a school. After the game is over, the program outputs the number of lockers and the locker numbers of the lockers that are open. Test run your program for the following inputs: 1000, 5000, 10,000. Do you see any pattern developing for the locker numbers that are open in the output?…
Four in a row is a game in which players take turns adding tokens to the columns on the game board.
Tokens fall to the lowest position in the chosen column that does not already have a token in it. Once one of the players has placed four of their tokens in a straight line (either vertically, horizontally, or diagonally), they win the game
If the board is full and no player has won, then the game ends in a draw.
TASK
Using the following class descriptions, create a UML diagram and a version of Four in a row game
The game must allow for a minimum of two and maximum of four players
The game must allow each player to enter their name(duplicate names should not be accepted)
The game should give the players the ability to choose how many rows (between four and ten), and how many columns (between four and ten) the game board should have.
The code uses several classes, including "Player", "Board","Game" and exceptions for handling errors such as invalid moves and full columns.…
Use java language
Chapter 3 Solutions
Problem Solving with C++ (9th Edition)
Ch. 3.1 - Determine the value, true or false, of each of the...Ch. 3.1 - Name two kinds of statements in C++ that alter the...Ch. 3.1 - In college algebra we see numeric intervals given...Ch. 3.1 - Prob. 4STECh. 3.2 - What output will be produced by the following...Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - What would be the output in Self-Test Exercise 6...Ch. 3.2 - What would be the output in Self-Test Exercise 6...Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - What would be the output in Self-Test Exercise 9...
Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - Write a multiway if-else statement that classifies...Ch. 3.2 - Given the following declaration and output...Ch. 3.2 - Given the following declaration and output...Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - What would be the output in Self-Test Exercise 15...Ch. 3.2 - What would be the output in Self-Test Exercise 15...Ch. 3.2 - What would be the output in Self-Test Exercise 15...Ch. 3.2 - Prob. 19STECh. 3.2 - Though we urge you not to program using this...Ch. 3.3 - Prob. 21STECh. 3.3 - Prob. 22STECh. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - Prob. 25STECh. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - Prob. 27STECh. 3.3 - For each of the following situations, tell which...Ch. 3.3 - Rewrite the following loops as for loops. a.int i...Ch. 3.3 - What is the output of this loop? Identify the...Ch. 3.3 - What is the output of this loop? Comment on the...Ch. 3.3 - What is the output of this loop? Comment on the...Ch. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - What does a break statement do? Where is it legal...Ch. 3.4 - Write a loop that will write the word Hello to the...Ch. 3.4 - Write a loop that will read in a list of even...Ch. 3.4 - Prob. 38STECh. 3.4 - Prob. 39STECh. 3.4 - What is an off-by-one loop error?Ch. 3.4 - You have a fence that is to be 100 meters long....Ch. 3 - Write a program to score the paper-rock-scissor...Ch. 3 - Write a program to compute the interest due, total...Ch. 3 - Write an astrology program. The user types in a...Ch. 3 - Horoscope Signs of the same Element are most...Ch. 3 - Write a program that finds and prints all of the...Ch. 3 - Buoyancy is the ability of an object to float....Ch. 3 - Write a program that finds the temperature that is...Ch. 3 - Write a program that computes the cost of a...Ch. 3 - (This Project requires that you know some basic...Ch. 3 - Write a program that accepts a year written as a...Ch. 3 - Write a program that scores a blackjack hand. In...Ch. 3 - Interest on a loan is paid on a declining balance,...Ch. 3 - The Fibonacci numbers F are defined as follows. F...Ch. 3 - The value ex can be approximated by the sum 1 + x...Ch. 3 - Prob. 8PPCh. 3 - Prob. 9PPCh. 3 - Repeat Programming Project 13 from Chapter 2 but...Ch. 3 - The keypad on your oven is used to enter the...Ch. 3 - The game of 23 is a two-player game that begins...Ch. 3 - Holy digits Batman! The Riddler is planning his...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 1. Your objective is to guide a robot through a labyrinth. 1. Your objective is to guide a robot through a labyrinth. The robot begins at the maze's middle, looking north. You have the option of facing the robot north, east, south, or west. You may tell the robot to travel ahead a particular distance, but it will halt if it comes too close to a wall. i. Create a problem statement for this situation. What is the size of the state space? ii. The only location we need to turn while traversing a labyrinth is at the junction of two or more passageways. This remark may be used to reformulate the issue. What is the current size of the state space? iii. We may go in any of the four directions from any point in the labyrinth until we reach a turning point, and that is the only action we need to do. Using these steps, rephrase the issue. Is it necessary to maintain track of the robot's orientation at this point? iv. We already abstracted from the actual world in our original description…arrow_forwardMULTIPLE CHOICE -The answer is one of the options below please solve carefully and circle the correct option Please write clear .arrow_forwardChildren often play the game of rock, paper, and scissors. This game has two players, each of whom chooses one of the three objects: rock, paper, or scissors. If player 1 chooses rock and player 2 chooses paper, player 2 wins the game because paper covers the rock. The game is played according to the following rules: If both players choose the same object, this play is a tie. If one player chooses rock and the other chooses scissors, the player choosing the rock wins this play because the rock breaks the scissors. If one player chooses rock and the other chooses paper, the player choosing the paper wins this play because the paper covers the rock. If one player chooses scissors and the other chooses paper, the player choosing the scissors wins this play because the scissors cut the paper. Write an interactive program that allows 1 person to play this game against the computer. Input This program has two types of input: The users’ responses when asked to play the game. The…arrow_forward
- This challenge is based on the classic videogame "Snake". Assume the game screen is an n * n square, and the snake starts the game with length 1 (i.e. just the head) positioned on the top left corner. For example, if n = 7 the game looks something like this: BEGINNING In this version of the game, the length of the snake doubles each time it eats food (e.g. if the length is 4, after eating it becomes 8). Create a function that takes the siden of the game screen and returns the number of times the snake can eat before it runs out of space in the game screen. Examples FIRST MOVE snakefill (3) snakefill (6) - 5 snakefill (24) → 9 3arrow_forwardA video player plays a game in which the character competes in a hurdle race. Hurdles are of varying heights, and the characters have a maximum height they can jump. There is a magic potion they can take that will increase their maximum jump height by unit for each dose. How many doses of the potion must the character take to be able to jump all of the hurdles. If the character can already clear all of the hurdles, return . Example The character can jump unit high initially and must take doses of potion to be able to jump all of the hurdles. Function Description Complete the hurdleRace function in the editor below. hurdleRace has the following parameter(s): int k: the height the character can jump naturally int height[n]: the heights of each hurdle Returns int: the minimum number of doses required, always or more Input Format The first line contains two space-separated integers and , the number of hurdles and the maximum height the character can jump naturally.The…arrow_forwardAssume you are playing a card game using a standard 52-card deck. You are dealt a hand of cards that are all the same suit, hearts. You are dealt first a 5, then a 3, then 8, and finally 4. You first grab the 8. Next you grab the 5 and place it in front of the 8. Then you take the 4 and place it in front of the 5. Finally, you take the 3 and place it in front of the 4. Which sorting algorithm is most similar to how you sorted your hand?Group of answer choices 1.Merge Sort 2.Selection Sort 3.Quick Sort 4.Insertion Sortarrow_forward
- Python tic tac toe. Tic tac toe is a very popular game. Only two players can play at a time. Game Rules Traditionally the first player plays with "X". So you can decide who wants to go with "X" and who wants to go with "O". Only one player can play at a time. If any of the players have filled a square then the other player and the same player cannot override that square. There are only two conditions that may match will be a draw or may win. The player that succeeds in placing three respective marks (X or O) in a horizontal, vertical, or diagonal row wins the game. Winning condition Whoever places three respective marks (X or O) horizontally, vertically, or diagonally will be the winner. Submit your code and screenshots of your code in action. Hints : Have a function that draws the board Have a function that checks position if empty or not Have a function that checks player or won or not expected output:arrow_forwardPython tic tac toe. Tic tac toe is a very popular game. Only two players can play at a time. Game Rules Traditionally the first player plays with "X". So you can decide who wants to go with "X" and who wants to go with "O". Only one player can play at a time. If any of the players have filled a square then the other player and the same player cannot override that square. There are only two conditions that may match will be a draw or may win. The player that succeeds in placing three respective marks (X or O) in a horizontal, vertical, or diagonal row wins the game. Winning condition Whoever places three respective marks (X or O) horizontally, vertically, or diagonally will be the winner. Submit your code and screenshots of your code in action. Hints : Have a function that draws the board Have a function that checks position if empty or not Have a function that checks player or won or not expected output:arrow_forwardEmail me the answers to the following questions. If you are not familiar with Peg Solitaire, then look it up online. Peg Solitaire is a game consisting of a playing board with 33 holes together with 32 pegs. In the picture above, the hole in the center is empty and the remaining holes contain pegs. The goal is to remove all the pieces except one, which should be in the center. A piece can be removed by jumping an adjacent piece over it into an empty hole. Jumps are permitted horizontally or vertically, but not diagonally. Your assignment consists of one required part, plus one extra credit part: 1. Explain (in words) why Breadth First Search and Iterative Deepening are not good methods for this problem.arrow_forward
- Bob is playing a game. He and his team have come up with a plan to throw a ball so that it can hit the target object. The target is at a distance of X meters from Bob. He is at a height of Y meters from the ground and the target is at a height of Z meters from the ground. Bob can throw the ball with a certain speed Task Determine the speed that he should throw the ball. Notes He is aiming at an angle parallel to the ground. Assume acceleration due to gravity is 10m/s² Example Assumptions • X = 2 • Y=5 • Z=2 Approach It can be calculated that he needs to fire at speeds 2.58m/s at an angle parallel to the ground respectively. The answers are taken up to 2 decimal places only. Hence, the answer is 2.58 m/s. Function description Complete the solve function provided in the editor. This function takes the following 3 parameters and returns the minimum speed required: • X Represents an integer denoting the distance of the target from Bob • Y Represents an integer denoting the height of Bob…arrow_forwardA flight of stairs has 10 steps numbered 1 to 10 as shown in the figure below. i. How many ways could you climb up the set of stairs, assuming that you can skip any number of stairs with each step, but you must end on step 10 and you can only go up, never down and never remaining on the same step. ii. How many ways could you climb up the set of stairs, assuming you take exactly 4 steps. Again, your staircase climb ends on step 10. JAlthough there are different ways in which you could solve this problem, model the problem as a balls and bins problem for full credit.arrow_forwardThe Game of Master Mind is performed in the following way:Each of the computer's four slots will hold a ball that is either red (R), yellow (Y), green (G), or blue (B). The computer may have the following configuration: RGGB (Slot #1 is red, Slots #2 and #3 are green, and Slot #4 is blue).The user is making an educated guess at the answer. For instance, you may assume YRGB.You receive a bonus when you predict the right colour for the right slot "hit:' You receive an if you choose a colour that is real but is in the incorrect slot "pseudo-hit:' Keep in mind that a hit slot can never also qualify as a pseudo-hit.For example, if the actual solution is RGBY and you guess GGRR, you have one hit and one pseudohitWrite a method that, given a guess and a solution, returns the number of hits and pseudo-hitsarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT