Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want a unique c++ problem. Create derived class called FizzBuzzExt from FizzBuzz generator class. FizzBuzz class is represented below combined with main class. All

I want a unique c++ problem.

Create derived class called FizzBuzzExt from FizzBuzz generator class. FizzBuzz class is represented below combined with main class.

All the thing in bold letters are supposed to be done in FizzBuzzExt

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).

Please prepare three files, a header file for FizzBuzz ( Already provided), a header file for FizzBuzzExt, and a cpp file with the main function (modify main).

FIZZBUZZ with main( please separate these files )

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

#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

}

Combine and provide 3 files and Show Output !

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

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions