
C++
Functions in files, random numbers , stringstream and precision
|
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 |

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps

- Computer Science I need to write a program in C that allows the user to play a game of Mystery Word, here are the requirements: The program begins with a 6-letter word which is obscured by displaying an asterisk * in the place of each letter of the word. Four 6-letter words should be included in your program and have a theme. The word should be randomly selected when the user begins the game. After 7 incorrect guesses the user loses the game. The player wins by correctly guessing all of the letters that are part of the word. At each step, the program should remind the player of the letters he or she has already guessed, the program should not be case sensitive for input, but keep the output as uppercase letters. If the user enters the same letter twice that should count against them. Any help would be greatly appreciated as I'm stumped on how to complete this one.arrow_forwardSee attached images C++arrow_forwardC++arrow_forward
- C++ program Write a program that will predict the size of a population of organisms. The program should ask the user for the starting number of organisms, their average daily population increase (as a percentage of current population), and the number of days they will multiply. A loop should display the size of the population for each day.arrow_forwardC++ questionarrow_forwardInstructions C++ 8-17 A company hired 10 temporary workers who are paid hourly and you are given a data file that contains the last name of the employees, the number of hours each employee worked in a week, and the hourly pay rate of each employee. You are asked to write a program that computes each employee’s weekly pay and the average salary of all employees. The program then outputs the weekly pay of each employee, the average weekly pay, and the names of all the employees whose pay is greater than or equal to the average pay. If the number of hours worked in a week is more than 40, then the pay rate for the hours over 40 is 1.5 times the regular hourly rate. Use two parallel arrays: a one-dimensional array to store the names of all the employees (Name) a two-dimensional array of 10 rows and 3 columns to store the number of hours an employee worked in a week (Hrs Worked), the hourly pay rate (Pay Rate), and the weekly pay (Salary). Your program must contain at least the following…arrow_forward
- 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





