Great Deal! Get Instant \$10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

# CPSC1012 Assignment 3 Part 1 - Fall 2022 Term CPSC1012 Assignment 3 Part 1 – Methods Weight: 5% of your final mark Due Date: 11:50pm Tuesday, November 15, 2022 (Late submissions will not be...

CPSC1012 Assignment 3 Part 1 - Fall 2022 Term
CPSC1012 Assignment 3 Part 1 – Methods
Weight: 5% of your final mark
Due Date: 11:50pm Tuesday, November 15, 2022 (Late submissions will not be graded)
Introduction
In this assignment you will design and write a modularized menu-driven program that allows the user to select one
of two games (Craps and Pig) to play or to quit the program. The description of the two games are described next.
Game of Craps
In the game of craps, a pass line bet proceeds as follows: Two six-sided dice are rolled; the first roll of the dice in a
craps round is called the "come out roll." A come out roll of 7 or 11 automatically wins, and a come out roll of 2, 3,
or 12 automatically loses. If 4, 5, 6, 8, 9, or 10 is rolled on the come out roll, that number becomes "the point." The
player keeps rolling the dice until either 7 or the point is rolled. If the point is rolled first, then the player wins the
et. If a 7 is rolled first, then the player loses.
Write code to play a variation of the game as follows:
• Ask the user for a wager amount
• Roll two six-sided dice.
• Check the sum of the two dice.
o If the sum is 2, 3, or 12 (called craps), you lose.
o If the sum is 7 or 11 (called naturals), you win.
o If the sum is another value (i.e., 4, 5, 6, 8, 9, or 10), a point is established. Continue to roll the
dice until either a 7 or the same point value is rolled. If 7 is rolled, you lose. Otherwise you win.
• Ask the user if they want to play another round
• If the user does not want to play another round, display the total amount of money they won or lost.
Here is a sample run:
-----------------
| Game of Craps |
-----------------
Enter amount to bet: 20
You rolled 5 + 6 = 11
You win \$20.00
Do you want to play again (y/n): y
Enter amount to bet: 5
You rolled 1 + 2 = 3
You lost \$5.00
Do you want to play again (y/n): y
Enter amount to bet: 5
You rolled 4 + 4 = 8
Point is 8
You rolled 2 + 6 = 8
You win \$5.00
Do you want to play again (y/n): y
Enter amount to bet: 5
You rolled 2 + 3 = 5
Point is 5
You rolled 5 + 2 = 7
You lost \$5.00
Do you want to play again (y/n): y
Enter amount to bet: 5
You rolled 3 + 3 = 6
Point is 6
CPSC1012 Assignment 3 Part 1 - Fall 2022 Term
You rolled 5 + 3 = 8
You rolled 5 + 5 = 10
You rolled 1 + 2 = 3
You rolled 5 + 4 = 9
You rolled 4 + 3 = 7
You lost \$5.00
Do you want to play again (y/n): n
Game of Pig
The game of Pig is a simple two-player dice game in which the first player to reach the user inputted game total or
more points wins. Players take turns. On each turn, a player rolls a six-sided die:
• If the player rolls a 1, then the player gets no new points and it becomes the other player’s turn.
• If the player rolls 2 through 6, then he or she can either:
o ROLL AGAIN or
o HOLD. At this point, the sum of all rolls is added to the player’s score, and it becomes the other
player’s turn.
Write code to play the game of Pig, where one player is a human and the other is the computer. When it is the
human’s turn, the program shows the score of both players and the previous roll. Allow the human to input ‘r’ to
oll again or ‘h’ to hold.
The computer program should be played according to the following rules:
• Keep rolling when it is the computer’s turn until it has accumulated 10 or more points, then hold. If the
computer wins or rolls a 1, then the turn ends immediately.
Allow the human to roll first.
Here are some sample runs (the colors in the console do not have to match):
---------------
| Game of Pig |
---------------
Enter the point total to play for: 20
You rolled a 6
Enter r to roll or h to hold (
h): r
You rolled a 3
Enter r to roll or h to hold (
h): r
You rolled a 4
Enter r to roll or h to hold (
h): r
You rolled a 3
Enter r to roll or h to hold (
h): r
You rolled a 5
Your turn point total is 21

