Develop a Gyarados class which only contains the following one member variable and four member functions: A member variable is needed that is a counter for the integer number of flips that have been taken A negative value will indicate that the game has completed (Tails has been flipped) A non-negative value (0 and up) will indicate that the game is still active (No tails yet) The magnitude of the number indicates the total flips of the coin so far Example: +0 means the game just started and is active (?) Example: +3 means the game is still active and three heads have been flipped so far (HHH?) Example: -4 means the game has completed and three heads were flipped before the final tails (HHHT) A default constructor for the class will be needed Simply initialize the counter variable to zero A member function named IsGameOver() will be needed No inputs and returns a bool The game is over if the counter variable value is negative, otherwise the game is active A member function named Flip() will be needed No inputs and has no outputs either If the game is over, do nothing If the game is still active, do the following: Increment the flip counter variable Simulate and randomize a new coin flip (0 or 1) If the new coin flip value is 0, then negate the counter variable to indicate the game is over A member function named NumberOfHeads() will be needed No inputs and has an integer return value The return value is the number of heads flips currently recorded by the game If the counter value is non-negative (0 and up) then return it If the counter value is negative, then return the value turned positive and then decremented by one Example: +0 would return 0 Example: +2 would return 2 (HH?) Example: -5 would return 4 (HHHHT) Example: +3 would return 3 (HHH?) Example: -4 would also return 3 (HHHT) Example: +8 would return 8 (HHHHHHHH?) Example: -13 would return 12 (HHHHHHHHHHHHT)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Develop a Gyarados class which only contains the following one member variable and four member functions:

  1. member variable is needed that is a counter for the integer number of flips that have been taken
    • A negative value will indicate that the game has completed (Tails has been flipped)
    • A non-negative value (0 and up) will indicate that the game is still active (No tails yet)
    • The magnitude of the number indicates the total flips of the coin so far
    • Example: +0 means the game just started and is active (?)
    • Example: +3 means the game is still active and three heads have been flipped so far (HHH?)
    • Example: -4 means the game has completed and three heads were flipped before the final tails (HHHT)
  2. default constructor for the class will be needed
    • Simply initialize the counter variable to zero
  3. member function named IsGameOver() will be needed
    • No inputs and returns a bool
    • The game is over if the counter variable value is negative, otherwise the game is active
  4. member function named Flip() will be needed
    • No inputs and has no outputs either
    • If the game is over, do nothing
    • If the game is still active, do the following:
      • Increment the flip counter variable
      • Simulate and randomize a new coin flip (0 or 1)
      • If the new coin flip value is 0, then negate the counter variable to indicate the game is over
  5. member function named NumberOfHeads() will be needed
    • No inputs and has an integer return value
    • The return value is the number of heads flips currently recorded by the game
    • If the counter value is non-negative (0 and up) then return it
    • If the counter value is negative, then return the value turned positive and then decremented by one
    • Example: +0 would return 0
    • Example: +2 would return 2 (HH?)
    • Example: -5 would return 4 (HHHHT)
    • Example: +3 would return 3 (HHH?)
    • Example: -4 would also return 3 (HHHT)
    • Example: +8 would return 8 (HHHHHHHH?)
    • Example: -13 would return 12 (HHHHHHHHHHHHT)
    •  
// There is no need to modify the contents of this file in any way
// Please make your Gyarados class work with this template source code
// Just need a standard library and your custom made class
#include <iostream>
#include "Gyarados.h"
// EXAMPLE RESULTS OF FIVE TRIAL RUNS OF THIS PROGRAM
// YOU SHOULD ALWAYS GET A RESULT PRETTY CLOSE TO 1.00
// 100106 HEADS IN 100000 ROUNDS = 1.00106
99546 HEADS IN 100000
ROUNDS = 0.99546
// 100133 HEADS IN 100000
ROUNDS = 1.00133
99947 HEADS IN 100000
ROUNDS = 0.99947
99647 HEADS IN 100000 ROUNDS = 0.99647
int main()
{
}
// Randomize the randomness
srand(static_cast<unsigned int>(time(NULL)));
// Experimental counters
const int ROUNDS = 100000;
int heads = 0;
// Let's brute force the simulation
for (int i = = 1; i <= ROUNDS; ++i)
{
// Keep flipping until the game has come to a conclusion
Gyarados game;
while (game.IsGameOver()
false)
{
game. Flip();
==
}
// Certainly one way to find out how many heads were flipped before a tails
heads + game. NumberOfHeads();
}
// Print final results
std::cout << heads << HEADS IN << ROUNDS << ROUNDS = ";
std::cout << static_cast<double> (heads) / ROUNDS << std::endl;
// Program complete
return 0;
Transcribed Image Text:// There is no need to modify the contents of this file in any way // Please make your Gyarados class work with this template source code // Just need a standard library and your custom made class #include <iostream> #include "Gyarados.h" // EXAMPLE RESULTS OF FIVE TRIAL RUNS OF THIS PROGRAM // YOU SHOULD ALWAYS GET A RESULT PRETTY CLOSE TO 1.00 // 100106 HEADS IN 100000 ROUNDS = 1.00106 99546 HEADS IN 100000 ROUNDS = 0.99546 // 100133 HEADS IN 100000 ROUNDS = 1.00133 99947 HEADS IN 100000 ROUNDS = 0.99947 99647 HEADS IN 100000 ROUNDS = 0.99647 int main() { } // Randomize the randomness srand(static_cast<unsigned int>(time(NULL))); // Experimental counters const int ROUNDS = 100000; int heads = 0; // Let's brute force the simulation for (int i = = 1; i <= ROUNDS; ++i) { // Keep flipping until the game has come to a conclusion Gyarados game; while (game.IsGameOver() false) { game. Flip(); == } // Certainly one way to find out how many heads were flipped before a tails heads + game. NumberOfHeads(); } // Print final results std::cout << heads << HEADS IN << ROUNDS << ROUNDS = "; std::cout << static_cast<double> (heads) / ROUNDS << std::endl; // Program complete return 0;
Expert Solution
Step 1

As per the given information:

Class name: Gyarados

Attribute: counter

Methods:

  1. Default constructor
  2. IsGameOver()
  3. Flip()
  4. NumberOfHeads()

We need to implement this class as per the given requirements.

 

steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education