Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MATLAB PROGRAMMING LANGUAGE Educational Goals The goals of this program are that the student should use the concepts of design using pseudocode output of prompts

MATLAB PROGRAMMING LANGUAGEimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Educational Goals The goals of this program are that the student should use the concepts of design using pseudocode output of prompts and labels to match specified output using random library functions strings calculations in assignment statements accumulators .if/else statements indefinite loop /input validation using sentinel logic documentation Your task You are going to write a program that will play a dice game called Twenty One. The Rules of the game There are two players, Player 1 and Player 2 They take turns rolling a six-sided die. The player adds the number they rolled to their running total. They play rounds until one of the players reaches 21. The first player who reaches 21 or over loses. Each player has two chances to "pass" meaning that they don't roll the die, their total doesn't change on that round Sample Run (user input is in red): The output of your program must match the following exactly, including spaces, uppercase/lowercase, newlines, etc Who is player 1? John Who is player 2? Mary Round 1: Player John (P)ass or (R)oll? John passed the roll Player Mary (P)ass or (R)oll? R rolled a 6 ohn total roll 0 passes 1 Mary total roll 6 passes 2 Round 2: Player John (P)ass or (R)oll? R rolled a 1 Player Mary (P)ass or (R)oll? R rolled a 3 ohn total roll 1 passes 1 Mary total roll 9 passes 2 Round 3: Player John (P)ass or (R)oll? R rolled a 4 Player Mary (P)ass or (R)oll? R rolled a 3 ohn total roll 5 passes 1 Mary total roll 12 passes2 Round 4: Player John (P)ass or (R)oll? R rolled a 1 Player Mary (P)ass or (R)o1l? P Mary passed the roll John total roll 6 passes 1Mary total roll 12 passes 1 Round 5: Player John (P)ass or (R)ol1? R rolled a 6 Player Mary (P)ass or (R)oll? R rolled a 2 John total roll 12 passes 1 Mary total roll 14 passes 1 Round 3: Player John (P)ass or (R)ol1? R rolled a 4 Player Mary (P)ass or (R)ol1? R rolled a3 ohn total roll 5 passes 1Mary total roll 12 passes 2 Round 4 Player John (P)ass or(R)ol1? R rolleda 1 Player Mary (P)ass or (R)oll? P Mary passed the roll John total roll 6 passes 1Mary total roll 12 passes 1 Round 5 Player John (P)ass or (R)oll2 R rolled a 6 Player Mary (P)ass or (R)oll?R rolled a 2 John total roll 12 passes Mary total roll 14 passes 1 Round 6: Player John (P)ass or (R)oll?R rolled a 4 Player Mary (P)ass or (R)ol1? x Invalid response. P or R please Player Mary (P)ass or (R)oll? x Invalid response. P or R please Player Mary (P)ass or (R)oll?R rolled a 4 John total roll 16 passes 1 Mary total roll 18 passes 1 Round 7 Player John (P)ass or ()oll? P John passed the roll Player Mary (P)ass or (R)oll? R rolled a 4 John total roll 16 passes Mary total roll 22 passes 1 John wins! Testing Main script: Description of Cases Inputs Expected Outputs/ Actions first 4 turns, players totals should not change, pass counts reduce to zero, after 4 turns, rolls are automatically done without asking 1. Normal play, ALL passes of both players used 2. Normal play, NO passes usedR by either player 3. Player 1 wins 4. Player 2 wins R,R,R,R.. rolls are added to player's total accordingly R, R, Player 2's total equals or exceeds 21 first Player 1's total equals or exceeds 21 first play turn function Description of Cases Inputs (total rolls, passes, choice) Expected Outputs Actions 0, 2, "P" 0,2, "R", roll is 4 Normal, player has 2 passes, uses one Normal, player has 2 passes, rolls Normal, player has 1 pass, uses one Normal, player has 1 pass, rolls Normal, player has no passes, rolls automatically 5, 0, no choice needed, rolls 3 returns 0, 1 returns 4, 2 returns 5.0 returns 9,1 returns 8, 0 6,1,"R", roll is 3 pass_or_roll function Description of Cases Inputs Expected Outputs / Actions Normal input first Normal input first Normal input first Normal input first One invalid input, then valid "X""P"gives error message, returns "P" Two invalid inputs, then valid "X","X","P" gives error message, gives error message, returns "P" returns "R" returns "R" returns "P" returnsP Design Decide on what steps you will need to perform to solve this problem. Put it in MATLAB form as comments. Do this for the design of the two functions below A rough design for the main program % title / instructions % get players' names % do setup, initialization, etc. % while neither player has lost display the round number do player 1's turn if player 1 didn't lose, do player 2's turn % display results of the turns (names, roll totals and pass counts) % announce who won Your design MUST include the following two functions as well as the main script. They must be defined to do the jobs given and they must be called somewhere in the program. NOTE: neither of these functions has anything to do with winning or losing. That (winning and losing) is decided in the main program. All these functions do is the job that is described below play turn has 3 input parameters and two return values (output parameters) The input parameters are the player's name, the player's total roll, the player's pass count. The outputs are the new total roll and pass count. The function plays one player's turn. The logic: o if the player still has a pass, then ask them if they want to Roll 'R Pass 'P. . Call the pass_or_roll function (described below) to do this. o if they pass, then subtract one from the pass count o if they roll, then get a roll of the die and add it to their total Note that if the player does NOT have any passes left, the program doesn't ask them if they want to Roll or Pass, it just goes ahead and rolls. Since you don't know ahead of time which one they will do (roll or pass), the function will modify either the total roll and the pass count. Only one of those will change for each execution of the function, but the function will always return both of them. pass_or_roll has one input parameter and one return value The parameter is the player's name, to customize the prompt. The return value is their answer of either 'R' or 'P, converted to uppercase The function uses sentinel logic to validate the user's input The function will accept either upper or lower case input. As usual with validation, if the user gives something other than 'P or 'R', an error message is displayed and they get another chance. The function returns the uppercase version of the user's response. Implementation Write a MATLAB program to implement your design. Start with a copy of the MATLAB file you have that has the design in it and write your MATLAB code between the commented lines of the design. Make sure you eliminate any syntax and semantics errors Verify that the program provides the correct behavior. First, implement pass_or_roll, and write a short script to test it. Try all the test cases listed above. Once that is working. mplement play_turn, and modify your script program to test it, again using the test cases listed above. Finally, once you are confident that play_turn works, implement your main program and test that. Educational Goals The goals of this program are that the student should use the concepts of design using pseudocode output of prompts and labels to match specified output using random library functions strings calculations in assignment statements accumulators .if/else statements indefinite loop /input validation using sentinel logic documentation Your task You are going to write a program that will play a dice game called Twenty One. The Rules of the game There are two players, Player 1 and Player 2 They take turns rolling a six-sided die. The player adds the number they rolled to their running total. They play rounds until one of the players reaches 21. The first player who reaches 21 or over loses. Each player has two chances to "pass" meaning that they don't roll the die, their total doesn't change on that round Sample Run (user input is in red): The output of your program must match the following exactly, including spaces, uppercase/lowercase, newlines, etc Who is player 1? John Who is player 2? Mary Round 1: Player John (P)ass or (R)oll? John passed the roll Player Mary (P)ass or (R)oll? R rolled a 6 ohn total roll 0 passes 1 Mary total roll 6 passes 2 Round 2: Player John (P)ass or (R)oll? R rolled a 1 Player Mary (P)ass or (R)oll? R rolled a 3 ohn total roll 1 passes 1 Mary total roll 9 passes 2 Round 3: Player John (P)ass or (R)oll? R rolled a 4 Player Mary (P)ass or (R)oll? R rolled a 3 ohn total roll 5 passes 1 Mary total roll 12 passes2 Round 4: Player John (P)ass or (R)oll? R rolled a 1 Player Mary (P)ass or (R)o1l? P Mary passed the roll John total roll 6 passes 1Mary total roll 12 passes 1 Round 5: Player John (P)ass or (R)ol1? R rolled a 6 Player Mary (P)ass or (R)oll? R rolled a 2 John total roll 12 passes 1 Mary total roll 14 passes 1 Round 3: Player John (P)ass or (R)ol1? R rolled a 4 Player Mary (P)ass or (R)ol1? R rolled a3 ohn total roll 5 passes 1Mary total roll 12 passes 2 Round 4 Player John (P)ass or(R)ol1? R rolleda 1 Player Mary (P)ass or (R)oll? P Mary passed the roll John total roll 6 passes 1Mary total roll 12 passes 1 Round 5 Player John (P)ass or (R)oll2 R rolled a 6 Player Mary (P)ass or (R)oll?R rolled a 2 John total roll 12 passes Mary total roll 14 passes 1 Round 6: Player John (P)ass or (R)oll?R rolled a 4 Player Mary (P)ass or (R)ol1? x Invalid response. P or R please Player Mary (P)ass or (R)oll? x Invalid response. P or R please Player Mary (P)ass or (R)oll?R rolled a 4 John total roll 16 passes 1 Mary total roll 18 passes 1 Round 7 Player John (P)ass or ()oll? P John passed the roll Player Mary (P)ass or (R)oll? R rolled a 4 John total roll 16 passes Mary total roll 22 passes 1 John wins! Testing Main script: Description of Cases Inputs Expected Outputs/ Actions first 4 turns, players totals should not change, pass counts reduce to zero, after 4 turns, rolls are automatically done without asking 1. Normal play, ALL passes of both players used 2. Normal play, NO passes usedR by either player 3. Player 1 wins 4. Player 2 wins R,R,R,R.. rolls are added to player's total accordingly R, R, Player 2's total equals or exceeds 21 first Player 1's total equals or exceeds 21 first play turn function Description of Cases Inputs (total rolls, passes, choice) Expected Outputs Actions 0, 2, "P" 0,2, "R", roll is 4 Normal, player has 2 passes, uses one Normal, player has 2 passes, rolls Normal, player has 1 pass, uses one Normal, player has 1 pass, rolls Normal, player has no passes, rolls automatically 5, 0, no choice needed, rolls 3 returns 0, 1 returns 4, 2 returns 5.0 returns 9,1 returns 8, 0 6,1,"R", roll is 3 pass_or_roll function Description of Cases Inputs Expected Outputs / Actions Normal input first Normal input first Normal input first Normal input first One invalid input, then valid "X""P"gives error message, returns "P" Two invalid inputs, then valid "X","X","P" gives error message, gives error message, returns "P" returns "R" returns "R" returns "P" returnsP Design Decide on what steps you will need to perform to solve this problem. Put it in MATLAB form as comments. Do this for the design of the two functions below A rough design for the main program % title / instructions % get players' names % do setup, initialization, etc. % while neither player has lost display the round number do player 1's turn if player 1 didn't lose, do player 2's turn % display results of the turns (names, roll totals and pass counts) % announce who won Your design MUST include the following two functions as well as the main script. They must be defined to do the jobs given and they must be called somewhere in the program. NOTE: neither of these functions has anything to do with winning or losing. That (winning and losing) is decided in the main program. All these functions do is the job that is described below play turn has 3 input parameters and two return values (output parameters) The input parameters are the player's name, the player's total roll, the player's pass count. The outputs are the new total roll and pass count. The function plays one player's turn. The logic: o if the player still has a pass, then ask them if they want to Roll 'R Pass 'P. . Call the pass_or_roll function (described below) to do this. o if they pass, then subtract one from the pass count o if they roll, then get a roll of the die and add it to their total Note that if the player does NOT have any passes left, the program doesn't ask them if they want to Roll or Pass, it just goes ahead and rolls. Since you don't know ahead of time which one they will do (roll or pass), the function will modify either the total roll and the pass count. Only one of those will change for each execution of the function, but the function will always return both of them. pass_or_roll has one input parameter and one return value The parameter is the player's name, to customize the prompt. The return value is their answer of either 'R' or 'P, converted to uppercase The function uses sentinel logic to validate the user's input The function will accept either upper or lower case input. As usual with validation, if the user gives something other than 'P or 'R', an error message is displayed and they get another chance. The function returns the uppercase version of the user's response. Implementation Write a MATLAB program to implement your design. Start with a copy of the MATLAB file you have that has the design in it and write your MATLAB code between the commented lines of the design. Make sure you eliminate any syntax and semantics errors Verify that the program provides the correct behavior. First, implement pass_or_roll, and write a short script to test it. Try all the test cases listed above. Once that is working. mplement play_turn, and modify your script program to test it, again using the test cases listed above. Finally, once you are confident that play_turn works, implement your main program and test that

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago