Problem Solving with C++, Student Value Edition
10th Edition
ISBN: 9780134543680
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 5, Problem 6PP
Program Plan Intro
Creation of main method to compute a value to find greatest puzzler
Program Plan:
- Define a method “shoot()” for simulation of a single shot.
- It simulates shooting at “targetAlive” with given “accuracy”.
- It generates a random number in between 0 and 1.
- If random number goes less than “accuracy”, target is hit also “targetAlive” is set to false.
- Define a method “startDuel()” for duel simulation.
- Declare variables used in function.
- Call “shoot()” method to simulate entire duel with this strategy.
- It loops until one contestant remains.
- It invokes shoot function with value for target as well as probability for hitting target.
- It returns a value that indicates the winner of duel.
- Define the main method.
- Declare variables required for the function.
- Call method “startDuel()” to simulation of a duel.
- It returns a value that indicates the winner of duel.
- It updates values for winners.
- Display values of percentages of win.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write an application with following method to resolve two player game of Rock-Paper-Scissors. rockPaperScissors method takes two parameters: a string representing a first player's move in a game of Rock-Paper-Scissors and a string representing a second player's move. Depending on each player's move, the function should output to the console the winner of the round if there was a winner, a tie if both players had the same move, or whether a player gave an invalid move. When comparing moves, letter-casing does not matter ("rock" should be considered the same move as "rOcK"). The two-player game of Rock-Paper-Scissors works as following: Each player chooses one of three moves: "rock", "paper", or "scissors". A move of "rock" wins over another player's move of "scissors". A move of "scissors" wins over another player's move of "paper". A move of "paper" wins over another player's move of "rock". If two players use the same move, the result is a tie For example, a call of…
Write the following program in python;
There is a class with m number of students and they have n number of lessons.
a)For each lesson the program has to find arithmetic,geometric,harmonic average of class
b)point avarage of each student
c)student numbers of highest and lowest avarage point of the class and those points too also
d)for each lesson result of highest point minus lowest point
e)for each lesson result of highest avarage minus lowest avarage
NOTE: M and N numbers will be choosed by keyboard after.
Write a program that plays the tic-tac-toe game. Two players take turns clicking an available cell in a grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal, vertical,or diagonal row on the grid, the game is over and that player has won. A draw (no winner) occurs when all the cells in the grid have been filled with tokens and neither player has achieved a win. Figure 12.17 shows the representative sample runs of the example.
Assume that all the cells are initially empty, and that the first player takes the X token and the second player the O token. To mark a cell, the player points the mouse to the cell and clicks it. If the cell is empty, the token (X or O) is displayed. If the cell is already filled, the player’s action is ignored.Define a custom class named Cell that extends Label for displaying a token and for responding to the button-click event. The class contains a data field token with three possible values—' ', X, and…
Chapter 5 Solutions
Problem Solving with C++, Student Value Edition
Ch. 5.1 - What is the output of the following program?...Ch. 5.1 - Are you required to have a return statement in a...Ch. 5.1 - Suppose you omitted the return statement in the...Ch. 5.1 - Prob. 4STECh. 5.1 - Prob. 5STECh. 5.1 - Is a call to a void function used as a statement...Ch. 5.2 - What is the output of the following program?...Ch. 5.2 - What would be the output of the program in Display...Ch. 5.2 - What would be the output of the program in Display...Ch. 5.2 - Prob. 10STE
Ch. 5.2 - Write a void function definition for a function...Ch. 5.2 - Prob. 12STECh. 5.3 - Prob. 13STECh. 5.3 - Prob. 14STECh. 5.3 - Rewrite the function declaration comment for the...Ch. 5.3 - Prob. 16STECh. 5.4 - Prob. 17STECh. 5.4 - Prob. 18STECh. 5.4 - Prob. 19STECh. 5.4 - Prob. 20STECh. 5.4 - Prob. 21STECh. 5.4 - Write a stub for the function whose function...Ch. 5.5 - Prob. 23STECh. 5.5 - Prob. 24STECh. 5.5 - Prob. 25STECh. 5 - Write a function that computes the average and...Ch. 5 - Write a program that reads in a length in feet and...Ch. 5 - Write a program like that of the previous exercise...Ch. 5 - (You should do the previous two Practice Programs...Ch. 5 - Write a program that reads in a weight in pounds...Ch. 5 - Write a program like that of the previous exercise...Ch. 5 - (You should do the previous two Practice Programs...Ch. 5 - (You need to do Practice Programs 4 and 7 before...Ch. 5 - The area of an arbitrary triangle can be computed...Ch. 5 - Write a program that converts from 24-hour...Ch. 5 - Write a program that requests the current time and...Ch. 5 - Modify your program for Programming Project 2 so...Ch. 5 - Write a program that tells what coins to give out...Ch. 5 - In cold weather, meteorologists report an index...Ch. 5 - Prob. 6PPCh. 5 - Write a program that inputs a date (for example,...Ch. 5 - Complete the previous Programming Project and...
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
- Let c(x) be "x is in this class", j(x) be "x knows how to write programs in JAVA", and h(x) be "x can get a highpaying job". Explain which rules of inference are used to get "Someone in this class can get a high-payingjob.", if we have the arguments ’Doug, a student in this class, knows how to write programs in JAVA’, and’Everyone who knows how to write programs in JAVA can get a high-paying jobarrow_forwardC++ Write a program that simulates the minute-by-minute operation of a checkout line, such as one you might find in a retail store. Use the following parameters: Customers arrive at the checkout line and stand in line until the cashier is free. When they reach the front of the line, they occupy the cashier for some period of time (referred to as ServiceTime) measured in minutes. After the cashier is free, the next customer is served immediately. Customers arrive at the checkout line at ArrivalRate per minute. Use the function included below (customerArrived()) to return the number of customers arriving in a given minute, determined randomly. The line can only hold so many people, MaxLineSize, until new arriving customers get frustrated and leave the store without purchasing anything. The overall time of the simulation is SimulationTime, measured in minutes. The program should take 5 inputs (to be read from a text file named simtest.txt, one per line): SimulationName - a string…arrow_forwardvvvHarry has a big wall clock, that got hit while he was playing. Now, the minute hand doesn't rotate by the angle 2π/3600 each second, but now it moves according to different angle x. You can assume that coordinates of the centre of the clock are (0, 0) and the length of the minute hand is l. One endpoint of the minute hand is always located at the clock centre; the other endpoint is initially located at the point (0, l). One second later, Harry observes that this endpoint is at distance d above the x-axis, i.e., the y-coordinate of this endpoint is equal to d. Harry is curious about where the minute hand will be (specifically, its y-coordinate) after t seconds. Because t can be very large, Harry can't wait for that moment. Please help him to write a python code that prints a single line containing the output.Input: 4 2 2Output4Harry has a big wall clock, that got hit while he was playing. Now, the minute hand doesn't rotate by the angle 2π/3600 each second, but now it moves according…arrow_forward
- CODE IN PYTHON In an alternate reality, chemistry Professors Hodge and Sibia have teamed up to design a chemical compound X such that when X is added to Dan’s favorite food (saltine crackers), it’ll make him despise it. For this, they are working with 6 kinds of extracts: Singleton Extracts: berries (B), green veggies (G), dairy (D) Combination Extracts: icecream (I), salad (S), and cheese sauce (C) Like regular food, mixing two extracts of the same kind will result in an extract of the same kind (eg. mixing berries B with berries B will result in berries B). Mixing two singleton extracts will result in a combination extract, using these rules: Berries (B) + Green Veggies (G) = Salad (S) Berries (B) + Dairy (D) = Icecream (I) Green Veggies (G) + Dairy (D)= Cheese Sauce (C) Mixing two combination extracts will result in a singleton extract closest to them. For example, Icecream (I) + Salad (S) is closest to Berries (B) since both Icecream and Salad extracts require using Berry…arrow_forwardWrite a program in c++ that will allow a user to find the hypotenuse of a right triangle using the Pythagorean Theorem. Note: In triangle ABC, given the figure, side c is the hypotenuse.arrow_forwardWRITE CODE IN C LANGUANGE On their way down the river, Jojo and Lili saw two frogs each in position X1 and X2. The two frogs are seen jumping happily towards the same direction that is come to Jojo. After watching the two frogs, Joio and Lili saw that the speed the two frogs are different. The first frog to start jumping from position X1 has a speed of v1, while the second frog that starts to jump from position X2 has a speed of V2. Joig guess that "YES" both frogs will be in the same position in a certain time T, while Bibi guessing "NO" the two frogs will never be in the same position in time. Help Joio and Lili calculate the frog's movements to determine whether the guess they are rightarrow_forward
- Write a program IN JAVA for an instructor whose course has the following policies: Two quizzes, each graded on the basis of 10 points, are given. One midterm exam and one final exam, each graded on the basis of 100 points, are given. The final exam counts for 50 percent of the grade, the midterm counts for 25 percent, and the two quizzes together count for a total of 25 percent. (Do not forget to normalize the quiz scores. They should be converted to percentages before they are averaged in.) Any grade of 90 percent or more is an A, any grade between 80 and 89 percent is a B, any grade between 70 and 79 percent is a C, any grade between 60 and 69 percent is a D, and grade below 60 percent is an F. The program should read in the student’s scores and display the student’s record, which consists of two quizzes scores, two exams scores, the student’s total score for the entire course, and the final letter grade. The total score is a number in the range to 100, which represents the…arrow_forwardThe questions should be completed with OCaml. Running screenshots should be provided. The background information is given by the picture. Question 1: Provide 5 good test cases each for eval_success_tests and eval_failure_tests, following the format of: let eval_success_tests : ((truth_assignment * formula) * bool) list = [] let eval_failure_tests : ((truth_assignment * formula) * exn) list = [] Question 2: Implement the function eval : truth_assignment -> formula -> bool. let eval (state : truth_assignment) (formula : formula) : bool = raise Not_implemented You are evaluating boolean formulae instead of float arithmetic. You also need to use the correct boolean value for each variable. We recommend using Variable_map.find_opt to perform lookups in the truth assignment. If a variable is needed but does not appear in the truth assignment, you must raise an Unassigned_variable x exception, where x is the unassigned variable. Once again, you may use any functions you want and…arrow_forward(A) Write a program for the Online Turing Machine Simulator to simulate a Turing Machine with one tape that recognizes the language O. Language O {w | w ∈ {a, b}* and a(w) <= b(w)} a(w) = number of a's in a string w. b(w) = number of b's in a string w. (B) Test the Turing Machine with one tape for: one string from the language O one string from the language M or language N Language M M = {w | w ∈ {a, b}* and a(w) == b(w)}. a(w) = number of a's in a string w. b(w) = number of b's in a string w. Language N N = {w | w ∈ {a, b}* and a(w) >= b(w)}. a(w) = number of a's in a string w. b(w) = number of b's in a string w.arrow_forward
- In javascript: Page #1: Greets User 1 (The Word Chooser) and asks for their Name, a word, and the number of wrong guesses they would like to give User 2(The Guesser).User 1 then clicks the "Go" button, which leads to page 2. Page #2: Greets User 2 by telling them the word choosers name and how many guesses they have been given for the word, they initially see a "-" for each unguessed letter, and a counter with remaining bad guesses. They must also be shown previously guessed letters. There is a place for them to enter their name and to guess letters. After all guesses are done, win or lose, the page goes to: Page #3: Congratulates the user, or informs them of their failure to guess the word. This page must show: User 1 Name User 2 Name Word they were trying to guessarrow_forwardin java using import java.util.Scanner; Bowling involves 10 frames. Each frame starts with 10 pins. The bowler has two throws to knock all 10 pins down. The total score is the sum of pins knocked down, with some special rules. For the first 9 frames: If all 10 pins are knocked down on a frame's first throw (a "strike"), that frame's score is the previous frame plus 10 plus the next two throws. (No second throw is taken). If all 10 pins are knocked down after a frame's second throw (a "spare"), that frame's score is the previous frame plus 10 plus the next throw. In the 10th frame, if the bowler's first throw is a strike, or the first two throws yields a spare, the bowler gets a third throw. The 10th frame's score is the previous frame's score plus the pins knocked down in the 10th frame's two or three throws. Given integers represents all throws for a game, output on one line each frame's score followed by a space (and end with a newline). Note that the number of throws may be as…arrow_forwardWrite a program in C that simulates a checkout line at a supermarket. The line is a queue object. Customers (i.e.,customer objects) arrive in random integer intervals of 1–4 minutes. Also, each customer is served in randominteger intervals of 1–4 minutes. Obviously, the rates need to be balanced. If the average arrival rate is largerthan the average service rate, the queue will grow infinitely. Even with “balanced” rates, randomness can stillcause long lines. Run the supermarket simulation for a 12-hours a day (720 minutes) using the followingalgorithm:1. Choose a random integer from 1 to 4 to determine the minute at which the first customer arrives.2. At the first customer’s arrival time: Determine customer’s service time (random integer from 1 to 4);Begin servicing the customer. Schedule arrival time of next customer (random integer 1 to 4 added to the current time).3. For each minute of the day: If the next customer arrives, Say so, Enqueue the customer.Schedule the arrival time of…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education