Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This card game requires a certain number of cards, n, where the n is a triangular number. A triangular number is a number that represent

image text in transcribed

This card game requires a certain number of cards, n, where the n is a triangular number. A triangular number is a number that represent the sum of the sequence: 1, 2, 3, 4, etc. For example, 21 123+4+56. The first few triangular numbers are 1, 3, 6, 15, 21, 28, 36, 45, etc. The Game: You will start the game with 45 cards. Divide the cards into a random number of piles. Each round, take one card from each pile and create a new one. Repeat the process until you have 9 piles of sizes 1, 2, 3, 4,5, 6, 7, 8, and 9 For example, if you start with 4 piles of 20, 15, 6, and 4, they would be transformed into 19,14, 5, 3, and 4, etc. Simulator Write a C++ program that simulates the game. Start by producing a random number of piles Make sure the total is 45. Apply the steps outlined above repeatedly until the final configuration is reached. At each step, print the number of cards in each of the piles. The final configuration is reached when the number of cards in the piles are 1, 2, 3, 4, 5, 6, 7, 8, and 9 Display the number of steps it took to reach the final configuration Hints: . Store the number of cards in each pile into an array of integers . To generate a random number use the function rand () in o First seed the random number generator with the current time. Do this only once in the program (beginning of main) ' srand (time (NULL)) To generate a random integer between 0 and 2147483647 ' randomIntegerrand ) Write a function that checks if the game is done by confirming the last sequence. You may want to sort the values to make it easier to check. . Extra Credit: Fix your program to accept any triangular number from the keyboard. Please complete the original requirements before attempting the extra credit. This card game requires a certain number of cards, n, where the n is a triangular number. A triangular number is a number that represent the sum of the sequence: 1, 2, 3, 4, etc. For example, 21 123+4+56. The first few triangular numbers are 1, 3, 6, 15, 21, 28, 36, 45, etc. The Game: You will start the game with 45 cards. Divide the cards into a random number of piles. Each round, take one card from each pile and create a new one. Repeat the process until you have 9 piles of sizes 1, 2, 3, 4,5, 6, 7, 8, and 9 For example, if you start with 4 piles of 20, 15, 6, and 4, they would be transformed into 19,14, 5, 3, and 4, etc. Simulator Write a C++ program that simulates the game. Start by producing a random number of piles Make sure the total is 45. Apply the steps outlined above repeatedly until the final configuration is reached. At each step, print the number of cards in each of the piles. The final configuration is reached when the number of cards in the piles are 1, 2, 3, 4, 5, 6, 7, 8, and 9 Display the number of steps it took to reach the final configuration Hints: . Store the number of cards in each pile into an array of integers . To generate a random number use the function rand () in o First seed the random number generator with the current time. Do this only once in the program (beginning of main) ' srand (time (NULL)) To generate a random integer between 0 and 2147483647 ' randomIntegerrand ) Write a function that checks if the game is done by confirming the last sequence. You may want to sort the values to make it easier to check. . Extra Credit: Fix your program to accept any triangular number from the keyboard. Please complete the original requirements before attempting the extra credit

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

Postgresql 16 Administration Cookbook Solve Real World Database Administration Challenges With 180+ Practical Recipes And Best Practices

Authors: Gianni Ciolli ,Boriss Mejias ,Jimmy Angelakos ,Vibhor Kumar ,Simon Riggs

1st Edition

1835460585, 978-1835460580

More Books

Students also viewed these Databases questions

Question

What does the acronym CI/CD stand for? LOP857

Answered: 1 week ago

Question

Pinpoint your needs for improvement in interpersonal relations.

Answered: 1 week ago