问题描述
我是编程初学者!我在
大学兼职从事C ++项目。目前,我正在开发一个理发店模拟模型。
目前的模型是 - >每次客户到货时,他都会检查
免费理发师。如果理发师是免费的,他会得到服务。否则他等待队列中的
(所有客户的公共队列)。
理发师完成工作后,他会检查队列是否为空,如果
没有,队列中的第一个客户端由理发师提供服务。
现在我需要更改它如下 - >客户偏好
理发师(我完成了这个)!每个理发师都有HIS SEPARATE队列!
客户检查这个理发师是否免费!如果不是他等待理发师的相应队列
!我想知道如何为每个理发师实施这个
qeueue。我只是粘贴理发师的源代码,
我生成了理发师的数量,并设置了他的椅子
数字,以及客户队列的初始化。 br />
queue< client *>理发:: clientQueue; //这是一个常见的队列
barber :: barber(int numberOfBarbers):currentClient(0),name(0){
for(int i = 1; i< = numberOfBarbers; i ++){
barber * b = dynamic_cast< barber *>(this-> clone());
b- > setChairNumber(i);
barbers.push_back(b);
b-> name = new char [255];
sprintf(b-> name,"%s - %i",this-> getClassName(),i);
}
}
< snip>
我想我会为每个理发师和一个公共队列建立一个队列。每个
客户进入系统时都会得到一个时间戳,不允许任何关系。当
a理发师获得免费时,他会检查领先的竞争者的时间戳
他的私人队列中的主要竞争者的时间戳在共同的
队列。他拿的是最老的时间戳。
< ; snip>
我想我会为每个理发师和一个公共队列排队。每个
客户进入系统时都会得到一个时间戳,不允许任何关系。当一名理发师获得自由时,他会在他的私人队列中检查主要竞争者的时间戳,并在常用队列中检查主要竞争者的时间戳。他会拿最老的时间戳。
这样的第一次切割。汇编。
#include< iostream>
#include< deque>
#include< vector>
//在一个真实的程序中,这将是一个头文件
struct Client
{
int id;
double time_stamp;
};
// -------------- -
typedef std :: deque< Client> QT; //队列类型
//结束标题
使用命名空间std;
int main()
{
vector< QT> VQ; //索引0 - 集体排队,
//每个理发师一个
//东西
}
Hi,
I am a beginner in programming! I work part time on C++ projects in
University. Currently, i am developing a barber shop simulation model.
The current model is--> Each time when the client arrives, he checks
for a free barber. if a barber is free, he is serviced. Else he waits
in a queue (Common queue for all clients).
After barber is done with his work, he checks if the queue is empty, if
not, the 1st client in the queue is served by the barber.
Now i need to change it as follows--> The client has a preference for
barber ( i am done with this)! and each barber has HIS SEPARATE queue!
the client checks if this barber is free! if not he waits in the
corresponding queue of the barber! I wish to know how to implement this
qeueue for each barber. I am just pasting the source code of barber,
where i have generated the number of barbers and has set his chair
number, and also the intialisation of the clientqueue.
queue<client*> barber::clientQueue; // this is a common queue
barber::barber( int numberOfBarbers ) : currentClient( 0 ), name( 0 ) {
for( int i = 1; i <= numberOfBarbers; i++ ) {
barber* b = dynamic_cast<barber*>( this->clone( ) );
b->setChairNumber( i );
barbers.push_back( b );
b->name = new char[255];
sprintf( b->name, "%s - %i", this->getClassName( ), i );
}
}
<snip>
I guess I would make a queue for each barber and also a common queue. Each
client gets a time stamp when he enters the system, no ties permitted. When
a barber becomes free he checks the time stamp of the leading contender in
his private queue with the time stamp of the leading contender in the common
queue. He takes whoever has the oldest time stamp.
<snip>
I guess I would make a queue for each barber and also a common queue. Each
client gets a time stamp when he enters the system, no ties permitted. When
a barber becomes free he checks the time stamp of the leading contender in
his private queue with the time stamp of the leading contender in the common
queue. He takes whoever has the oldest time stamp.
Something like this for a first cut. It compiles.
#include <iostream>
#include <deque>
#include <vector>
// in a real program, this would be in a header file
struct Client
{
int id;
double time_stamp;
};
//----------------
typedef std::deque<Client> QT; // queue type
// end header
using namespace std;
int main()
{
vector<QT> vq; // index 0 - collective queue,
// else one for each barber
// stuff
}
这篇关于理发店模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!