Question: Functionality Must be done in C++ You will define a small hierarchy of fairy classes. In main(), you will then instantiate (i.e., create) several fairy

  • Functionality Must be done in C++

    You will define a small hierarchy of fairy classes. In main(), you will then instantiate (i.e., create) several fairy objects (from the derived classes ONLY), but no more than 5. When the user encounters a fairy, the fairy will state his/her name and ask what the user wants. In response, the user may:

    • Ask for a wish,
    • Offer to help the fairy, or
    • Say goodbye to the fairy.

    The user will continue to interact with the fairy until the user chooses the final option, saying goodbye to the fairy. Once the user says goodbye, the game moves on to the next fairy. After the user has encountered all of the fairies, the game is over and the user's points total is displayed.

  • Specifications

    • All interaction will occur through standard input and standard output.
    • Fairy (base class; NEVER instantiated):
      • Must state his/her name and a greeting
      • Must ask what the user wants
      • Must respond to requests for wishes
      • Must respond to offers to help
    • Good Fairy (derived class):
      • Will always grant a wish
      • For each wish granted, the user gets 10 points
      • Will accept an offer for help once, but then decline additional offers
      • The user earns 50 points for the offer to help
      • Can grant up to 5 wishes
    • Evil Fairy (derived class):
      • Will always deny the user's wish; i.e., cannot grant any wishes
      • For each wish denied, the user loses 10 points
      • Will always reject an offer of help
      • For each offer rejected, the user loses 50 points
    • Equivocal Fairy (derived class):
      • Will grant the user's wish sometimes (based on a random number generator)
      • For each wish granted, the user gets 10 points
      • For each wish denied, the user loses 10 points
      • Will respond to an offer of help with the statement, "I'll think about it"
      • Can grant up to 3 wishes
    • No fairy may disclose what type it is, nor may the user ask. The user must figure out the type of fairy encountered by assessing the responses.
    • Inherit the members and methods that you can, redefining only when necessary.
  • Interaction

    Here is a sample interaction:

    Hello, my name is Pixie! What is your choice? Enter a number as follows: 1) Ask for a wish 2) Offer to help me 3) say goodbye ? 2 You have offered to help me. How wonderful! You earn 50 points. What is your choice? Enter a number as follows: 1) Ask for a wish 2) Offer to help me 3) say goodbye ? 3 Goodbye to you, too! Hello, my name is Esmeralda! What is your choice? Enter a number as follows: ... 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!