0

How do I write pointer reference parameter of coin class type?

Code instructions: The Coin class will act as the base class. Three child classes will be created using the Coin class as the base class. The classes will be Quarter, Dime, and Nickel. These child classes will contain a constructor that will be used to set the value field to the value of their amount (Quarter = 0.25, Dime=0.10, Nickel=0.05) Instead of creating a separate counter variable to keep the balance of the coins the static field balance will keep track of the balance of the coin tosses. Write a program that uses the Quarter, Dime, and Nickel classes. The program will create one of each instance of the Quarter, Dime, and Nickel class. When the game begins, your starting balance is $0. During each round of the game, the program will toss each of the simulated coins. When a tossed coin lands heads-up, the value of the coin is added to your balance. For example, if the quarter lands heads-up, 25 cents is added to your balance. Nothing is added to your balance for coins that land tails-up. The game is over when your balance reaches one dollar or more. If your balance is exactly one dollar, you win the game. If your balance exceeds one dollar, you lose. In the main create a function called evaluateToss that will take a Coin reference pointer parameter. Use this method to toss the coin, decide if the coin is showing heads or tails, and add the value to the balance if needed. Pass the Quarter, Dime, and Nickel objects to this function each time to do the work. What I have tried: Below is the code I've written so far but can anyone please help me to write correct code by using pointer reference parameter in evaluateToss function so that it works correctly. #include<iostream> #include<string> #include<stdlib.h> using namespace std; //Coin class class Coin { private: double balance; string sideUp; bool heads; double value; public: Coin(double val) { value = val; int side = rand() % 2; if (side == 0) { sideUp = "heads"; heads = true; } else { side

4th Mar 2022, 4:56 AM
bazi
bazi - avatar
1 Resposta
0
Hi Bazi, The code is too big to fit in the Description, thus it got truncated (incomplete). Please save a copy of the code in SoloLearn (as a code bit) and share the code link instead. Code links doesn't need as much space as raw text code, easier to access and review. Follow this guide to share your code link https://www.sololearn.com/post/75089/?ref=app
4th Mar 2022, 7:39 AM
Ipang