C++ Programming I Program 4: C++ Craps Game       Functions in files, random numbers , stringstream and precision     Craps is a popular dice game played in casinos.  The C++ variation is as follows:  Make a bet.  Roll two dice.  Each die has six faces, representing values 1-6.  Check the sum of the faces showing on the two dice.: If the sum is 2, 3 or 12 (craps), you lose. If the sum is 7 or 11 (natural), you win.  If the sum is anything else, a point is established (the sum of the dice you rolled) and you continue to roll until you re-roll the point (you win) or you roll a 7 (you lose).             This program will contain 6 functions to be called from main and from another function.  The functions will be contained in two files:  Functions.h, which contains the function prototypes, and Functions.cpp, which will contain the function implementations (or bodies).  Do not forget to put include guards in the Functions.h file.    Begin the program by declaring variables and then calling the function  WriteHeader.  This function will display your name, the program title and objective.  Then call ShowRules, which explains the rules.  See the random number generator function.  This is only done once.  Call AskForName to get the player’s name.  This functions returns a string with the player’s name.   Open a do while or while loop.  This is the “play loop,” which allows the user to play craps as many times as he/she wants.  Call the function AskForBet to retuun the amount of the user’s bet.  The bet minimum is $5.00 and can only be increased in increments of $5.00.  The amount of the bet is a double or a float.  Assume that the player begins with a balance of $200.00 in his/her pocket.   Call ThrowDice, which displays the sum of the values of the faces of the two dice rolled.  ThrowDice returns the sum to main.  Check the sum to see if the user won, lost, or has to continue.  If the player continues, call PlayPointRound, passing the function the point (or the sum of the two dice thrown).  PlayPointRound opens a do while loop and calls ThrowDice until the sum is the point or 7.  If the point was thrown, it returns true, for a win.  If 7 was thrown, it returns false.    Keep track of the player’s money balance as he/she plays craps by calling UpdateBalance.  Also keep track of the number of  wins and losses. Ask the user if s/he wants to play again.  Be sure to give the user the choices as an answer.  When the user is finished, display a summary of the user’s games, starting with the user’s name, the number of games won, the number of games lost, and the final money balance. Use precision and $ to show money correctly.   Then say thank you and goodbye.   Function prototypes: Return type Function Name Function Parameters Description void WriteHeader ( ) Write your class header void ShowRules ( ) Display rules of our Craps Game string AskForName ( ) Ask for player’s name double AskYourBet ( ) Ask for player’s bet int ThrowDice ( ) Show sum of the two dice thrown bool PlayPointRound (int dice) Throw until the point is made or 7 double UpdateBalance (bool didWin, double bet) Keep track of the player’s balance

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C++ Programming I Program 4: C++ Craps Game      

Functions in files, random numbers , stringstream and precision

 
 

Craps is a popular dice game played in casinos.  The C++ variation is as follows:  Make a bet.  Roll two dice.  Each die has six faces, representing values 1-6.  Check the sum of the faces showing on the two dice.:

If the sum is 2, 3 or 12 (craps), you lose.

If the sum is 7 or 11 (natural), you win. 

If the sum is anything else, a point is established (the sum of the dice you rolled) and you continue to roll until you re-roll the point (you win) or you roll a 7 (you lose).

 

 

 

 

 

 

This program will contain 6 functions to be called from main and from another function.  The functions will be contained in two files:  Functions.h, which contains the function prototypes, and Functions.cpp, which will contain the function implementations (or bodies).  Do not forget to put include guards in the Functions.h file. 

 

Begin the program by declaring variables and then calling the function  WriteHeader.  This function will display your name, the program title and objective.  Then call ShowRules, which explains the rules. 

See the random number generator function.  This is only done once.  Call AskForName to get the player’s name.  This functions returns a string with the player’s name.

 

Open a do while or while loop.  This is the “play loop,” which allows the user to play craps as many times as he/she wants.  Call the function AskForBet to retuun the amount of the user’s bet.  The bet minimum is $5.00 and can only be increased in increments of $5.00.  The amount of the bet is a double or a float.  Assume that the player begins with a balance of $200.00 in his/her pocket.

 

Call ThrowDice, which displays the sum of the values of the faces of the two dice rolled.  ThrowDice returns the sum to main.  Check the sum to see if the user won, lost, or has to continue.  If the player continues, call PlayPointRound, passing the function the point (or the sum of the two dice thrown).  PlayPointRound opens a do while loop and calls ThrowDice until the sum is the point or 7.  If the point was thrown, it returns true, for a win.  If 7 was thrown, it returns false. 

 

Keep track of the player’s money balance as he/she plays craps by calling UpdateBalance.  Also keep track of the number of  wins and losses.

Ask the user if s/he wants to play again.  Be sure to give the user the choices as an answer.  When the user is finished, display a summary of the user’s games, starting with the user’s name, the number of games won, the number of games lost, and the final money balance. Use precision and $ to show money correctly.   Then say thank you and goodbye.

 

Function prototypes:

Return type

Function Name

Function Parameters

Description

void

WriteHeader

( )

Write your class header

void

ShowRules

( )

Display rules of our Craps Game

string

AskForName

( )

Ask for player’s name

double

AskYourBet

( )

Ask for player’s bet

int

ThrowDice

( )

Show sum of the two dice thrown

bool

PlayPointRound

(int dice)

Throw until the point is made or 7

double

UpdateBalance

(bool didWin, double bet)

Keep track of the player’s balance

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Concept of Parenthesis
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
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education