#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
const int QueueNum=6;//the real Num of the Queue is QueueNum-1
const int ERROR=0;
const int OK=1;
const int QueuePre=-1;
typedef int ElemType;
//head define....................
/*************************CONST DEFINE*****************************************/
//------------------------------------------------------------------------------
//==============================================================================
//==================Define of Class Queue_c=====================================
class Queue_c
{
ElemType Q[QueueNum];
int front,rear;
public:
//basic information of the class Queue_c:
Queue_c();
int qFull();
int qEmpty();
int qEnQueue(ElemType e);
ElemType qDeQueue();
int qGetNumber();
int qGetElem(int);
int qShowQueue();
//other functions:
ElemType qGetFrontElem(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return Q[front];}
//int qGetFront(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return front;}
//ElemType qGetRearElem(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return Q[(rear-1+QueueNum)%QueueNum];}
//int qGetRear(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return (rear-1+QueueNum)%QueueNum;}
//int qShowAll();
/* int qDec()
{
if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}//endif
Q[front]--;
return OK;
}
*/
};
//===============END Define of Class Queue_c=====================================
//==============================================================================
//==============================================================================
//==================Define of Class Work_c======================================
class Work_c
{
Queue_c buf;
public:
int wConsumer();
int wProducer();
int wShowBUF(){return buf.qShowQueue();}
int wInBUF(int i){return buf.qEnQueue(i);}
};
//==================END Define of Class Work_c==================================
//==============================================================================
//-----------------------------------------------------------------------------
/******************************END OF CLASSES DEFINE***************************/
/*******************************==main==****************************************************
********************************==proc==***************************************************/
/*******************************==main==****************************************************
********************************==proc==***************************************************/
void main()
{
Work_c w;
int judge;
w.wInBUF(5);
w.wInBUF(3);
w.wInBUF(1);
clrscr();
char flag='y';
while('n'!=flag)
{
cout<<"------------------work----------------------"<<endl;
//w.buf.qShowQueue();
judge=random(flag)%3;
if(0==judge){w.wProducer();cout<<"prodecer produce a produect"<<endl;}
if(1==judge){w.wConsumer();cout<<"consumer consume a product"<<endl;}
if(2==judge)cout<<"do nothing"<<endl;
#include<stdlib.h>
#include<conio.h>
const int QueueNum=6;//the real Num of the Queue is QueueNum-1
const int ERROR=0;
const int OK=1;
const int QueuePre=-1;
typedef int ElemType;
//head define....................
/*************************CONST DEFINE*****************************************/
//------------------------------------------------------------------------------
//==============================================================================
//==================Define of Class Queue_c=====================================
class Queue_c
{
ElemType Q[QueueNum];
int front,rear;
public:
//basic information of the class Queue_c:
Queue_c();
int qFull();
int qEmpty();
int qEnQueue(ElemType e);
ElemType qDeQueue();
int qGetNumber();
int qGetElem(int);
int qShowQueue();
//other functions:
ElemType qGetFrontElem(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return Q[front];}
//int qGetFront(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return front;}
//ElemType qGetRearElem(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return Q[(rear-1+QueueNum)%QueueNum];}
//int qGetRear(){if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}return (rear-1+QueueNum)%QueueNum;}
//int qShowAll();
/* int qDec()
{
if(qEmpty()){cout<<"ERROR!"<<endl;return ERROR;}//endif
Q[front]--;
return OK;
}
*/
};
//===============END Define of Class Queue_c=====================================
//==============================================================================
//==============================================================================
//==================Define of Class Work_c======================================
class Work_c
{
Queue_c buf;
public:
int wConsumer();
int wProducer();
int wShowBUF(){return buf.qShowQueue();}
int wInBUF(int i){return buf.qEnQueue(i);}
};
//==================END Define of Class Work_c==================================
//==============================================================================
//-----------------------------------------------------------------------------
/******************************END OF CLASSES DEFINE***************************/
/*******************************==main==****************************************************
********************************==proc==***************************************************/
/*******************************==main==****************************************************
********************************==proc==***************************************************/
void main()
{
Work_c w;
int judge;
w.wInBUF(5);
w.wInBUF(3);
w.wInBUF(1);
clrscr();
char flag='y';
while('n'!=flag)
{
cout<<"------------------work----------------------"<<endl;
//w.buf.qShowQueue();
judge=random(flag)%3;
if(0==judge){w.wProducer();cout<<"prodecer produce a produect"<<endl;}
if(1==judge){w.wConsumer();cout<<"consumer consume a product"<<endl;}
if(2==judge)cout<<"do nothing"<<endl;