Question

In: Computer Science

Programing assignment in C++ The following description has been adopted from Deitel & Deitel. One of...

Programing assignment in C++

The following description has been adopted from Deitel & Deitel. One of the most popular games of chance is a dice game called "craps," which 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.

Write a program that implements a craps game according to the above rules. The game should allow for wagering. This means that you need to prompt that user for an initial bank balance from which wagers will be added or subtracted. Before each roll prompt the user for a wager. Once a game is lost or won, the bank balance should be adjusted. As the game progresses, print various messages to create some "chatter" such as, "Sorry, you busted!", or "Oh, you're going for broke, huh?", or "Aw cmon, take a chance!", or "You're up big, now's the time to cash in your chips!"

Use the below functions to help you get started! You may define more than the ones suggested if you wish!

(5 pts) void print_game_rules (void) — Prints out the rules of the game of "craps".

(5 pts) double get_bank_balance (void) - Prompts the player for an initial bank balance from which wagering will be added or subtracted. The player entered bank balance (in dollars, i.e. $100.00) is returned.

(5 pts) double get_wager_amount (void) - Prompts the player for a wager on a particular roll. The wager is returned.

(5 pts) int check_wager_amount (double wager, double balance) - Checks to see if the wager is within the limits of the player's available balance. If the wager exceeds the player's allowable balance, then 0 is returned; otherwise 1 is returned.

(5 pts) int roll_die (void) - Rolls one die. This function should randomly generate a value between 1 and 6, inclusively. Returns the value of the die.

(5 pts) int calculate_sum_dice (int die1_value, int die2_value) - Sums together the values of the two dice and returns the result. Note: this result may become the player's point in future rolls.

(10 pts) int is_win_loss_or_point (int sum_dice) - Determines the result of thefirstdice roll. If the sum is 7 or 11 on the roll, the player wins and 1 is returned. If the sum is 2, 3, or 12 on the first throw (called "craps"), the player loses (i.e. the "house" wins) and 0 is returned. If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then the sum becomes the player's "point" and -1 is returned.

(10 pts) int is_point_loss_or_neither (int sum_dice, int point_value) - Determines the result of any successive roll after the first roll. If the sum of the roll is the point_value, then 1 is returned. If the sum of the roll is a 7, then 0 is returned. Otherwise, -1 is returned.

(5 pts) double adjust_bank_balance (double bank_balance, double wager_amount, int add_or_subtract) - If add_or_subtract is 1, then the wager amount is added to the bank_balance. If add_or_subtract is 0, then the wager amount is subtracted from the bank_balance. Otherwise, the bank_balance remains the same. The bank_balance result is returned.

(5 pts) void chatter_messages (int number_rolls, int win_loss_neither, double initial_bank_balance, double current_bank_balance) - Prints an appropriate message dependent on the number of rolls taken so far by the player, the current balance, and whether or not the player just won his roll. The parameter win_loss_neither indicates the result of the previous roll.

(10 pts) Others?

(20 pts) A main ( ) function that makes use of the above functions in order to play the game of craps as explained above. Note that you will most likely have a loop in your main ( ) function (or you could have another function that loops through the game play).

Have a great time with this assignment! There is plenty of room for creativity! Note: I have not stated how you must display the game play! You may do as you wish!

1-Your project must contain one header file (a .h file), two C source files (which must be .c files), and project workspace.

Solutions

Expert Solution


// Program to sort array using quick sort

# include <iostream.h>
# include <conio.h>
const int MAX = 10 ;

class array
{
   private :

       int arr[MAX] ;
       int count ;

   public :

       array( ) ;
       void add ( int item ) ;
       int getcount( ) ;
       static int split ( int *, int, int ) ;
       void quiksort ( int lower, int upper ) ;
       void display( ) ;
} ;

// initialises data member
array :: array( )
{
   count = 0 ;
   for ( int i = 0 ; i < MAX ; i++ )
       arr[i] = 0 ;
}

// adds a new element to the array
void array :: add ( int item )
{
   if ( count < MAX )
   {
       arr[count] = item ;
       count++ ;
   }
   else
       cout << "\nArray is full" << endl ;
}

// returns total number of elements
int array :: getcount( )
{
   return count ;
}

// calls split to arrange array
void array :: quiksort ( int lower, int upper )
{
   if ( upper > lower )
   {
       int i = split ( arr, lower, upper ) ;
       quiksort ( lower, i - 1 ) ;
       quiksort ( i + 1, upper ) ;
   }
}

// sorts array using quick sort
int array :: split ( int *a, int lower, int upper )
{
   int i, p, q, t ;

   p = lower + 1 ;
   q = upper ;
   i = a[lower] ;

   while ( q >= p )
   {
       while ( a[p] < i )
           p++ ;

       while ( a[q] > i )
           q-- ;

       if ( q > p )
       {
           t = a[p] ;
           a[p] = a[q] ;
           a[q] = t ;
       }
   }

   t = a[lower] ;
   a[lower] = a[q] ;
   a[q] = t ;

   return q ;
}

