Question

In: Computer Science

In C++  Write a program that simulates coin tossing. For each toss of the coin the program...

In C++  Write a program that simulates coin tossing. For each toss of the coin the program should print heads or tails. Let the program toss the coin 100 times and count the number times each side of the coin appears. Print the results. 0 represents tails and 1 for heads.

Solutions

Expert Solution

#source code in c++

#include<iostream>

#include <ctime>

#include <random>

using namespace std;

int main(){

srand(time(0));

int tail_count=0;

int head_count=0;

for(int i=0;i<100;i++){

int r=rand()%2;

if(r==0){

tail_count=tail_count+1;

cout<<"tail"<<endl;

}

if(r==1){

head_count=head_count+1;

cout<<"head"<<endl;

}

}

cout<<"head-count:"<<head_count<<endl;

cout<<"tail-count:"<<tail_count<<endl;

return 0;

}

#source code and output:

#if you have any doubt or more information needed comment below...i will respond as possible as soon..thanks...


Related Solutions

Write an application that simulates coin tossing. Let the program toss a coin each time the...
Write an application that simulates coin tossing. Let the program toss a coin each time the user chooses the “Toss Coin” menu option. Count the number times each side of the coin appears. Display the results. The program should call a method flip( ) that takes no arguments and returns a zero to represent a tail or a one to represent a head. There is a Random class that will allow you to generate a random integer. Import it from...
C++ Create a program that simulates a coin being flipped. Ask the user to guess between...
C++ Create a program that simulates a coin being flipped. Ask the user to guess between heads and tails. Let the user input 0 for heads and 1 for tails. Use a random generator to get random guesses every time. If the user guesses correctly, give them 1pt. Use a counter and initialize it to 0.   If the user does not guess correctly, subtract a point. Create a menu that allows the user to continue guessing, view the current score...
I toss a fair coin 20 times. (a) Calculate the probability of tossing 18 or more...
I toss a fair coin 20 times. (a) Calculate the probability of tossing 18 or more heads exactly. (b) Now perform the same calculation, approximating the actual binomial distribution with a normal distribution, picking a proper random variable, and using the correct mean and variance. (c) Do the results reasonably agree?
For which of these coin-tossing scenarios are you most likely to get heads on every toss?...
For which of these coin-tossing scenarios are you most likely to get heads on every toss? Explain your answer. Toss a coin 3 times. Toss a coin 5 times. Toss a coin 10 times .
Create a histogram on excel for a coin toss. Flip the coin 6 times, each time...
Create a histogram on excel for a coin toss. Flip the coin 6 times, each time moving down to the left (for heads) and to the right (for tails). Consider it a success if when flipping a coin, the coin lands with the head side facing up. Then the probability of a success is .5 (p=.5) and the probability of failure is .5 (q=.5) for each event of flipping a coin. In this lab you will repeat a procedure of...
Create a histogram on excel for a coin toss. Flip the coin 6 times, each time...
Create a histogram on excel for a coin toss. Flip the coin 6 times, each time moving down to the left (for heads) and to the right (for tails). Consider it a success if when flipping a coin, the coin lands with the head side facing up. Then the probability of a success is .5 (p=.5) and the probability of failure is .5 (q=.5) for each event of flipping a coin. In this lab you will repeat a procedure of...
Write a program in c++ that prompts the user to input a coin collection of number...
Write a program in c++ that prompts the user to input a coin collection of number of quarters, dimes, nickels and pennies. The program should then convert the coin collection into currency value as dollars. The coin values should all be whole numbers and the resulting currency value should be displayed with two decimals. An example of user interaction is as follows: Coin Convertor Enter number of quarters: 3 Enter number of dimes: 1 Enter number of nickels: 4 Enter...
USE R-studio TO WRITE THE CODES! # 2. More Coin Tosses Experiment: A coin toss has...
USE R-studio TO WRITE THE CODES! # 2. More Coin Tosses Experiment: A coin toss has outcomes {H, T}, with P(H) = .6. We do independent tosses of the coin until we get a head. Recall that we computed the sample space for this experiment in class, it has infinite number of outcomes. Define a random variable "tosses_till_heads" that counts the number of tosses until we get a heads. ```{r} ``` Use the replicate function, to run 100000 simulations of...
On each turn, bonnie is tossing a fair coin and Clyde is rolling a fair die....
On each turn, bonnie is tossing a fair coin and Clyde is rolling a fair die. They stop once Clyde rolls an odd number for the first time. Let X be the number of "Heads" that Bonnie's coin showed. a) Compute E[X] b) Compute var(X)
An experiment consists of repeatedly tossing 2 fair coins until the toss results in one each...
An experiment consists of repeatedly tossing 2 fair coins until the toss results in one each of a Head and a Tail. What is the mathematical expectation of the number of times you will need to toss the 3 coins to achieve this?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT