Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++. We want to write a program for playing the game of NIM. Our version of the game starts with up to 20 pegs

In C++.

We want to write a program for playing the game of NIM. Our version of the game starts with up

to 20 pegs and up to 10 discs in each peg. Two players take turns removing discs from the

pegs. On a player's turn, she chooses a peg and removes one or more discs from that peg.

She can remove all discs from the peg. The player who takes the last disc from the pegs (so

that all pegs are empty) loses. This version of the game is called misere.

1- a)Write a procedure (this is a function that does not return a value and so is declared

with a return type of void) that prompt and reads the number of discs in each peg;. Define the

procedure to have three input parameters: the array of pegs, the size of the array,

and the maximum number of discs per peg. This

procedure will traverse the array of pegs and call the following helper procedure for

each peg in the list.

b- Write a helper procedure that will prompt the user for the number of discs to place on

this peg. If the number of discs entered for the peg is not between 1 and the maximum

number of discs allowed then display a warning message and prompt again. Define this

helper procedure to have three input parameters: the array entry for this peg (use pass

by reference), the array index for this peg, and the maximum number of discs per peg.

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

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

Students also viewed these Databases questions

Question

7. Define and describe the occurrence of culture shock.

Answered: 1 week ago

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago