In C++. This program should not be terminated or crashed (terminate abnormally) while processing invalid data types. It should continue to prompt the user to input the correct data type.
A barbershop consists of a waiting room with n chairs and a barber room with one barber chair. If there are no customers to be served, the barber goes to sleep. If a customer enters the barbershop and all chairs are occupied, then the customer leaves the shop. If the barber is busy but chairs are available, then the customer sits in one of the free chairs. If the barber is asleep, the customer wakes up the barber.
C++:
// Header files
#include <iostream>
#include <cstdio>
#include<bits/stdc++.h>
using namespace std;
// Main function
int main() {
int n; // n = number of chairs.
cin>>n;
int customer=0; // number of customers in the shop.
int choice=1; // choice to terminate the loop.
while(choice) // loop
{
// what we are doing initially number of customers are zero so barber is sleeping.First customer wakes up the barber.if no chair is empty customer leaves the shop and exit the program.and press 0 for stop the program manually.
if(customer==0)
{
cout<<"barber is sleeping.\n";
cout<<"customer wakes up the barber.\n";
customer+=1;
}
else if(customer!=n)
{
cout<<"Customer sits in one of the vacant chair.\n";
customer+=1;
}
else{
cout<<"no chair is empty so customer leaves the shop and program is terminated.\n";
break;
}
cout<<"Press 0 for exit.\n";
cin>>choice;
}
return 0;
}
In C++. This program should not be terminated or crashed (terminate abnormally) while processing invalid data...
i need the code in C please ,,,, POSIX Synchronization In the Sleeping-Barber problem, a barbershop consists of a waiting room with n chairs and one barber chair. If there are no customers to be served, the barber goes to sleep. If a customer enters the barbershop and the barber is asleep, the customer wakes up the barber. If the barber is busy but chairs are available, then the customer sits in FCFS free chairs. If all chairs are occupied,...