Questions
Write a C++ program to play the dice game "Craps". Craps is one of the most...

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()
    • Open rules.txt file and read the rules from the file.
    • Display the rules to the screen.
    • Close the file
    • NOTE: Using Notepad, create a rules.txt file within your project folder and copy and paste the rules inside the file.
  • int rollOneDice()
    • NOTE: This function simulates rolling one dice
    • Generate random integer number from 1 to 6
    • return the random number
  • int rollTwoDice()
    • NOTE: This function simulates rolling two dice
    • Calls rollOneDice() function twice to get two random values
    • Print to the console "Sum: 6 (Die1: 4 Die2: 2)" where 4 is the value of the first dice and 2 is the value of the second dice and 6 is the sum of both dice.
    • return the sum.

Write a program that implements craps according to the above rules. Additionally:

  • When the program first begins, show the user the rules of Craps.
  • Before each initial throw of the dice, prompt the user to ask him/her to keep playing or quit. Gameplay ends when the user chooses to quit or runs out of money.
  • Your program should allow for wagering before each roll. This means that you need to prompt the user for an initial bank balance from which wagers will be added or subtracted.
    • Validate the initial bank balance entered by the user greater than zero. If the initial bank balance is not greater than zero, then inform the user and re-prompt.
  • Before each roll prompt the user for a wager. This includes rolls when the user is trying to make their point. Wagers must be less than or equal to the available bank balance.
    • The available bank balance is based on the accumulation of the previous wagers this game.
  • Once a game is lost or won, the bank balance should be adjusted.
  • Additional wagering details include:
    • Require the user to enter a non-zero wager for the first roll. Allow the user to enter a wager of 0 for subsequent “point” rolls.
    • Validate that the user’s wager is within the limits of the player's available balance. If the wager exceeds the player's available balance, then inform the user and re-prompt.

In: Computer Science

Would you make separated this code by one .h file and two .c file? **********code************* #include...

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...

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 the Super-Mega lottery there are 50 numbers (1 to 50), a player chooses ten different...

In the Super-Mega lottery there are 50 numbers (1 to 50), a player chooses ten different numbers and hopes that these get drawn. If the player's numbers get drawn, he/she wins an obscene amount of money. The table below displays the frequency with which classes of numbers are chosen (not drawn). These numbers came from a sample of 202 chosen numbers.
Chosen Numbers (?=202)
n
=
202
)
1 to 10 11 to 20 21 to 30 31 to 40 41 to 50
Count 24 50 54 47 27
Test the claim that chosen numbers are not evenly distributed across the five classes. Test this claim at the 0.01 significance level.

(a) Find the test statistic.

In: Statistics and Probability

Why does blood pressure increase in atherosclerosis? This is related to Resistance, afterload, the impact on...

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...

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

Suppose you take out a loan for school this year for $9000. The bank expects that...

  1. Suppose you take out a loan for school this year for $9000. The bank expects that the rate

      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.

    1. How much will you pay back in one year, assuming simple interest?
  1. What is the anticipated rate of inflation?
  2. What is the unanticipated rate of inflation?
  3. What is the real rate of interest?
  4. What is the nominal rate of interest?
  5. Who wins and who loses from this loan?

In: Economics

1. Should We Get Rid of the Electoral College? 2. Why did the founders create the...

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...

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...

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