Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program that simulates a game of chance using object-oriented principles. To begin, the program should prompt and read in the user's starting

Write a C++ program that simulates a game of chance using object-oriented principles. To begin, the program should prompt and read in the user's starting balance value. Validate this value. The minimum balance must be at least $1 (one dollar). The random generator should be called to produce a value between 1 and 6 (similar to a die). If the random generator number is an even number, the user wins $1. If the random generator number is an odd number, the user loses $1. The user may play as much as they want as long as they have at least $1 balance. If the balance falls below $1, the game is over. If the user wishes to continue to play, the random generator is called again. Odd loses $1 and even wins $1. The program must keep up with the balance of the user. With each instance, the balance is displayed along with if the user won $1 or lost $1.

The program should have as a minimum: a class named Game private member variables:

int balance

int rolled value from the random generator

char to hold the value if the user wants to roll again

void validateBalance() - validates the input balance value from the user

void validateAgain() - validates the answer if the user wants to roll again (y or n entered)

public member functions:

constructor to seed the random generator and set the balance to zero

void setBalance() - reads in the starting balance entered from the user

void roll() - call the random generator to return a value between 1 and 6

void display() - display the results of the roll (odd or even) and the user's balance

void again() - determine if the user wants to roll again or quit the game

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

Were they made on a timely basis?

Answered: 1 week ago

Question

Did the decisions need to be made, or had they already been made?

Answered: 1 week ago

Question

When there was controversy, was it clear who had the final say?

Answered: 1 week ago