|
#include <stdlib.h>
class CBarberShop
{
private:
int m_NoWaitingChairs,m_NoCustomers,m_HairCutTime;
const int MAX_CHAIRS;
bool m_BarberStatus,IsRandEven;
public:
CBarberShop():MAX_CHAIRS(5) //Constructor initializing variables
{
m_NoWaitingChairs=5;
m_NoCustomers=0;
m_HairCutTime=0;
m_BarberStatus=false;
}
bool Barber_Status() //returns the barber's status. true=busy; false=free;
{
if(m_BarberStatus == false)
return false;
else
return true;
}
void Wakeup() // if the barber is sleeping customer wakes him up
{
cout << "Barber is sleeping. Wake him up" << endl;
Set_Barber_Status(true);
}
//constantly checks for new customer arriaval. If the random number is even, it triggers
// new customer arrival. if random number is odd, no trigger.
void Check_For_New_Customer()
{
IsRandEven = IsEven(rand());
if(IsRandEven == true)
{
cout << "NEW CUSTOMER ARRIVED" << endl<<endl;
m_NoCustomers++;
m_NoWaitingChairs--;
if(m_NoWaitingChairs < 0)
m_NoWaitingChairs=0;
}
}
//while barber doing haircut. decrease no.of customers and increase waiting chairs.
void Haircut()
{
m_NoCustomers--;
m_NoWaitingChairs++;
}
//gets the current customer and seats info
void Get_Customer_Seat_Status()
{
cout << "No of customers waiting:" << No_Customers() << endl;
cout << "No. of available waiting chairs:" << No_WaitChairs_Available() << endl<<endl;
}
// sets the barber status to true or false depending on the customers.
void Set_Barber_Status(bool status)
{
m_BarberStatus=status;
}
//returns no.of customers at any time
int No_Customers()
{
if(m_NoCustomers > 5)
m_NoCustomers = 5;
return m_NoCustomers;
}
//retuns no. of waiting chairs availalbe at any time
int No_WaitChairs_Available()
{
return m_NoWaitingChairs;
}
bool IsEven(int x)
{
if((x % 2) == 0)
return true;
else
return false;
}
};
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am Ananth Nag Sastry Ganti, working as a software engineer at IBM T.J Watson Research Center, NY. I am working on Image processing and Video suviellence projects. My areas of interests include DSP, Image Processing.
Any advices or suggestions on my articles are always welcome.