Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ program that uses object-oriented principles to play a game of chance. Name the class Game. The object of the game is to earn as

C++ program that uses object-oriented principles to play a game of chance. Name the class Game. The object of the game is to earn as many points as possible for payout. The computer will roll a pair of dice. Each die holds the value between 1 and 6. If the combination of the dice equal to 7 or 11, the user wins a point. If the combination of dice equal to 2, 3, or 12, the user loses a point. Any other combinations of the dice do not win or lose. The user may play until they wish to stop. The program will keep up with the total number of points won. When the user decides to end the game, the program will display the total number of dice rolls and the total points scored. The Game class should have the following private member variables:

  • die1: an integer randomly generated between 1 and 6
  • die2: an integer randomly generated between 1 and 6
  • totalPoints: an integer that holds the grand total of points won by the user
  • totalRolls: an integer that holds the total number of times the dice rolled

The class should have private member functions:

  • mutator functions to update the private member variables
  • accessor functions to access the private member variables
  • calls to the random generator
  • determine if win or loss

The member variables of the class should be set as private meaning that they may not be directly accessed in main(). The class should have the following public member functions:

  • driver - the sequence of calls to the class member functions
  • class constructor - to initialize private member variables

The program will validate all input values from the user. When the user opts to stop playing the game, display the number of times the user rolled the dice and how many total points accumulated

Example: Your Game of Chance! Do you want to roll? (y = yes, n = no): y Rolling the dice... You rolled a 7! You win! Points: 1 Do you want to roll? (y = yes, n = no): Y Rolling the dice... You rolled a 4! No points. Points: 1 Do you want to roll? (y = yes, n = no): okay Invalid response: y = yes, n = no: maybe Invalid response: y = yes, n = no: 2 Invalid response: y = yes, n = no: @ Invalid response: y = yes, n = no: y Rolling the dice... You rolled a 3! You lost. Points = 0 Do you want to roll? (y = yes, n = no): n You rolled the dice 3 times. You won 0 points. Better luck next time!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

List the four categories of HR metrics.

Answered: 1 week ago