| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3803 人关注过本帖
标题:[求助]急求理发店模型程序
只看楼主 加入收藏
skyler
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-11-22
收藏
 问题点数:0 回复次数:10 
[求助]急求理发店模型程序

题目内容:使用队列模拟理发馆的排队现象,通过仿真手法评估其营业状况。
基本要求:设某理发店有N把理发椅和M个烫发机,可同时为N位顾客理发或洗发和M个顾客烫发。理发服务分为三个等级(洗头 理发 烫发),对应不同收费,当顾客进门时,若有相应服务类型有空椅,则可立即坐下理发,否则需依次排队等候。一旦有顾客服务完离去时,排在队头的顾客便可开始受理服务。若此顾客服务时间超过关闭时间则放弃此服务。
若理发店每天连续营业T小时,要求输出一天内平均顾客数.平均收入.顾客在理发馆内平均的逗留时间、顾客排队等候理发的队列的平均长度。

测试数据:理发椅数N和烫发机M由用户读入,第一个顾客进门的时刻为0,之后每个顾客进门的时刻由前一个顾客进门时间确定。即在进门事件发生时即产生两个随机数(durtime,intertime),durtime为进门顾客理发所需要的服务时间(即服务类型:洗发:20分钟,5元;理发:40分钟,10元;烫发:1小时,40元),intertime为下一个顾客将到达的时间间隔(下一个随机数产生时间)。R为由随机发生器产生的随机数,顾客理发时间和顾客之间的间隔时间不妨设与R有关

durtime=1+R%3

intertime=2+R%10

这里设早上9点开业,下午5点关门





哪位高人能帮帮忙啊,在下感激不尽!!

我的邮箱360204883@qq.com

[此贴子已经被作者于2005-11-22 17:24:28编辑过]

搜索更多相关主题的帖子: 理发店 模型 
2005-11-22 16:20
EVENMOON
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-11-22
收藏
得分:0 

我也要阿
急用
谢谢好心的高手
evenmoon@163.com

2005-11-22 16:53
热情依然
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:715
专家分:0
注 册:2005-4-5
收藏
得分:0 

问题是你要c++还是c语言


c++/C + 汇编 = 天下无敌
2005-11-22 20:11
skyler
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-11-22
收藏
得分:0 
以下是引用热情依然在2005-11-22 20:11:00的发言:

问题是你要c++还是c语言

2005-11-22 22:45
skyler
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-11-22
收藏
得分:0 
C++和C都可以
2005-11-22 22:46
热情依然
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:715
专家分:0
注 册:2005-4-5
收藏
得分:0 

写得差不多了


c++/C + 汇编 = 天下无敌
2005-11-23 08:31
skyler
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-11-22
收藏
得分:0 
+U+U

先谢谢了
2005-11-23 12:26
热情依然
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:715
专家分:0
注 册:2005-4-5
收藏
得分:0 

我的qq是269312185,差不多好了,这条程序的复杂程度远远超出我的想象
变态的题目.


c++/C + 汇编 = 天下无敌
2005-11-23 17:29
skyler
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-11-22
收藏
得分:0 
辛苦辛苦
2005-11-23 18:05
热情依然
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:715
专家分:0
注 册:2005-4-5
收藏
得分:0 

#include<iostream>
#include<queue> //标准队列
#include<time.h>
#include<fstream>
using namespace std;

struct hair_cut_seat//理发或着洗头位置
{
int flag; //标记,表示这个位置有没有人
int times;//客人所选择的服务所需要的时间
int price;
int number;//第几个服务
int begin_time;//入门时间
int count;//第几号客人
};

struct marcel_seat//烫发位置
{
int flag;
int times;
int price;
int begin_time;//入门时间
int count;
};

struct Time //这个是为了储存 20,5,40,10,60,40
{
int times;
int price;
};

struct arriver//用来储存等待中客人的消息
{
int arriver_time;//到达时间
int times;//接受服务时间
int number;
int count;
};

class hair_cut_shop//理发店类
{
public:
hair_cut_shop(int n,int m);//初试化
~hair_cut_shop();
float stay_time(); //平均顾客逗留时间
int average_queue_long();//平均等待队列长度
void action();//开始进行操作;
void display(ostream & out);

private:
int h_c_s_count;//理发或者洗头位置的个数
int m_s_count;//烫发位置的个数
const int end_time;
int sum_time;//用来记录等待的客人所要的服务的时间总和
float que_long;//队列长度
int que_change;//队列改变长度的次数
int sum_cousterm,sum_intertime;//总共客人数,总共赚钱数,总共间隔时间
float sum_earn;//总共赚的钱
hair_cut_seat *h_c_s_array;
marcel_seat *m_s_array;
Time *t_array;
};