// displays elements of array
void array :: display( )
{
   for ( int i = 0 ; i < count ; i++ )
       cout << arr[i] << " " ;
   cout << endl ;
}

void main( )
{
   array a ;
   clrscr();
   a.add ( 11 ) ;
   a.add ( 2 ) ;
   a.add ( 9 ) ;
   a.add ( 13 ) ;
   a.add ( 57 ) ;
   a.add ( 25 ) ;
   a.add ( 17 ) ;
   a.add ( 1 ) ;
   a.add ( 90 ) ;
   a.add ( 3 ) ;

   cout << "\nQuik sort.\n" ;
   cout << "\nArray before sorting:" << endl ;
   a.display( ) ;

   int c = a.getcount( ) ;

   a.quiksort ( 0, c - 1 ) ;
   cout << "\nArray after quick sorting:" << endl ;
   a.display( ) ;
   getch();
}


Related Solutions

**C programming language The following description has been adopted from Deitel & Deitel. One of the...
**C programming language The following description has been adopted from Deitel & Deitel. One of the most popular games of chance is a dice game called "craps," which 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...
c programing language This assignment, which introduces the use of loops, solves the following problem: given...
c programing language This assignment, which introduces the use of loops, solves the following problem: given a starting location in a city, how long does it take a “drunken sailor” who randomly chooses his direction at each intersection to reach the city’s border? You will read input values to set up the problem parameters, run several trials to determine an average number of steps for the sailor to reach the border, and output the results. This problem is an example...
In C++, pls comment code This assignment is adopted from Project Euler Question 13. Requirement -...
In C++, pls comment code This assignment is adopted from Project Euler Question 13. Requirement - use file for the input (nums.txt) - (recommended) use only one linked list to hold intermediate answer and final answer. You may use another one to reverse the answer. - store the num reversely in the linked list. For example, the num 123 is stored as 3 (at first node), 2 (at second node) and 1 (at third node) in the linked list. -...
Please code in C# (C-Sharp) Assignment Description A pirate needs to do some accounting and has...
Please code in C# (C-Sharp) Assignment Description A pirate needs to do some accounting and has asked for your help. Write a program that will accept a pirate’s starting amount of treasure in number of gold pieces. The program will then run one of two simulations, indicated by the user: 1) The first simulation runs indefinitely, until one of two conditions is met: the pirate’s treasure falls to 0 or below, or the pirate’s treasure grows to 1000 or above....
Please code in C# - (C - Sharp) Assignment Description Write out a program that will...
Please code in C# - (C - Sharp) Assignment Description Write out a program that will ask the user for their name; the length and width of a rectangle; and the length of a square. The program will then output the input name; the area and perimeter of a rectangle with the dimensions they input; and the area and perimeter of a square with the length they input. Tasks The program needs to contain the following A comment header containing...
C++ programing Write a main function that  reads a list of integers from a user, adds to...
C++ programing Write a main function that  reads a list of integers from a user, adds to an array using dynamic memory allocation, and then displays the array. The program also displays the the largest element in the integer array. Requirement: Using pointer notation.
One example of Global Marketing that has been unsuccessful. Provide a brief description of the example...
One example of Global Marketing that has been unsuccessful. Provide a brief description of the example that you selected. Be sure to include the company, market they were entering and why you considered it to be a failure. Why do you think the company took the approach it did in marketing to an international market? What did they not consider in marketing their product, good or service? What consequences did the company suffer as a result of this failed marketing...
Select one publicly listed company from a country that has adopted IFRS (not Australia). Collect the...
Select one publicly listed company from a country that has adopted IFRS (not Australia). Collect the most recent annual financial reports for their selected firm and then prepare a detailed report in which they: •   Critically analyze and explain about the selected firm. •   Critically analyze the national reporting and regulatory environment within which the selected firm operates. •     select two specific accounting items from the firm’s accounts and discuss the extent to which the company consistently applies the relevant...
Assignment Description: Write a C++ program for keeping a course list for each student in a...
Assignment Description: Write a C++ program for keeping a course list for each student in a college. Information about each student should be kept in an object that contains the student id (four digit integer), name (string), and a list of courses completed by the student. The course taken by a student are stored as a linked list in which each node contain course name (string such as CS41, MATH10), course unit (1 to 4) and the course grade (A,B,C,D,F)....
After the description has been written, the litmus test to a good description is that closes....
After the description has been written, the litmus test to a good description is that closes. True False A plat is required if at least one tract of the subdivision is five acres or less. True False
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT