Help with C Code - I have also posted some of my code below. I need help finishi
ID: 3848144 • Letter: H
Question
Help with C Code - I have also posted some of my code below. I need help finishing it.
4. Suppose that a university wants to show off how politically correct it is by applying the U.S. Supreme Courts "Separate but equal is inherently unequal" doctrine to gender as well as race, ending its long- standing practice of gender-segregated bathrooms on campus. However, as a concession to tradition, it decrees that when a woman is in a bathroom, other women may enter, but no men, and vice versa. For example, if a woman is currently using the restroom and another woman wants to use the restroom, the second woman is allowed to enter. However, if a man wants to use the restroom, he must wait. A sign with a sliding marker on the door of each bathroom indicates which of three possible states it is currently in Empty Women present Men present In C code using whatever constructs you like (mutexes, condition variables, semaphores, etc.), write the following procedures woman wants-to-enter man wants to enter woman leaves man leavesExplanation / Answer
int placement(){
int i;
for(i = 0; i < 50; i++)
if (queue[i]!='F' && queue[i]!='M'){
return i;
}
}
void woman_leaves(){ //bathroom int signals bathroom occupants. 0 = Empty, < 0 = Males Present, > 0=Females present
bathroom--;
}
void man_leaves(){ //bathroom int signals bathroom occupants. 0 = Empty, < 0 = Males Present, > 0=Females present
bathroom ++;
}
void woman_wants_to_enter()
{
int i;
queue[placement()]='F'; //place F in first available queue
for (i=0; queue[i] != ''; i++){
if (queue[0]='F' && bathroom >=0){
queue[i] = queue[i+1]; //removes F from beginning of Queue
printf (" Woman enters bathroom.");
bathroom ++;
}
}
if (bathroom < 0){
man_leaves();
printf(" Woman can not enter. Placed in queue spot ");
printf("%d", placement());
queue[placement()]='F';
}
displayQueue();
}
void man_wants_to_enter()
{
int i;
queue[placement()]='M';
for (i=0; queue[i] != ''; i++){
if (queue[0]='M' && bathroom <=0){
queue[i] = queue[i+1];
printf (" Man enters bathroom.");
bathroom --;
}
}
if (bathroom > 0){
woman_leaves();
printf(" Man can not enter. Placed in queue spot.");
printf("%d", placement());
queue[placement()]='M';
}
displayQueue()
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.