Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++, virtual studios In the game of Musical chairs, chairs are placed in a circle with one less chair than players. People march to the

C++, virtual studios

In the game of Musical chairs, chairs are placed in a circle with one less chair than players. People march to the music around the circle of chairs until the music stops. Then each person sits in the chair nearest them. The one person that cannot find a chair is eliminated from the game. A chair is removed, and the game continues until there is just one person left. That person is the winner. Write a program to simulate a game of Musical chairs and determine the winner of each game played. The simulation will work as follows: The chairs are numbered from 1 to m. The people are numbered from 1 to m + 1. Two integers a and b are given. The first integer a is the chair number where person #1 will sit when the music stops. When the music stops, the people begin sitting down with person #1 sitting in chair a, person #2 sitting in chair a + 1, etc., until chair b is reached. The person who would have been assigned to chair b is eliminated and the next person in line is seated in chair b. Since the chairs are in a circle, once chair m is reached, the people begin sitting in chair #1 and continue until the rest of the people have been seated. The people are then renumbered with the person sitting in chair #1 becoming person #1, the person in chair #2 becoming person #2, etc. Chair number m is then removed, and the game is continued with one less chair and one less person. The first line of input from a text file, will contain a single integer n that indicates the number of games to be played. For each game there will be m + 2 lines where m is the number of chairs in the game. The first of these lines will be the integer m that indicates the number of chairs in the game. The second of these lines will have the first names of m + 1 players separated by a comma and a space. Each of the next m lines will have two integers separated by a space. The first integer a will represent the chair number where the people will begin sitting and the second number b will be the number, relative to the first chair, of the person who will not find a seat. Output to the screen each game played, properly labeled, on the Updated March 2, 2021 COSC 2436 S21 3 following line output original players of the game, output a blank line, then output the order of the players, beginning with chair #1, each time the music stops. The winner will be the last person. Output a blank line between each game played. Let the user input the file name from the keyboard. For C++ use the string class. Use a linked list data structure. Refer to the sample output below.

Sample Run:

Enter the file name: chairs.txt

Game 1:

Original List: ANNE, BECKA, CHAD, DREW, ERNIE, FRANK, GEORGE

FRANK GEORGE ANNE BECKA DREW ERNIE

ERNIE FRANK GEORGE ANNE BECKA

FRANK GEORGE BECKA ERNIE

BECKA ERNIE FRANK

FRANK ERNIE

Winner: FRANK

Sample Text File:

1 6 ANNE, BECKA, CHAD, DREW, ERNIE, FRANK, GEORGE 3 5 2 1 4 3 3 1 2 2 1 2

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

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

Write any 5 composite formulas.

Answered: 1 week ago

Question

Know the principles of effective service recovery systems.

Answered: 1 week ago

Question

Explain the service recovery paradox.

Answered: 1 week ago