programming language: C++
*Include Line Documenatations*
Overview
For this assignment, write a program that will
simulate a game of Roulette.
Roulette is a casino game of chance where a player may
choose to place bets on either a single number, the colors red or
black, or whether a number is even or odd. (Note: bets may also be
placed on a range of numbers, but we will not cover that situation
in this program.) A winning number and color is determined by a
croupier/dealer spinning a wheel in one direction and a ball in the
opposite direction. The wheel contains 38 colored and numbered
pockets. The pocket that the ball falls into is the winning number
and color.
The pockets of the roulette wheel are numbered with 00
and 0 through 36. The 0 and 00 pockets are green. In the ranges 1
through 10 and 19 through 28, the odd numbers are red and the even
numbers are black. In the ranges 11 through 18 and 29 through 36,
the odd numbers are black and the even numbers are red.
For this assignment, 0 and 00 will be treated the
same.
Basic Program Logic
The program will use the random number generator to
simulate the spinning of the wheel. Therefore, the random number
generator must be seeded. This is done one time in the program. Use
srand(6) for the final version of the program that will be
graded.
Call the betOptionsMenu function that is described
below to display a menu of possible options to the player and get
their bet option.
In a loop that will execute as long as the player does
not want to quit the game of roulette:
Call the spinWheel function that is described below to
get the pocket where the ball lands when the croupier/dealer spins
the wheel.
If the player chose to bet on a single number, call
the getSingleNum function that is described below to get the number
that the player wants to bet on. Call the displayWheelResult
function that is described below to display the number of the
pocket where the ball landed. If the player's number matches the
number of the pocket where the ball landed, display a
congratulatory message to the player. If the player's number does
not match the number of the pocket where the ball landed, display a
message that the player lost.
If the player chose to bet on the colors red or black,
call the getPocketColor function that is described below to
determine the color of the pocket where the ball landed when the
wheel was spun. Call the displayWheelResult function to display the
color that the wheel landed on (green, red, or black) along with
the number for the pocket. If the player's color matches the color
of the pocket on the wheel, display a congratulatory message to the
player. If the player's color does not match the color of the
pocket where the ball landed, display a message that the player
lost. Note: landing on either of the green pockets is a
loss.
If the player chose to bet even or odd, call the
getPocketEvenOdd function that is described below to determine the
category of pocket where the ball landed when the wheel was spun.
Call the displayWheelResult function to display the category (even,
odd, or zero) and the number of the pocket where the ball landed.
If the player's choice matches the category of the pocket on the
wheel, display a congratulatory message to the player. If the
player's choice does not match the category of the pocket where the
ball landed, display a message that the player lost. Note: landing
on either of the 0s is a loss.
Call the betOptionsMenu function to get the user's
next bet option.
The Functions
Write and use the following 6 functions in the
program.
int spinWheel()
This function will generate a random number between 0
and 36 to simulate the spinning of the roulette wheel. It takes no
argument. It returns an integer: the random number between 0 and
36.
DO NOT call the srand
function in this function. This is being done in
main().
char betOptionsMenu()
This function will display a menu of the possible
betting options and get a VALID choice from the player. It takes no
arguments. It returns a character: the player's betting
choice.
The function should display the menu of possible
options (S for a single number bet, R for a bet on red, B for a bet
on Black, E for a bet on even, O for a bet on odd, or Q to quit the
game) and then get the player's betting choice. The player's
betting choice should be validated and the player should be made to
re-enter a value until they have made a valid selection.
The lowercase representation of each menu option
should be considered a valid option.
Once the player has entered a valid option, it should
be returned to the calling function.
int getSingleNum()
This function will get a number between 0 and 36 from
the player. It takes no arguments. It returns an integer: the
player's number.
The function should prompt the user to enter a number
between 0 and 36. The player's number should be validated and the
player should be made to re-enter a value until they have made a
valid selection.
Once the player has selected a valid number, it should
be returned to the calling function.
char getPocketColor( int pocketNum )
This function will determine the color of the pocket
where the ball landed after the wheel was spun. It takes an integer
argument: the number of the pocket where the ball landed. It
returns a character: an uppercase letter that represents the color
of the pocket where the ball landed.
The function should test the value of the pocketNum
argument and return 'G' for green, 'R' for red, or 'B' for black.
As described above, the pockets of the roulette wheel are numbered
with 00 and 0 through 36. The 0 and 00 pockets are GREEN. In the
ranges 1 through 10 and 19 through 28, the odd numbers are RED and
the even numbers are BLACK. In the ranges 11 through 18 and 29
through 36, the odd numbers are BLACK and the even numbers are
RED.
char getPocketEvenOdd( int pocketNum
)
This function will determine the category (even, odd,
or zero) of the pocket where the ball landed after the wheel was
spun. It takes an integer argument: the number of the pocket where
the ball landed. It returns a character: an uppercase letter that
represents the category of the pocket where the ball
landed.
The function should test the value of the pocketNum
argument and return 'E' for an even number, 'O' for an odd number,
or 'Z' for zero.
void displayWheelResult( char type, int pocketNum
)
This function will display the result of
croupier/dealer spinning the wheel. It takes two arguments: a
character that represents the type of bet and an integer that
represents the number of the pocket where the ball landed. It
returns nothing.
The function should test the value of the type
argument and display one of three things. If the type argument
represents a single number bet ('S'), display the number of the
pocket where the ball landed. If the type argument represents that
the bet was on a color ('R' 'B' or 'G'), display the color of the
pocket and the number of the pocket where the ball landed. If the
type argument represents that the bet was on a category ('E' 'O' or
'Z'), display the category of the pocket and the number of the
pocket where the ball landed.
Processing Requirements
As with the previous assignments and the assignments
until the end of the semester, complete program documentation is
required. For this assignment, that means that line documentation
AND function documentation boxes are needed. In regards to line
documentation, there is no need to document every single line, but
logical "chunks" of code should be preceded by a line or two that
describe what the "chunk" of code does. Make sure that main() and
any function that you write contains line documentation
Each function must have a documentation box detailing:
its name
its use or function: that is, what does it do? What
service does it provide to the code that calls it?
a list of its arguments briefly describing the meaning
and use of each
the value returned (if any) or none
notes on any unusual features, assumptions,
techniques, etc.
/***************************************************************
Function: void displayWheelResult( char type, int pocketNum ) Use:
This function displays the result of spinning the roulette wheel
Arguments: type - a character that represents the type of bet made
by the player pocketNum - an integer that represents the number of
the pocket where the ball landed when the wheel was spun Returns:
Nothing Note: None
***************************************************************/
See the documentation standards on the course webpage for more
examples or if further clarification is needed. Your program will
not get full credit (even if it works correctly) if these standards
are not followed
Make sure to use meaningful variable names.
Be sure to #include <cstdlib>
Make sure that the copy of the program that is handed
in uses srand(6); to set the seed value for the random number
generator.
Hand in a copy of the source code (CPP file) using
Blackboard.
Output
Run using srand(6); on Windows PC
What type of bet would you like? (S = single number, R = red, B =
black, E = even, O = odd, Q = quit the game): S What number would
you like to bet on (0-36)? 3 The wheel is spinning...and landed on
21 You LOST! What type of bet would you like? (S = single number, R
= red, B = black, E = even, O = odd, Q = quit the game): R The
wheel is spinning...and landed on BLACK (13) You LOST! What type of
bet would you like? (S = single number, R = red, B = black, E =
even, O = odd, Q = quit the game): b The wheel is spinning...and
landed on RED (1) You LOST! What type of bet would you like? (S =
single number, R = red, B = black, E = even, O = odd, Q = quit the
game): b The wheel is spinning...and landed on BLACK (20) You WON!
What type of bet would you like? (S = single number, R = red, B =
black, E = even, O = odd, Q = quit the game): E The wheel is
spinning...and landed on EVEN (26) You WON! What type of bet would
you like? (S = single number, R = red, B = black, E = even, O =
odd, Q = quit the game): o The wheel is spinning...and landed on
EVEN (36) You LOST! What type of bet would you like? (S = single
number, R = red, B = black, E = even, O = odd, Q = quit the game):
o The wheel is spinning...and landed on EVEN (30) You LOST! What
type of bet would you like? (S = single number, R = red, B = black,
E = even, O = odd, Q = quit the game): o The wheel is
spinning...and landed on ODD (33) You WON! What type of bet would
you like? (S = single number, R = red, B = black, E = even, O =
odd, Q = quit the game): t Invalid Option. Try again: H Invalid
Option. Try again: G Invalid Option. Try again: S What number would
you like to bet on (0-36)? -9 Invalid Number. Try again: 57 Invalid
Number. Try again: 42 Invalid Number. Try again: -42 Invalid
Number. Try again: 18 The wheel is spinning...and landed on 5 You
LOST! What type of bet would you like? (S = single number, R = red,
B = black, E = even, O = odd, Q = quit the game): q
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
char betOptionsMenu();
int getSingleNum();
int spinWheel();
char getPocketColor(int pocketNum);
char getPocketEvenOdd(int pocketNum);
void displayWheelResult(char type, int pocketNum);
int main() {
srand(6);
// Declaring variables
int unum, snum;
char color;
while (true) {
char choice = betOptionsMenu();
if (choice == 'S' || choice == 's') {
unum = getSingleNum();
snum = spinWheel();
cout << "and landed on " << snum;
if (unum == snum) {
cout << " You Won!" << endl;
} else {
cout << " You LOST!" << endl;
}
} else if (choice == 'R' || choice == 'r' || choice == 'B' ||
choice == 'b') {
snum = spinWheel();
color = getPocketColor(snum);
displayWheelResult(color,snum);
if ((choice == 'R' || choice == 'r') && color == 'r')
{
cout << " You WON! " << endl;
} else if ((choice == 'B' || choice == 'b') && color ==
'b') {
cout << " You WON! " << endl;
} else {
cout << " You LOST! " << endl;
}
} else if (choice == 'E' || choice == 'e') {
snum = spinWheel();
char evenOrOdd = getPocketEvenOdd(snum);
displayWheelResult(evenOrOdd, snum);
if ((choice == 'E' || choice == 'e') && evenOrOdd == 'e')
{
cout << "You Won!" << endl;
} else {
cout << "You Lost!" << endl;
}
} else if (choice == 'O' || choice == 'o') {
snum = spinWheel();
char evenOrOdd = getPocketEvenOdd(snum);
displayWheelResult(evenOrOdd, snum);
if ((choice == 'O' || choice == 'o') && evenOrOdd == 'o')
{
cout << "You Won!" << endl;
} else {
cout << "You Lost!" << endl;
}
} else if (choice == 'Q' || choice == 'q') {
break;
}
}
return 0;
}
char betOptionsMenu() {
char choice;
cout << "What type of bet would you like? " <<
endl;
cout << "(S = single number, R = red, B = black, E = even, O
= odd, Q = quit the game): ";
while (true) {
cin >> choice;
if (choice != 'S' && choice != 's' && choice != 'R'
&& choice != 'r' && choice != 'B' && choice
!= 'b' && choice != 'E' && choice != 'e' &&
choice != 'O' && choice != 'o' && choice != 'Q'
&& choice != 'q') {
cout << "Invalid Option. Try again:";
} else {
return choice;
}
}
}
int getSingleNum() {
int num;
cout << "What number would you like to bet on (0-36)?";
while (true) {
cin >> num;
if (num < 0 || num > 36) {
cout << " Invalid Number. Try again:";
} else {
return num;
}
}
}
int spinWheel() {
int randNum;
randNum = rand() % (37);
cout << "The wheel is spinning...";
return randNum;
}
char getPocketColor(int pocketNum) {
char ch;
if (pocketNum == 0) {
ch = 'g';
} else if ((pocketNum >= 1 && pocketNum <= 10) ||
(pocketNum >= 19 && pocketNum <= 28)) {
if (pocketNum % 2 == 0) {
ch = 'b';
} else if (pocketNum % 2 != 0) {
ch = 'r';
}
} else if ((pocketNum >= 11 && pocketNum <= 18) ||
(pocketNum >= 29 && pocketNum <= 36)) {
if (pocketNum % 2 == 0) {
ch = 'r';
} else if (pocketNum % 2 != 0) {
ch = 'b';
}
}
return ch;
}
char getPocketEvenOdd(int pocketNum) {
char ch;
if (pocketNum == 0)
ch = 'z';
else if (pocketNum % 2 == 0)
ch = 'e';
else if (pocketNum % 2 != 0)
ch = 'o';
return ch;
}
void displayWheelResult(char type, int pocketNum) {
if (type == 'r') {
cout << "and landed on RED(" << pocketNum <<
")";
} else if (type == 'b') {
cout << "and landed on BLACK(" << pocketNum <<
")";
} else if (type == 'g') {
cout << "and landed on GREEN(" << pocketNum <<
")";
} else if (type == 'e') {
cout << "and landed on EVEN " << endl;
} else if (type == 'o') {
cout << "and landed on ODD " << endl;
} else if (type == 'z') {
cout << "and landed on ZERO " << endl;
}
}
____________________________
Output:
_______________Could you plz rate me well.Thank You
programming language: C++ *Include Line Documenatations* Overview For this assignment, write a program that will simulate...
Question 12 5 pts Roulette is a game involving a wheel that contains numbers 1 through 36 along with O and 00. Eighteen numbers are red and eighteen numbers are black. The 0 and 00 are green. Players can place a bet on any of the numbers, specified ranges or the color of the number. A ball is then dropped onto the spinning wheel and the ball comes to rest on one of the 38 spots on the wheel. A...
QuestionI the casino gambling game of American Roulette the wheel has 38 pockets numbered 00,0,1..36. Half of the numbers from 1 and 36 are painted black, while the others are painted red. The numbers 00 and 0 are painted green. A ball is equally likely to land in any pocket. Listed below are several of the many possible bets on where the ball lands, together with their winning payouts based on a 81 stake. In each case calculate the expected...
1. In the game of roulette a metal ball is dropped into a spinning wheel having 38 compartments, 18 of which are red, 18 are black, and two are green. Suppose we spin the wheel ten consecutive times and let a random variable X be the number of times the metal ball will land on a red color. a. Construct the probability distribution of X. b. Suppose you always bet $5 on red. If red...
Roulette is one of the most common games played in gambling casinos in Las Vegas and elsewhere. An American roulette wheel has slots marked with the numbers from 1 to 36 as well as 0 and 00 (the latter is called "double zero"). Half of the slots marked 1 to 36 are colored red and the other half are black. (The 0 and 00 are colored green.) With each spin of the wheel, the ball lands in one of these...
Question 2.9 lt Wieelr With a bet of $5 on black and a bet of $2 on the specific group of four numbers pictured in Figure 2.1 (13, 14, 16, 17). What is the bettor's expectation on this combined bet? Conclude, as suggested in the text, that the bettor's expected loss is 5.26 cents for every dollar bet. 2.9 A European roulette wheel has 37 sectors including a zero but no double zero. Furthermore if the zero comes up, any...
A roulette wheel has 38 numbers, with 18 odd numbers (black) and 18 even numbers (red), as well as 0 and 00 (which are green). If you bet $19 that the outcome is an odd number, the probability of losing the $19 is 20/38 and the probability of winning is $38 (for a net gain of only $19, given you already paid $19) is 18/38. If a player bets $19 that the outcome is an odd number, what is the...
In the casino gambling game of American Roulette the wheel has 38 pockets numbered 00,0,1, . . . ,36. Half of the numbers from 1 and 36 are painted black, while the others are painted red. The numbers 00 and 0 are painted green. A ball is equally likely to land in any pocket. Listed below are several of the many possible bets on where the ball lands, together with their winning payouts based on a$1 stake. In each case...
Please Home Chapter 3 Use the following information to answer the next three exercises. The casino game, roulette, allows the gambler to bet on the probability of a ball, which spins in the roulette wheel, landing on a particular color, number, or range of numbers. The table used to place bets contains of 38 numbers, and each number is assigned to a color and a range. Ist Dozen 2nd Dozen 3rd Dozen 1 to 18 EVEN ODD 19 to 36...
Problem Statement: A company intends to offer various versions of roulette game and it wants you to develop a customized object-oriented software solution. This company plans to offer one version 100A now (similar to the simple version in project 2 so refer to it for basic requirements, but it allows multiple players and multiple games) and it is planning to add several more versions in the future. Each game has a minimum and maximum bet and it shall be able...