You WIN

---------------
| Game of Pig |
---------------
Enter the point total to play for: 20
You rolled a 6
Enter r to roll or h to hold (
h): r
CPSC1012 Assignment 3 Part 1 - Fall 2022 Term
You rolled a 6
Enter r to roll or h to hold (
h): r
You rolled a 6
Enter r to roll or h to hold (
h): r
You rolled a 1

Computer total points: 0

It’s the computer’s turn.
Computer rolled a 6
Computer rolled a 5
Computer HOLD
Computer turn score is 11

Computer total points: 11

You rolled a 6
Enter r to roll or h to hold (
h): r
You rolled a 6
Enter r to roll or h to hold (
h): h
You HOLD

Computer total points: 11

It’s the computer’s turn.
Computer rolled a 6
Computer rolled a 2
Computer rolled a 1
Computer turn total is 0

Computer total points: 11

You rolled a 2
Enter r to roll or h to hold (
h): r
You rolled a 4
Enter r to roll or h to hold (
h): r
You rolled a 3
You WIN

Computer total points: 11
Create a program menu to allow the user to select which game to run or exit the program. Menu choice input
validation is required. Here is a sample run:
|------------------|
| CPSC1012 Casino |
|------------------|
| 1. Play Craps |
| 2. Play Pig |
| 0. Exit Program |
CPSC1012 Assignment 3 Part 1 - Fall 2022 Term
|------------------|
x is not a valid menu choice. Try again.
-----------------
| Game of Craps |
-----------------

|------------------|
| CPSC1012 Casino |
|------------------|
| 1. Play Craps |
| 2. Play Pig |
| 0. Exit Program |
|------------------|
---------------
| Game of Pig |
---------------

|------------------|
| CPSC1012 Casino |
|------------------|
| 1. Play Craps |
| 2. Play Pig |
| 0. Exit Program |
|------------------|
Good-bye and thanks for coming to the CPSC1012 Casino.

Design your program to use methods where each method cannot have more than 50 statements. Your
program must handle invalid input values and not crash.

CODING STANDARDS
The following coding standards must be followed when developing your program:
• Your C# Console App project must be named as Assignment3Part1-YourFullName where
YourFullName is your first and last name.
• A C# comment block at the beginning of the source file with titles for the purpose, inputs,
outputs, algorithm, test plan, written by, written for, section no, and last modified of the
program such as shown below:
*
Purpose: ____________________________________________________

Inputs: XXXXXXXXXX____________________________________________________

Outputs: ____________________________________________________

Algorithm: ____________________________________________________
____________________________________________________
____________________________________________________

Test Plan:
Test Case Test Data Expected Results
CPSC1012 Assignment 3 Part 1 - Fall 2022 Term
--------- --------- ----------------

Written for: Instructor Name

Section No: ____________________________________________________

*/
• Write only one statement per line.
• Write only one declaration per line.
• Use camelCase (firstName) for local variable names and method parameter names.
• Use PascalCase/TitleCase (FirstName) for constant variable names and method names.
• If continuation lines are not indented automatically, indent them one tab stop (four spaces).
• Do NOT use the goto or continue statement
• Do NOT use
eak statement to exit a looping structure (a switch statement is not a looping
structure)
• Braces layout must be at next line.
• If statement must include
aces.
• Multi-way if-else statement must include an else block.
• Switch statement must include a default case.
• All looping statements must include
aces.
• Value-returning methods are not allowed to use more than ONE return statement.
• Do not use data structures in your code that has not been presented in
Answered 1 days After Nov 11, 2022

## Solution

Vikas answered on Nov 12 2022
SOLUTION.PDF