Answered step by step
Verified Expert Solution
Question
1 Approved Answer
9 . 1 4 LAB: Flipping for tails Given main ( ) and GVCoin struct, complete function FlipForTails ( ) in main.c that counts and
LAB: Flipping for tails
Given main and GVCoin struct, complete function FlipForTails in main.c that counts and returns the number of flips taken to achieve a desired number of tails. Function FlipForTails has a GVCoin struct and an integer representing the desired number of tails as parameters. Review the GVCoin struct in "GVCoin.h and the function implementations in "GVCoin.c by clicking on the orange arrow.
Note: For testing purposes, a GVCoin struct is created in the main function using a pseudorandom number generator with a fixed seed value. The program uses a seed value of during development, but when submitted, a different seed value will be used for each test case.
Ex: If the GVCoin struct is created with a seed value of and the desired number of tails is then the function FlipForTails returns and the program outputs:
Total number of flips for tails:
#ifndef GVCOINH
#define GVCOINH
#include
#include
typedef struct GVCoinstruct
bool isHeads;
int flips;
int heads;
GVCoin;
GVCoin InitGVCoinint seed;
GVCoin FlipGVCoin coin;
int NumFlipsGVCoin coin;
int NumHeadsGVCoin coin;
int NumTailsGVCoin coin;
bool IsHeadsGVCoin coin;
#endif
#include
#include
#include
#include "GVCoin.h
GVCoin InitGVCoinint seed
srandseed;
GVCoin coin;
coin.heads ;
coin.flips ;
coin.isHeads ;
return coin;
GVCoin FlipGVCoin coin
coin.isHeads rand;
coin.flips;
if coinisHeads
coin.heads;
return coin;
int NumFlipsGVCoin coin
return coin.flips;
int NumHeadsGVCoin coin
return coin.heads;
int NumTailsGVCoin coin
return coin.flips coin.heads;
bool IsHeadsGVCoin coin
return coin.isHeads;
#include
#include "GVCoin.h
#include "GVCoin.h
int FlipForTailsGVCoin coin, int goal
int numflips ;
int numtails ;
while numtails goal
Flipcoin;
numflips;
if IsHeadscoin
numtails;
return numflips;
int main
GVCoin coin InitGVCoin; Create a GVcoin object with seed value
int numTails ; Desire tails
int total FlipForTailscoin numTails; Should return using GVcoin object with seed value
printfTotal number of flips for tails: d
total;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started