Answered! Problem 1 Build a function with the prototype void setup Doors (char &doorl, char 6door2, char &door3) that…

Problem 1 Build a function with the prototype void setup Doors (char &doorl, char 6door2, char &door3) that randomly assigns the value C or G to the three reference parameters. Test this function to check the following 1. Each call must check that two of doorl door 2, and door is a G, and that the other is a C. 2. You can trust the built in random library to do good enough at assigning the result fairly. Problem 2 Write a function with prototype: void pick DoorChoices (char doorl char door 2, char door 3, int &door Player, int &door Monty) This procedure should randomly set a value 1 through 3 for door Player. The value of doorMonty should be set to an integer 1-3 that obeys the constraint that Monty never picks the same door as the player and never picks the door that has the car.
media%2F10c%2F10c9f0ba-ba26-42b1-8c35-23

Problem 1 Build a function with the prototype void setup Doors (char &doorl, char 6door2, char &door3) that randomly assigns the value C’ or G’ to the three reference parameters. Test this function to check the following 1. Each call must check that two of doorl door 2, and door is a ‘G’, and that the other is a ‘C’. 2. You can trust the built in random library to do good enough at assigning the result fairly. Problem 2 Write a function with prototype: void pick DoorChoices (char doorl char door 2, char door 3, int &door Player, int &door Monty) This procedure should randomly set a value 1 through 3 for door Player. The value of doorMonty should be set to an integer 1-3 that obeys the constraint that Monty never picks the same door as the player and never picks the door that has the car.

Expert Answer

 //main.c

#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;

int stay(char door1, char door2, char door3, int doorPlayer)
{
int count=0;
int num=0;
if(door1==’C’)
num=1;
else if(door2==’C’)
num=2;
else if(door3==’C’)
num=3;

if(doorPlayer==num)
count++;

return count;
}

void setupDoors(char &door1, char &door2, char &door3)
{
int num;

num=(rand() % 3 + 1);
if(num==1)
{
door1=’G’;
door2=’G’;
door3= ‘C’;
}
else if(num==2)
{
door1=’G’;
door2=’C’;
door3= ‘G’;
}
else if(num==3)
{
door1=’C’;
door2=’G’;
door3= ‘G’;
}

}

void pickDoorChoices(char door1, char door2, char door3, int &doorPlayer, int &doorMonty)
{
int num=0;
if(door1==’C’)
num=1;
else if(door2==’C’)
num=2;
else if(door3==’C’)
num=3;

doorPlayer = (rand() % 3 + 1);
do
{
doorMonty = (rand() % 3 + 1);
}while((doorMonty==num) || (doorMonty==doorPlayer));

}

int main()
{

srand(time(NULL));
char door1, door2, door3;
int doorPlayer, doorMonty;
int staying=0;
double total =10000;

for(int x=0; x<total;x++)
{
setupDoors(door1, door2, door3);
pickDoorChoices(door1, door2, door3, doorPlayer, doorMonty);
staying+=stay(door1, door2, door3, doorPlayer);
}
double a = (staying/total) * 100;
double b = (total-staying) / total * 100;

cout<<“Staying: ” <<a<<“%”<<endl;
cout<<“Switching: ” <<b<<“%”<<endl;

}

=============================================================================

sample output

Still stressed from student homework?
Get quality assistance from academic writers!