Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS 241: Advanced Object-Oriented Programming using C++ Spring 2021 Homework 4 A school building has two floors with equal number of classrooms in each floor.

image text in transcribedimage text in transcribedimage text in transcribed

CS 241: Advanced Object-Oriented Programming using C++ Spring 2021 Homework 4 A school building has two floors with equal number of classrooms in each floor. On a Saturday, the principle went to the school to finish some work and he took his son with him. Being bored, the son decided to entertain himself by going around the building and checking each classroom door. If the door is closed, he opens it and if it is open he closes it. To make it more exciting for himself, he decided to do this game in several rounds and change the status of certain doors each round. Here is how he played the game: For odd rounds (rounds 1, 3, 5, etc.) he visits the first floor only and for even rounds, he visits the second floor only. In each round, he doesn't visit all the doors on the floors he is visiting. He skips some doors and visits other doors depending on the round number. For example: o In round 1 (odd round number), he visits the first floor and skips 1 door and visits door next to it and so until he finishes the floor. For example, he skips door 1 and visits door 2 then skips door 3 and visits door 4 and so on. In other words, in round 1, he visits every other door in floor 1. In round 2 (even round number), he visits the second floor and skips 2 doors and visits the third. For example, he skips doors 1 and 2 and visits door 3 then skips doors 4 and 5 and visits door 6 and so on. This means, in round 2, he visits every second door in floor 2. o In round 3 (odd round number), he visits the first floor and skips 3 doors and visits the fourth. For example, he skips doors 1, 2, and 3 and visits door 4 then skips doors 5, 6, and 7 and visits door 8 and so on until he finishes the floor. In other words, he visits every third door in floor 1. Let's assume all the doors are closed when he starts. Write a C++ program that simulates this game. The program should do the following: 1- Ask the user to enter the number of classrooms per floor. 2- Ask the user for the number of rounds in the game. 3. Once this data is entered, the program should simulate the game for the number of requested rounds then displays the total number of doors that will remain open at the end of the game and list them in each floor. 4- The program should ask the user if they want to play again. If the answer is yes, then it repeats again by asking for the parameters of the new game (number of classrooms and rounds). Here is an example of how the program should look like when it runs if the user enters 30 classrooms per floor and 5 rounds. How many classroons in each floor?: If the user enters 30 in response to this question, the program asks for the number of rounds. How many classrooms in each floor?: 30 How many rounds in this game?: If the user enters 5 in response to this question, the program will run for 5 rounds then displays the following at the end of the game. How many classrooms in each floor?: 38 How many rounds in this game?: 5 At the end of round 5 the total number of open doors is 19 (7 in floor1 and 12 in floor2) The open doors are: First Floor: Door2Doorle Door12 Door14 Door22 Door24 Door26 Second Floor: Doors Doors Doors Doors Doorie Door12 Door18 Door2e Door21 Door24 Door25 Door27 Play the game again (Y/N)? If the user answers Y or y in response to the play again question, the game restarts again by asking for the number of classrooms and the number of rounds. Any other input should terminate the program. Programming Requirements and Guidelines: Use pointers to dynamically allocate memory to store the status of each classroom door in each floor based on the number of classrooms provided by the user during program execution (runtime). Do not declare static arrays instead of using pointers and dynamic memory allocation. Include data validation for the values entered by the user. For example, your program should not accept 0 or any negative value for the number of classrooms or the number of game rounds. Design your program to be modular by having functions that perform various tasks and call these functions from the main. Each time you run the game, you should start round 1 with all the doors closed. This can be done by calling a function called closeAllDoors() which will reset the status of all doors to "closed". You may also include the following functions: o visit Floor(): This function will simulate visiting the classroom doors in a specific floor according to the rules mentioned above. The input to this function could be a pointer to the floor classroom doors array for the floor being visited as well as the round number so that it can decide which doors to visit on that specific floor. You may also want to pass the number of classrooms in the floor. For each door visited, if the door is open, it will close it and if it is closed it will open it. o getNumberOfOpenDoors(): This function counts the number of open door in a specific floor and returns this number. The input to this function could a pointer to the floor classrooms array. You may also want to pass the number of classrooms in the floor. o listOpenDoors(): This function will list all the doors that are open in a specific floor. The input to this function could a pointer to the floor classrooms array. You may also want to pass the number of classrooms in the floor. Do not use global variables. Each function should use it's local variables and the arguments passed to it from main. Since your programs will allocate dynamic memory during runtime, you must make sure it doesn't have any memory leaks by releasing any dynamically allocated memory at the end of each game. Part of your grade will be for the programming style used. Here are some guidelines: Each program should begin with a comment section giving the name of the file, the author's name, the date the file was last modified, and a description of its purpose. In addition, it is also considered good programming practice to include any assumptions you have made and any error-checking that has been provided. For example, Filename: make_change.cpp Author: L. Stauffer Date last modified: 2/10/2021 This program accepts a dollar amount specified by the user and displays the minimum number of $10, $5, and $1 bills required to make up the amount. */ o Use meaningful and descriptive identifiers for variable names. This can make a program easier to understand. Add comments in your program to provide clarity for the reader. o Use consistent and reasonable indentation conventions throughout your program to improve program readability. Avoid using several spaces for an indent - instead use a tab. If there are several levels of indentation, each level should be indented the same additional amount of space. When you are finished, submit your source code file in Blackboard by the due date. Your source code file is the file that has the C++ code (the .cpp file). Don't submit the Visual Studio solution file (the .sin file). The only file you need to submit is the C++ source code file for your program. No picture or screen captures of your program is needed

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

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago