Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
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++ (10th 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...Ch. 3 - You have an augmented reality game in which you...
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
- MULTIPLE CHOICE -The answer is one of the options below please solve carefully and circle the correct option Please write clear .arrow_forwardThis 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_forward
- Assume 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_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_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_forward
- A fish-finder is a device used by anglers to find fish in a lake. If the fish-finder finds a fish, it will sound an alarm. It uses depth readings to determine whether to sound an alarm. For our purposes, the fish-finder will decide that a fish is swimming past if:there are four consecutive depth readings which form a strictly increasing sequence (such as 3 4 7 9) (which we will call "Fish Rising"), orthere are four consecutive depth readings which form a strictly decreasing sequence (such as 9 6 5 2) (which we will call "Fish Diving"), orthere are four consecutive depth readings which are identical (which we will call "Constant Depth").All other readings will be considered random noise or debris, which we will call "No Fish."Create a Python program called "fishfinder_firstname_lastname" that takes 1 input of string of 4 numbers separated with comma. Your program must display "Fish Rising", "Fish Diving.", "Fish At Constant Depth" or "No Fish".Example:30,10,20,20 Must display No…arrow_forwardCelebrity problem A celebrity among a group of n people is a person who knows nobody but is known by everybody else. The task is to identify a celebrity by only asking questions to people of the form: ”Do you know him/her?” Solution Select two people from the group given, say, A and B, and ask A whether A knows B. If A knows B, remove A from the remaining people who can be a celebrity; if A doesn’t know B, remove B from this group. Solve the problem recursively for the remaining group of people who can be a celebrity Which design strategy does the following solution use? A-)Decrease-by-a-constant factor algorithm B-)Variable-size-decrease algorithm C-)Decrease-by-a-constant algorithm D-)Divide-and-Conquerarrow_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_forward
- Correct answer will be upvoted else Multiple Downvoted. Computer science. player begins the game from the 1-st stage and should beat the stages in expanding request of the stage number. The player dominates the match in the wake of beating the n-th stage. There is all things considered one designated spot on each stage, and there is consistently a designated spot on the 1-st stage. Toward the start of the game, just the designated spot on the 1-st stage is initiated, and any remaining designated spots are deactivated. At the point when the player gets to the I-th stage that has a designated spot, that designated spot is initiated. For each attempt of a phase, the player can either beat the stage or bomb the stage. On the off chance that they beat the I-th stage, the player is moved to the i+1-st stage. On the off chance that they bomb the I-th stage, the player is moved to the latest designated spot they actuated, and they need to beat the stages after that designated spot once…arrow_forwardJava Program Scenario: A high school has 1000 students and 1000 lockers, one locker for each student. On the first day of school, the principal plays the following game: She asks the first student to open all the lockers. She 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 fourth student is asked to check every fourth 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 that prompts 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…arrow_forwardThere are three boxes. One is labeled "APPLES" another is labeled "ORANGES". The last one is labeled "APPLES AND ORANGES". You know that each is labeled incorrectly. You may ask me to pick one fruit from one box which you choose. How can you label the boxes correctly? Select one: Pick from the one labeled "Oranges" b. Pick from the one labeled "Apples" Pick from the one labeled "Apples & Oranges" a. C.arrow_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