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...
Write a program that determines the probability of tossing a coin 10 times and getting exactly...
Write a program that determines the probability of tossing a coin 10 times and getting exactly 0, 1, 2, 3, etc. heads. This is the binomial probability distribution. Store the probability in an array. You could get 0 heads or 10 heads or anything inbetween. Use a for loop. The for loop will go from 0 to 10 inclusive. Use r as the number of successes. So r will go from 0 to 10. The probability of a success is...
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 .
Write a program that simulates flipping a coin repeatedly until three consecutive        heads are...
Write a program that simulates flipping a coin repeatedly until three consecutive        heads are tossed. The program should then display the total number of times the coin was        flipped. The user does not have to enter any information and we must use a while loop.
Write a program that simulates the flipping of a coin n times, where n is specified...
Write a program that simulates the flipping of a coin n times, where n is specified by the user. The program should use random generation to flip the coin and each result is recorded. Your program should prompt the user for the size of the experiment n, flip the coin n times, display the sequence of Heads and Tails as a string of H (for Head) and T (for Tail) characters, and display the frequencies of heads and tails in...
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...
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...
. Dice rolling: In c++Write a program that simulates the rolling of two dice. The sum...
. Dice rolling: In c++Write a program that simulates the rolling of two dice. The sum of the two values should then be calculated. [Note: Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums.] The following table shows the 36 possible combinations of the two dice. Your program should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT