1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
elena-s [515]
3 years ago
6

Write a program that simulates flipping a coin repeatedly and continues until three consecutive heads. are tossed. At that point

, your program should display the total number of coin tips that were made the average number of heads. #1 - Write a function to read in the user's information (name & gender) #2 - Write a function to flip the coin and return a bool (heads = true, tails = false) #3 - Write a function to calculate the average of heads vs. total flips #4 - Write a function to output the results Address male users as Mr. and female users as Ms. HINT: Code one function at a time and test it... then add the loop and re-test. Turn in as a single PDF file-Include three (3) test runs. 1-Output (cut and pasted into a txt file in eclipse) 2- Source Code (printed from eclipse - PROPERLY DOCUMENTED) INPUT/OUTPUT - should be formatted as follows - This represents one possible sample run (Class heading should be also displayed) Welcome to coin toss! Get 3 heads in a row to win! What is your name? Ed Peck What is your gender (m/f): M Try to get 3 heads in a row. Good luck Mr. Ed Peck! Press to flip TAIL Press center> to flip HEAD Press to flip HEAD Press center to flip HEAD Press center> to flip HEAD It took you 6 tosses to get 3 heads in a row. On average you flipped heads 67% of the time
Computers and Technology
1 answer:
quester [9]3 years ago
8 0

Answer and Explanation:

#include <iostream>

#include <string>

#include <time.h>

#include <vector>

using namespace std;

//Takes user info

int user_info(string *name,char *gender){

   char G;

   cout<<"What is your name?: ";

   getline(cin, *name);

   cout<<"What is your gender(m/f):";

   cin>>G;

   cout<<endl;

   *gender = tolower(G);

   return 0;

}

//Toss coin(part 2)

bool coin_toss(double seed){

   double r;

   r = (double)seed/(double)RAND_MAX;

   //cout<<r;

   if (r<0.5) return true;

   return false;

}

//check results

float toss_result(vector<char> v,int *h){

   int num_heads=0;

   int num_toss = v.size();

   *h = 0;

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

       if(v[i]=='h'){num_heads++;(*h)++;}

   }

   return (float)num_heads/(float)num_toss;

}

void show_result(int total_num,int head_num,float ratio){

   cout<<"it took you "<<total_num<<" tosses to get 3 heads in a row"<<endl;

   cout<<"on average you flipped heads "<<(ratio*100)<<"% of the time"<<endl;

}

int main()

{

   string name;

   char gender;

   string K; //Mr or Mrs

 

   cout<<"Welcome to coin toss! Get 3 heads in row to win!"<<endl;

 

   //part 1

   user_info(&name,&gender);

 

   if(gender == 'f') K = "Mrs.";

   else K = "Mr.";

 

   cout<<"Try to get 3 heads in a row. Good luck "<<K<<name<<"!"<<endl;

   char dummy = getchar();

 

   //part 2

   int num_toss;

   vector<char> toss_results;//store toss results

   bool result;//result of toss

   srand(time(0));

   while(true){

       //cout<<rand()<<endl;

       result = coin_toss(rand());

       cout<<"Press <enter> to flip"<<endl;

       while (1)

       {

           if ('\n' == getchar())

           break;

       }

     

 

     

       if(result) {toss_results.push_back('h');cout<<"HEAD"<<endl;}

       else {toss_results.push_back('t');cout<<"TAIL"<<endl;}

     

       num_toss = toss_results.size();

     

       if(num_toss>=3){

           if ((toss_results[num_toss-1] == 'h')&&(toss_results[num_toss-2] == 'h')&&(toss_results[num_toss-3] == 'h')){

               break;

           }

       }

   }

 

   //part 3

   float ratio_head;

   int num_of_heads;

   ratio_head = toss_result(toss_results,&num_of_heads);

 

   //part 4

 

   show_result(toss_results.size(),num_of_heads,ratio_head);

 

   return 0;

}

You might be interested in
According to the SANS Institute, a __________ is typically a document that outlines specific requirements or rules that must be
nata0808 [166]
That’s should be in the quizlet I think..
7 0
3 years ago
Robert and Anne, a married couple filing jointly, have an adjusted gross income of $68,676. They claim two exemptions, and can d
artcher [175]

Answer:

the answer is B

Explanation:

Just took the test

8 0
2 years ago
Read 2 more answers
What do character format's do for your documents message
MrMuchimi

depends you could use .doc .pdf whatever you would prefer if you made a document and named it mybirthdaylist if you would put it in .doc or .pdf

3 0
3 years ago
When you move the pointer to the left of two existing rows, a(n) ____ appears outside the table.?
marishachu [46]
When you move the pointed to the left of two existing rows, a SUPER POINTER appears outside the table. 

The super pointer is usually a small black arrow or a white arrow that is pointing to the right. Clicking the mouse while the super pointer is active will select the row. 

The super pointer also appears when the mouse pointer is at the top edge of a column. The super pointer will be pointing downwards. 
6 0
3 years ago
"If an architecture has a move instruction with more than one word and at most one of the two operands may be an indirect memory
Citrus2011 [14]

Answer:

6

Explanation:

An instruction set architecture (ISA) can be defined as series of native memory architecture, instructions, addressing modes, external input and output devices, virtual memory, and interrupts that are meant to be executed by the directly.

Basically, this set of native data type specifies a well-defined interface for the development of the hardware and the software platform to run it.

Also, the set of instructions that defines the computer operation to perform (operand specifier) such as the addition of memory contents to a register, conditional move is referred to as an opcode. Thus, the number of operands in an instruction is grouped with respect to the maximum number of operands stated in the particular instruction such as 0, 1, 2, 3, etc.

In a processor, the minimum number of frames needed by a process depends on its instruction set architecture (ISA), as well as the number of pages used by each instruction.

<em>Hence, if an architecture has a move instruction with more than one word and at most one of the two operands may be an indirect memory reference, the minimum number of frames needed to run a process on this architecture is 6.</em>

6 0
3 years ago
Other questions:
  • Transparency is an important concept in policies related to the handling and use of customer data. Organizations should be trans
    5·1 answer
  • Which of the following actions might contribute to recommendations you see online?
    6·1 answer
  • How does a hard drive work?
    5·1 answer
  • What to do when you accidentally delete usb drivers?
    8·1 answer
  • Rhea has been asked to interview the new CEO of an energy company. She has scheduled a meeting with him in the company’s meeting
    9·2 answers
  • Mention two strategies of collecting data​
    13·1 answer
  • Lab 6B: printing a binary number
    13·1 answer
  • Danielle is analyzing logs and baselines of the systems and services that she is responsible for in her organization. She wants
    12·1 answer
  • 8.11 LAB: Count characters - functions Write a program whose input is a character and a string, and whose output indicates the n
    6·1 answer
  • In one sentence, how would you sum up the internet?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!