Write a C++ program to play the dice game "Craps". Craps is one of the most popular games of chance and is played in casinos and back alleys throughout the world. The rules of the game are straightforward:
A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5, and 6 spots. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on the first throw, the player wins. If the sum is 2, 3, or 12 on the first throw (called "craps"), the player loses (i.e. the "house" wins). If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then the sum becomes the player's "point." To win, you must continue rolling the dice until you "make your point." The player loses by rolling a 7 before making the point.
At a minimum, your solution must contain the functions below.
void displayGameRules()
int rollOneDice()
int rollTwoDice()
Write a program that implements craps according to the above rules. Additionally:
In: Computer Science
Would you make separated this code by one .h file and two .c file?
**********code*************
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include<time.h>
// Prints out the rules of the game of "craps".
void print_game_rule(void)
{
printf("Rules of the game of CRAPS\n");
printf("--------------------------\n");
printf("A player rolls two dice.Each die has six faces.\n");
printf("These faces contain 1, 2, 3, 4, 5, and 6 spots.\n");
printf("After the dice have come to rest, the sum of the spots\n on
the two upward faces is calculated.\n");
printf("If the sum is 7 or 11 on the first throw, the player
wins.\n");
printf("If the sum is 2, 3, or 12 on the first throw (called
craps), \nthe player loses(i.e.the house wins).\n");
printf("If the sum is 4, 5, 6, 8, 9, or 10 on the first throw,
\nthen the sum becomes the player's point.\n");
printf("To win, you must continue rolling the dice until you make
your point.\n");
printf("The player Loses by Rolling a 7 before making the
Point.\n\n");
}
//function definition of get_bank_balance()
double get_bank_balance(void)
{
//Prompt the player for an initial bank balance
printf("Enter initial bank balance: ");
double balance;
scanf("%lf", &balance);
return balance;
}
//function definition of get_wager_amount method
double get_wager_amount(void)
{
double wager;
//Prompt the player for a wager on a particular roll.
printf("Enter the wager: ");
scanf("%lf", &wager);
return wager;
}
//function definition of check_wager_amount method
int check_wager_amount(double wager, double balance)
{
// to check if the wager is within the limits of player's available
balance
if (wager > balance)
return 0;
else
return 1;
}
//function definition of roll_die method
int roll_die(void)
{
int random;
// to generate random number between 1 and 6
srand(time(0));
random = rand() % 6 + 1;
return random;
}
//function definition of calculate_sum_dice method
int calculate_sum_dice(int die1_value, int die2_value)
{
return die1_value + die2_value;
}
//function definition of is_win_loss_or method
int is_win_loss_or_point(int sum_dice)
{
// to check if the sum is 7 or 11 on the roll
if (sum_dice == 7 || sum_dice == 11)
return 1;
// to check if the sum is 2, 3, or 12
else if (sum_dice == 2 || sum_dice == 3 || sum_dice == 12)
return 0;
//if the sum is 4, 5, 6, 8, 9, or 10
else
return -1;
}
//function definition of is_point_loss_neither method
int is_point_loss_neither(int sum_dice, int point_value)
{
//to check if the sum of the roll is the point_value
if (sum_dice == point_value)
return 1;
//to check if the sum of the roll is a 7,
else if (sum_dice == 7)
return 0;
else
return -1;
}
//function definition of adjust_bank_balance method
double adjust_bank_balance(double bank_balance, double
wager_amount, int add_or_subtract)
{
// to check if add_or_subtract is 1
if (add_or_subtract == 1)
bank_balance += wager_amount;
// to check if add_or_subtract is 0,
else if (add_or_subtract == 0)
bank_balance -= wager_amount;
return bank_balance;
}
//function definition of chatter_message method
void chatter_message(int number_rolls, int win_loss_neither, double
initial_bank_balance,
double current_bank_balance)
{
printf("Number of Rolls: %d\n", number_rolls);
printf("Current Balance: %lf\n", current_bank_balance);
if (initial_bank_balance - current_bank_balance > 0)
printf("Amount lost: %lf\n", initial_bank_balance -
current_bank_balance);
else
printf(" Amount %lf\n", current_bank_balance -
initial_bank_balance);
if (win_loss_neither == 1)
printf("Congratulations!!! You WON\n");
else if (win_loss_neither == 0)
printf("Sorry!!! You LOSS\n");
else if (win_loss_neither == -1)
printf("Sorry!!! It is neither win or loss\n");
}
//main function
int main(void)
{
// variable declaration
double balance, initial_balance;
bool play = true;
int point, rollCount = 1;;
//call function print_game_rule to print the rules of the
game
print_game_rule();
//call function get_bank_balance()
balance = get_bank_balance();
initial_balance = balance;
while (play && balance > 0)
{
double wager = get_wager_amount();
// to check if wager is less than balance
if (!check_wager_amount(wager, balance))
{
printf("Insufficient balance.\n");
continue;
}
// set the dice values by calling function roll_die()
int dice1 = roll_die();
int dice2 = roll_die();
//calculate sum of dices by calling function
calculate_sum_dice()
int sum = calculate_sum_dice(dice1, dice2);
printf("Sum of dices: %d\n", sum);
if (rollCount == 1)
{
int check = is_win_loss_or_point(sum);
if (check == 1)
{
printf("Congratulations!!!You WON\n");
// call function adjust_bank_balance() to calculate new
balance
balance = adjust_bank_balance(balance, wager, 1);
// call function chatter_message() to display appropriate
messages
chatter_message(rollCount, check, initial_balance, balance);
break;
}
else if (check == 0)
{
printf("Sorry!!! House wins.\n");
balance = adjust_bank_balance(balance, wager, 0);
chatter_message(rollCount, check, initial_balance, balance);
break;
}
else
{
point = sum;
}
chatter_message(rollCount, check, initial_balance, balance);
}
else
{
int check = is_point_loss_neither(sum, point);
if (check == 1)
{
printf("Congratulations!!! You WON\n");
balance = adjust_bank_balance(balance, wager, 1);
chatter_message(rollCount, check, initial_balance, balance);
break;
}
else if (check == 0)
{
printf("Sorry!!! House wins.\n");
balance = adjust_bank_balance(balance, wager, 1);
chatter_message(rollCount, check, initial_balance, balance);
break;
}
else
{
point = sum;
}
chatter_message(rollCount, check, initial_balance, balance);
}
}
return 0;
}
In: Computer Science
Q1(a) Mr. Sweetheart likes sugar in his hot tea. He buys sugar packets from a local grocery store. Suppose the amount of sugar in a packet follows a normal distribution with mean 2.17 grams and standard deviation 0.08 grams. The amount of sugar in a package should be between 2.13 and 2.21 grams. Otherwise, a packet is considered to be defective.
i. What is the probability that a randomly selected packet is defective?
ii. Three sugar packets are chosen randomly. What is the probability that two of them are not defective?
iii. Mr Sweetheart needs between 8.2 and 9 grams of sugar in a cup of tea for the drink to taste right. One morning, he adds four randomly selected sugar packets. What is the probability that Mr Sweetheart’s tea tastes right?
Q1(b) President Fisher posts 2 messages on a social media platform daily on average.
i. What is the probability that he posts no message in three consecutive days?
ii. What is the probability that he posts more than one message in one hour?
Q2
A restaurant chain owner would like to know the sales of a certain signature dish in his restaurants. A random sample of 120 restaurants is selected and the sales of the dish in 2018 are summarized as follows.
| Sales (in thousand ($)) | Frequency |
| 26 – 30 | 6 |
| 31 – 35 | 12 |
| 36 – 40 | 15 |
| 41 – 45 | 36 |
| 46 – 50 | 21 |
| 51 – 55 | 20 |
| 56 – 60 | 10 |
Q2(a) Calculate the mean, median and standard deviation of the sales. $)) Frequency 26 – 30 6 31 – 35 12 36 – 40 15 41 – 45 36 46 – 50 21 51 – 55 20 56 – 60 10
Q2(b) Calculate the coefficient of skewness using results in (a) and interpret your result briefly.
Q2(c) Estimate, from the frequency distribution table, the number of restaurants who sales were between $38,500 and $54,500 in 2018.
Q2(d) Estimate, from the frequency distribution table, the sales amount that exceeded by 30% of the restaurants in 2018.
Q3(a) To estimate the mean amount of time children spend in physical activities daily, a researcher randomly selects 8 children and records the number of hours they spend in physical activities in one day. The numbers of hours are: 4.1, 1.2, 4.6, 2.4, 3.2, 1.8, 2.4, and 0.7. Obtain a 95% confidence interval of the mean number of hours that children spend in physical activities.
Q3(b) It is found that the average lifespan of 100 smart phones is 23.5 months with a standard deviation of 10.2 months. Construct the 99% confidence interval for the mean lifespan of all smart phones. State the assumption(s) made.
Q3(c) A machine produces DVD discs. The diameters of these DVD discs vary, and the standard deviation is 0.01 centimeter. How large a sample should be taken if we wish to have 95% confidence that our sample mean will not differ from the true mean by more than 0.001 centimeter?
Q4 (a) On a sunny day, a theme park had 1,000 visitors. According to the attendance record, 800 visitors took a ride on the roller coaster; 450 visitors took a ride on the merry-go-round. It is estimated that among those visitors who took a ride on the roller coaster, 40% of them also took a ride on the merry-go-round. A visitor on that day is selected at random.
i. What is the probability that this visitor rode on both rides?
ii. What is the probability that this visitor rode on no rides at all?
iii. If this visitor has taken a ride on the merry-go-round, what is the probability that he has not ridden on the roller coaster?
Q4(b) In a tutorial session of AMA1501, there are 11 accounting students, 6 marketing students and 8 financial service students. Among these 25 students, a group of 5 students is selected randomly for the first presentation.
i. How many different groups can be formed?
ii. What is the probability that this group consists of only accounting students?
iii. What is the probability that this group consists of exactly 2 accounting students and 3 marketing students?
Q4(c) Three urns contain colored balls. Urn 1 contains 3 red, 4 white and 1 blue balls. Urn 2 contains 4 red, 3 white and 2 blue balls. Urn 3 contains 1 red, 2 white and 3 blue balls. One urn is chosen at random and a ball is drawn from it. If the ball is red, what is the probability that it came from Urn 3?
In: Statistics and Probability
In: Statistics and Probability
Why does blood pressure increase in atherosclerosis? This is related to Resistance, afterload, the impact on SV leading to the change in BP. This also includes the short term and long term regulation of BP. Tell me how this developed form there being a plaque in the coronary vessels. It deals with the backing up of pressure from the blocked arteries.
You want to discuss the baroreceptors, the ones in the aorta and the ones in the carotid bodies, they are receiving two different BP measurements when this all starts. The one in the aorta is dealing with a build up of resistance and pressure, the other is the loss of flow and pressure. The brain wins and the long term regulation of BP is activated because of this.
Please no cursive answers, Thank You!
In: Nursing
The English Premier League has 20 teams, throughout the season,
each team plays each of the other teams once at home and once away.
(e.g. Everton plays Liverpool at Anfield, which is Liverpool’s home
field, and Everton plays Liverpool at Goodison Park, which is
Everton’s home field.) Teams are awarded 3 points for a win, 1
point for a draw, and 0 points for a loss
(a) How many combinations of wins, losses, and draws are possible for a team throughout the season, regardless of the order?
(b) How many ways can a team win 6 out of 10 games? Here, order matters, and you are only considering those 10 games.
In: Statistics and Probability
of inflation for next year will equal 2%. You and the bank agree that in one year’s time, you
will pay back the full amount at an interest rate of 5%. Next year though, there is a sudden
rise in inflation, causing inflation to equal 12%.
Based upon this information, answer the following questions.
In: Economics
1. Should We Get Rid of the Electoral College?
2. Why did the founders create the Electoral College system? Is it still a fair way of choosing a president?
3. So let’s say we amend the Constitution and finally get rid of the Electoral College, and go with “whoever gets the most votes wins.” How would this change presidential elections? What would happen if NO candidate received over 50% of the vote?
4. How would eliminating the Electoral College affect the small (or low population) states? How would it affect the large (or large population) states?
(please answer all questions in a 5 sentence paragraph)
In: Economics
Apple LLC decides that it is going to bid on some government work. All contractors must post a bid bond when bidding on government work. Apple bids on the government work and wins. Apple posts a payment bond, as per the contract, and starts to work. After about 2 years into the job, Apple walks off the job, which was left uncompleted. Can the government collect the bond?
1. Yes, the government can collect on the bid bond that Apple took out
2. No, there is no bond available here that the government could collect on
3. No, the surety must be given the chance to mitigate their losses first
4. Yes, Apple guaranteed its work.
In: Civil Engineering
4. Diversification can eliminate risk if two events are perfectly negatively correlated. Suppose that two firms are competing for a government contract and have an equal chance of winning. Because only one firm can win, the other must lose, so the two events are perfectly negatively correlated. You can buy a share of stock in either firm for $20. The stock of the firm that wins the contract will worth $40, while the stock of the loser will worth $10. • If you buy two shares of one firm, calculate the expected value and variance of two shares. • If you buy one share on each firm, calculate the expected value and variance of two shares.
In: Finance