Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want a unique c++ problem. Please solve this problem with comments and proper format. Please solve this C++ problem, Just modify and separate the

I want a unique c++ problem. Please solve this problem with comments and proper format.

Please solve this C++ problem, Just modify and separate the files. Please prepare three files, a header file for FizzBuzz, a header file for FizzBuzzExt, and a cpp file with the main function.

Create derived class called FizzBuzzExt from FizzBuzz generator class. I will provide the code below!!

define a struct with two parts: an integer factor (3, 5, 11, etc.) and a string associated (fizz, buzz, biff, etc)

create a private attribute array of these structs

new methods:

clear()

addRule()

run()

menu()

The user should be presented with a menu that allows them to clear the game, run the game, add a rule, set a new limit, or quit, whenever they wish, as many times as they wish (of course, they'll only be able to quit once per game).

USE THIS CODE TO MODIFY!!!

// ------------------------------------------------------------------------

#include

using namespace std;

class FizzBuzz

{

// private data members

private:

int limit; // stores the maximum output value

// public methods

public:

FizzBuzz();

void run();

void setLimit();

};

// ------------------------------------------------------------------------

//Constructor which sets limit to its default value of 100

FizzBuzz::FizzBuzz()

{

limit = 100;

}

// ------------------------------------------------------------------------

//Function to play the stored game of FizzBuzz

void FizzBuzz::run()

{

for(int i = 1; i <= limit; i++){

if(i % 3 == 0 && i % 5 == 0) // The number is divisible by both 3 and 5

cout << "FizzBuzz" << endl;

else if(i % 3 == 0) // The number is only divisible by 3

cout << "Fizz" << endl;

else if(i % 5 == 0) // The number is only divisible by 5

cout << "Buzz" << endl;

else cout << i << endl;

}

}

// ------------------------------------------------------------------------

// Asks the user for a new value of limit and sets it replacing

// the default value of limit

void FizzBuzz::setLimit()

{

int val;

cout << " Enter the new limit of the game: ";

cin >> val;

limit = val; // new value of limit is set

cout << "New limit is set to " << limit << endl;

cout << " "; // moves the cursor to a newline

}

int main()

{

FizzBuzz f; // an object of the class is created

int choice;

// Menu

do

{

cout << "**********Menu**********" << endl << endl;

cout << "1. Run the game" << endl << "2. Set the limit value"

<< endl << "3. Quit" << endl;

cout << endl << "Enter your choice: ";

cin >> choice;

switch(choice)

{

case 1:

cout << endl;

f.run();

cout << endl;

break;

case 2:

f.setLimit();

break;

case 3:

cout << endl << "The game is quitting, Goodbye." << endl;

exit(0);

default:

cout<< "Wrong Choice. Try Again."<< endl << endl;

break;

}

}

// while condition is true i.e., until the user wants to quit the game,

// the game will continue.

while(1);

return 0

}

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

Recommended Textbook for

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions

Question

Replace the question mark by or = whichever is correct. 2/3 ? 0.67

Answered: 1 week ago

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago