implement in c++. This is a OS concept Implement the Ballroom Dancers simulation discussed on slides 26-28 in the Semaphores powerpoint. Input: .about n m output.txt where n is the number of \"leaders\" and m is the number of \"followers\" and output.txt is the output file generated by your program. Output: leader dances with follower for all threads... Note, the number of leaders and followers may be different. We want to make sure all dancers dance at least once. After all have dance, the program ends. Solution I have created the code with the information you have provided: #include //Provides API for POSIX(or UNIX) OS for system calls #include #include #include //For exit() and rand() #include //Threading APIs #include //Semaphore APIs #define DANCE_TIME 1 //Dance Time 1 second #define NUM_LEAD 2 //No. of leaders (input value can be set here for leaders) #define MAX_FOLL 30 //Maximum no. of followers for simulation (input value can be set here for followers) sem_t followers; //Semaphore sem_t leaders; //Semaphore sem_t mutex; //Semaphore for providing mutially exclusive access int MAX_LEADERS = NUM_LEAD; int danceWithMe = 0; //Index for next legitimate couple int serveMeNext = 0; //Index to choose a candidate for dancing int numberOfFreeLeaders = MAX_LEADERS;//Counter for Vacant seats in waiting room int seatPocket[MAX_LEADERS]; //To exchange pid between customer and barber static int count = 0; //Counter of No. of followers void leaderThread(void *tmp); //Thread Function void followerThread(void *tmp); //Thread Function void wait(); //Randomized delay function int main() { pthread_t leader[NUM_LEAD],follower[MAX_FOLL]; //Thread declaration int i,status=0; /*Semaphore initialization*/ sem_init(&followers,0,0); sem_init(&leaders,0,0); sem_init(&mutex,0,1); /*leader thread initialization*/ for(i=0;i 0) { --numberOfFreeLeaders; printf(\"follower-%d waiting for leaders.\ \",count); danceWithMe = (++danceWithMe) % MAX_LEADERS; myPartner = danceWithMe; seatPocket[myPartner] = count; sem_post(&mutex); sem_post(&leaders); sem_wait(&followers); sem_wait(&mutex); //Lock mutex B = seatPocket[myPartner]; //leader replaces follower PID with his own PID numberOfFreeLeaders++; //Stand Up and Go to leader Room sem_post(&mutex); //Release the seat change mutex /*follower is having DANCE with leader \'B\'*/ } pthread_exit(0); } void leaderThread(void *tmp) /*leader Process*/ { int index = *(int *)(tmp); int myNext, C; printf(\"leader-%d[Id:%d]\",index,pthread_self()); while(1) /*Infinite loop*/ { sem_wait(&leaders); sem_wait(&mutex); //Lock mutex to protect seat changes serveMeNext = (++serveMeNext) % MAX_LEADERS; //Select next follower myNext = serveMeNext; C = seatPocket[myNext]; //Get selected follower\'s PID seatPocket[myNext] = pthread_self(); //Leave own PID for follower sem_post(&mutex); sem_post(&followers); //Call selected follower /*leader is Dancing with follower \'C\'*/ printf(\"leader-%d Is Dancing with follower-%d.\ \",index,C); sleep(DANCE_TI.