hair_cut_shop::hair_cut_shop(int n,int m):h_c_s_count(n),m_s_count(m),end_time(8*60)
{
h_c_s_array = new hair_cut_seat[h_c_s_count];
m_s_array = new marcel_seat[m_s_count];
t_array = new Time[3];
int i;

for(i=0;i<n;i++)
{
h_c_s_array[i].flag=0;//初始化空位置
h_c_s_array[i].times = 0;
h_c_s_array[i].count = 0;
h_c_s_array[i].number = -1;
}

for(i=0;i<m;i++)
{
m_s_array[i].flag=0;
m_s_array[i].times=0;
m_s_array[i].count = 0;
}

t_array[0].times = 20;//0号是洗头,1号是理发,3号是烫发
t_array[0].price = 5;
t_array[1].times = 40;
t_array[1].price = 10;
t_array[2].times = 60;
t_array[2].price = 40;

sum_cousterm=0;
sum_earn=0;
sum_intertime=0;
que_long = 0;
que_change = 0;
sum_time = 0;

}


hair_cut_shop::~hair_cut_shop()
{
delete [] h_c_s_array;
delete [] m_s_array;
delete [] t_array;
}

void hair_cut_shop::action()
{

int durtime=-1,intertime=-1;
int j;//获得理发或者洗头位置的下标
int z;//获得烫发位置的下标
arriver a;//用来储存等待客人的资料
queue<arriver> w_c_que;//等待理发跟洗头队列
queue<arriver> m_que;
queue<arriver> tem_que;//辅助队列
int flag=1;//判断是否第一个客人,为0的时候就表示不是第一个客人;
int copy_end_time = end_time;
int insert_flag=1;

int c_flag=0;//用来判断是否接受服务
int count=1;
int min;//用来计算最剩下的最小时间
vector<int> temp_c_h;//用来记录理洗发区的工作时间
vector<int> temp_m; //用来记录烫发区的工作时间
vector<int> tem_w_c_que;

cout<<"还有 "<<copy_end_time<<" 分就关门了"<<endl;

while(copy_end_time>0)//外循环,用来计算还有多少分钟
{

if(flag==0 && insert_flag == 1)//这个是用来判断空隙
{
count++;
srand((unsigned)time( NULL ));
intertime = 2+rand()%10;
cout<<"下一次客人来的时间是:"<<intertime<<endl<<endl;
insert_flag=0;
}

if(intertime==0||flag==1)
{
cout<<"有客人"<< count<<" 到来"<<endl;
insert_flag = 1;
flag=0;
srand((unsigned)time( NULL ));
const int i =rand()%3;
durtime = t_array[i].times;

if(i==0||i==1)
{ //做一系列的初始化工作

tem_w_c_que.clear();

while(!w_c_que.empty())
{
tem_que.push(w_c_que.front());
tem_w_c_que.push_back(w_c_que.front().times);
w_c_que.pop();
}

while(!tem_que.empty())
{
w_c_que.push(tem_que.front());
tem_que.pop();
}

if(i==0)
cout<<"客人"<<count<<"选择的是洗头"<<endl;
else if(i==1)
cout<<"客人"<<count<<"选择的是理发"<<endl;

if(w_c_que.empty())
{
min = 0;
for(int index2 = 1; index2< h_c_s_count;index2++)
if(h_c_s_array[min].times > h_c_s_array[index2].times)
min = index2;



if(h_c_s_array[min].times+durtime>copy_end_time)
{
c_flag = 1;
if(i==0)
cout<<"时间不够,不能接受洗发服务"<<endl<<endl;
else if(i==1)
cout<<"时间不够,不能接受理发服务"<<endl<<endl;
}
}//if
else{

temp_c_h.clear();
for(int index = 0;index<h_c_s_count; index++)
temp_c_h.push_back(h_c_s_array[index].times);

int count_tem_w_c_que = 0;

for(int index1 = 0;index1<w_c_que.size();index1++)//预计理洗发混合队列中的人要完成服务的最少时间
{
min = 0;
for(int index2 = 1; index2< h_c_s_count;index2++)
if(temp_c_h[min] > temp_c_h[index2] )
min = index2;
temp_c_h[min] += tem_w_c_que[count_tem_w_c_que++];
}

min = 0;
for(int index2 = 1; index2< h_c_s_count;index2++)
if(temp_c_h[min] > temp_c_h[index2] )
min = index2;



if(temp_c_h[min]+durtime > copy_end_time)
{
c_flag = 1;
if(i==0)
cout<<"时间不够,不能接受洗发服务"<<endl<<endl;
else if(i==1)
cout<<"时间不够,不能接受理发服务"<<endl<<endl;
}


}//else
}//if


else if(i==2)//用来判断是否接受服务
{
//做一系列的初始化工作

tem_w_c_que.clear();

while(!m_que.empty())
{
tem_que.push(m_que.front());
tem_w_c_que.push_back(m_que.front().times);
m_que.pop();
}

while(!tem_que.empty())
{
m_que.push(tem_que.front());
tem_que.pop();
}

cout<<"客人"<<count<<"选择的是烫发"<<endl;

if(m_que.empty())
{
min = 0;
for(int index2 = 1; index2< m_s_count;index2++)
if(m_s_array[min].times > m_s_array[index2].times)
min = index2;


if(m_s_array[min].times+durtime>copy_end_time)
{
c_flag = 1;
cout<<"时间不够,不能接受烫发服务"<<endl<<endl;
}
}//if
else
{
temp_m.clear();
for(int index = 0;index<m_s_count; index++)
temp_m[index] = m_s_array[index].times;

int count_tem_w_c_que = 0;

for(int index1 = 0;index1<m_que.size();index1++)//预计烫发队列中的人要完成服务的最少时间
{
min = 0;
for(int index2 = 1; index2< m_s_count;index2++)
if(temp_m[min] > temp_m[index2])
min = index2;
temp_m[min] += tem_w_c_que[count_tem_w_c_que++];
}

min = 0;
for(int index2 = 1; index2< m_s_count;index2++)
if(temp_m[min] > temp_m[index2])
min = index2;


if(temp_m[min]+durtime > copy_end_time)
{
c_flag = 1;
cout<<"时间不够,不能接受烫发服务"<<endl<<endl;
}


}//else

}//else_if

if(c_flag==0)
{
if(i==0 || i==1)
{
j=0;
while(j<h_c_s_count)
{
if(h_c_s_array[j].flag == 0)
{
cout<<"客人"<<count<<"坐的是 "<<j<<"号理发或者洗发位置"<<endl;
h_c_s_array[j].begin_time = copy_end_time;
h_c_s_array[j].flag=1;
h_c_s_array[j].times = durtime;
h_c_s_array[j].price = t_array[i].price;
h_c_s_array[j].number = i;
h_c_s_array[j].count = count;
break;
}
j++;
}
if(j==h_c_s_count)
{
cout<<"理发或洗发位置满了,请等一等"<<endl;
a.arriver_time = copy_end_time;
a.times = durtime;
a.number = i;
a.count = count;
w_c_que.push(a);
que_long += w_c_que.size();
que_change++;
}
}//if
else if(i==2)
{
z=0;
while(z<m_s_count)
{
if(m_s_array[z].flag == 0)
{
cout<<"客人坐的是 "<<z<<"号烫发位置"<<endl;
m_s_array[z].flag = 1;
m_s_array[z].begin_time = copy_end_time;
m_s_array[z].times = durtime;
m_s_array[z].count = count;
m_s_array[z].price = t_array[i].price;
break;
}
z++;
}
if(z == m_s_count)
{
cout<<"烫发位置满了,请等一等"<<endl;
a.arriver_time = copy_end_time;
a.times = durtime;
a.count = count;
a.number = i;
m_que.push(a);
que_long += m_que.size();
que_change++;
}
}//else if
}//if
c_flag=0;
}//if
for(int index = 0;index<h_c_s_count;index++)
{
if(h_c_s_array[index].flag==1 && h_c_s_array[index].times>0)
{
--h_c_s_array[index].times;
if(h_c_s_array[index].times == 0)
{
sum_cousterm++;
if(h_c_s_array[index].number == 0)
{
cout<<"座位号"<<index <<"的客人"<<h_c_s_array[index].count<<"的洗发服务完成了"<<endl;
cout<<"这个客人逗留了"<<h_c_s_array[index].begin_time - copy_end_time+1<<"分"<<endl;
h_c_s_array[index].number = -1;
sum_time += h_c_s_array[index].begin_time - copy_end_time+1;
}

else if(h_c_s_array[index].number == 1)
{
cout<<"座位号"<<index <<"的客人"<<h_c_s_array[index].count<<"的理发服务完成了"<<endl;
cout<<"这个客人逗留了"<<h_c_s_array[index].begin_time - copy_end_time+1<<"分"<<endl;
h_c_s_array[index].number = -1;
sum_time += h_c_s_array[index].begin_time - copy_end_time+1;
}

cout<<"总共完成 "<<sum_cousterm<<" 客人的服务"<<endl;
h_c_s_array[index].count = 0;
sum_earn += h_c_s_array[index].price;
cout<<"总共赚了:"<<sum_earn<<endl;
h_c_s_array[index].flag = 0;
h_c_s_array[index].times=0;
cout<<"理发或者洗发"<<index<<"号位置空了"<<endl;

if(!w_c_que.empty())
{
if(w_c_que.front().number == 0)
{
cout<<"等待洗发队列中的客人 "<<w_c_que.front().count<<" 号去 "<<index<<" 号理发或者洗发位置开始接受洗发服务"<<endl;
h_c_s_array[index].flag=1;
h_c_s_array[index].begin_time = w_c_que.front().arriver_time;
h_c_s_array[index].times = w_c_que.front().times;
h_c_s_array[index].price = 5;
h_c_s_array[index].number = w_c_que.front().number;
h_c_s_array[index].count = w_c_que.front().count;
w_c_que.pop();
que_long += w_c_que.size();
que_change++;
}
else if(w_c_que.front().number == 1)
{
cout<<"等待理发队列中的客人"<<w_c_que.front().count<<" 号去 "<<index<<" 号理发或者洗发位置开始接受理发服务"<<endl;
h_c_s_array[index].flag=1;
h_c_s_array[index].begin_time = w_c_que.front().arriver_time;
h_c_s_array[index].times = w_c_que.front().times;
h_c_s_array[index].price = 10;
h_c_s_array[index].number = w_c_que.front().number;
h_c_s_array[index].count = w_c_que.front().count;
w_c_que.pop();
que_long += w_c_que.size();
que_change++;
}
}//if
}//if
}//if
}//for

for(index = 0;index<m_s_count;index++)
{
if(m_s_array[index].flag==1 && m_s_array[index].times>0)
{
--m_s_array[index].times ;
if(m_s_array[index].times == 0)
{
cout<<"座位号"<<index <<"的客人"<<m_s_array[index].count<<" 烫发服务完成了"<<endl;
cout<<"这个客人逗留了"<<m_s_array[index].begin_time - copy_end_time+1<<"分"<<endl;
sum_cousterm++;
cout<<"总共完成 "<<sum_cousterm<<" 客人的服务"<<endl;
sum_earn += m_s_array[index].price;
cout<<"总共赚了:"<<sum_earn<<endl;
m_s_array[index].flag = 0;
m_s_array[index].times = 0;
m_s_array[index].count = count;
sum_time += m_s_array[index].begin_time - copy_end_time+1;
if(!m_que.empty())
{
cout<<"等待烫发的客人"<<m_que.front().count<<"开始去"<<index<<"号烫发位置接受服务"<<endl;
m_s_array[index].flag=1;
m_s_array[index].times = m_que.front().times;
m_s_array[index].price = 40;
m_s_array[index].begin_time = m_que.front().arriver_time;
m_s_array[index].count = m_que.front().count;
m_que.pop();
que_long += m_que.size();
que_change++;
}
}
}
}
copy_end_time--;
cout<<"还有 "<<copy_end_time<<" 分就关门了"<<endl;
cout<<endl;
for(int t = 0;t <50000000;t++);
if(flag==0&&intertime>0)
intertime--;
}//while
}


int hair_cut_shop::average_queue_long()
{
return static_cast<int>(que_long / que_change);
}

float hair_cut_shop::stay_time()
{
return static_cast<float>(sum_time/sum_cousterm);
}

void hair_cut_shop::display(ostream &out)
{
out<<"总共赚 "<<sum_earn<<"元"<<endl;
out<<"平均队列长度是:"<<average_queue_long()<<endl;
out<<"顾客平均逗留时间:"<<stay_time()<<endl;
}


void main()
{
int m,n;
cout<<"请输入理发位置的个数"<<endl;
cin>>m;
cout<<"请输入烫发位置的个数"<<endl;
cin>>n;

cout<<endl;

hair_cut_shop h(m,n);
h.action();
cout<<"过程输出到文本里,是D盘的"<<endl;
h.display(cout);
}


c++/C + 汇编 = 天下无敌
2005-11-24 21:09
快速回复:[求助]急求理发店模型程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017452 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved