A. C#银行排队叫号系统
// 写了一个比较简陋的排队系统,可以参考下:
classProgram{
staticvoidMain(string[]args){
ServiceWindow[]serviceWindows=newServiceWindow[Bank.MAX];
for(inti=0;i<Bank.MAX;i++)
serviceWindows[i]=newServiceWindow(){No=(i+1).ToString()};
Bankbank=newBank(serviceWindows);
Randomrand=newRandom();
//多线程模拟顾客取号
newThread(()=>{
intk=0;
while(true){
Bank.Enqueue();
if(++k>=100)break;
Thread.Sleep(1000);
}
}).Start();
//多线程模拟服务窗口叫号
newThread(()=>{
while(true){
bank.ServiceWindows[rand.Next(0,Bank.MAX)].Call();
Thread.Sleep(3000);
}
}).Start();
Console.ReadKey(true);
}
}
internalclassBank{
publicconstintMAX=3;
publicstaticConcurrentQueue<uint>queue{get;set;}
publicstaticvolatileuintcurNo=0;
publicBank(){
Init();
}
publicvoidInit()
{
queue=newConcurrentQueue<uint>();
}
publicBank(ServiceWindow[]serviceWindows)
{
Init();
ServiceWindows=serviceWindows;
}
publicServiceWindow[]ServiceWindows{get;set;}
publicstaticvoidEnqueue()
{
intk=0;
k=queue.Count();
curNo++;
queue.Enqueue(curNo);
Console.WriteLine("您的号码是:"+(curNo)+",前面还有"+k+"人在等待!");
}
}
internalclassServiceWindow{
publicStringNo{get;set;}
publicboolCall()
{
uintresult=0;
boolsuccess=false;
success=Bank.queue.TryDequeue(outresult);
if(success)Console.WriteLine(result+"号,请到"+No+"号窗口办理业务!");
returnsuccess;
}
}
B. c语言银行排队系统
你所指的队列是线程吗?
线程操作,大概思路如下:
1. 创建4个线程,表示四个窗口,用semaphore来等待客户进入(WaitForSingleObject).
2. 创建n个线程表示客户,每创建一个客户增加一个ReleaseSemaphore,以让窗口处理(记录相关信息,随机时间可以用srand获取),窗口要设定为while循环,可以多次处理,条件可以设置为处理多少个客户就可以退出.
3. 共用资源记得设置临界区CriticalSection.
C. 想做一个c语言程序,,类似银行排队叫号,关于定时器的问题
你应该把自己的需求分解一下
1.如果你的每个窗口都是一个单独线程的话;
除非你用了底层中断,当成窗口从忙碌切到闲置时,发送中断信号。保存现场和函数切换,一般由系统来处理。
2. 如果你不是多线程并行;
那么执行本身在任务应用级别是串行的,你需要做的是,把你操作分解到原子操作,每个原子操作后又一定的状态检测;但是务必高效,比如64个子窗口进程,用一个longlong 64个bit,用位操作比较。切任务保存现场就需要你自己来做了。
D. 银行排队系统叫号,怎么样使各个窗口同时工作,c语言
设置一个标志,工作时置为1 然后while循环检测时间, 到时间了就置为0,然后跳出while循环
调用窗口的时候先检测该窗口的这个状态,如果为1就接着检测下个窗口,直到该窗口状态为0,就为其服务
E. 模拟实现一个银行叫号程序 (c语言)
#include<stdio.h>
main()
{
int n,i;
n=0;
while(1)
{
printf("请输入指令:");
scanf("%d",&i);
if(i==0)
break;
if(i==1)
{
if(n==0)
printf("您前面无人排队,请直接去柜台办理业务\n");
else
printf("您前面还有%d位,请等待\n",n);
n++;
}
if(i==2)
{
if(n>0)
n--;
}
}
}
F. 用C语言编银行叫号系统
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <conio.h>
#define MAX_SIZE 500
struct tagCustom
{
int m_nID; // 客户的编号
int m_nProcessTime; // 需要处理业务的时间
int m_nArrivalTime; // 到达时间
int m_nDepartTime; // 离开时间
};
struct tagTeller
{
int m_nCustomNum; // 处理的客户数
int m_nAllServiceTime; // 所有服务时间
int m_nFinishServiceTime; // 柜台针对一个客户服务的结束时间
bool m_bBusy; // 柜台是否忙
int m_nCustomID; // 正在服务的客户的ID号
};
tagTeller g_aryTellers[MAX_SIZE];
int g_nTellerNum; // 柜台数量
// 用户到达数组(随机的,无序的)
tagCustom g_aryAllCustoms[MAX_SIZE];
int g_nCustomsNum;
int g_nWorkTime; // 经营时间
int g_nArrivalRange,g_nServiceRange;
// 用户队列
tagCustom g_CustomQueue[MAX_SIZE];
int g_nHeader,g_nTail;
// 队列的操作
void InitQueue()
{
g_nHeader = g_nTail = -1;
}
void AddToTail(tagCustom aCustom)
{
g_nTail++;
g_CustomQueue[g_nTail] = aCustom;
}
bool RemoveFromHeader(tagCustom* pCustom)
{
if(g_nHeader < g_nTail)
{
g_nHeader++;
(*pCustom) = g_CustomQueue[g_nHeader];
return true;
}
return false;
}
// 功能:模拟用户的随机到来
void GenerateCustom()
{
tagCustom aCustom;
for(int nCounter = 0; nCounter < g_nCustomsNum; nCounter++)
{
aCustom.m_nID = nCounter;
aCustom.m_nArrivalTime = rand() % g_nWorkTime ;
aCustom.m_nProcessTime = (rand() % g_nServiceRange + 1) * 6;
aCustom.m_nDepartTime = -1;
g_aryAllCustoms[nCounter] = aCustom;
}
}
void Init()
{
g_nTellerNum = 3;
g_nWorkTime = 200;
g_nCustomsNum = 30;
g_nArrivalRange = 18 ;
g_nServiceRange = 5 ;
srand((unsigned)time(NULL));
InitQueue();
GenerateCustom();
for(int nC = 0; nC < g_nTellerNum; nC++)
{
g_aryTellers[nC].m_nAllServiceTime = 0;
g_aryTellers[nC].m_nCustomID = -1;
g_aryTellers[nC].m_bBusy = false;
g_aryTellers[nC].m_nFinishServiceTime = -1;
}
}
G. 用C语言编银行叫号系统
#include
"stdafx.h"
#include
<stdio.h>
#include
<stdlib.h>
#include
<time.h>
#include
<string.h>
#include
<conio.h>
#define
MAX_SIZE
500
struct
tagCustom
{
int
m_nID;
//
客户的编号
int
m_nProcessTime;
//
需要处理业务的时间
int
m_nArrivalTime;
//
到达时间
int
m_nDepartTime;
//
离开时间
};
struct
tagTeller
{
int
m_nCustomNum;
//
处理的客户数
int
m_nAllServiceTime;
//
所有服务时间
int
m_nFinishServiceTime;
//
柜台针对一个客户服务的结束时间
bool
m_bBusy;
//
柜台是否忙
int
m_nCustomID;
//
正在服务的客户的ID号
};
tagTeller
g_aryTellers[MAX_SIZE];
int
g_nTellerNum;
//
柜台数量
//
用户到达数组(随机的,无序的)
tagCustom
g_aryAllCustoms[MAX_SIZE];
int
g_nCustomsNum;
int
g_nWorkTime;
//
经营时间
int
g_nArrivalRange,g_nServiceRange;
//
用户队列
tagCustom
g_CustomQueue[MAX_SIZE];
int
g_nHeader,g_nTail;
//
队列的操作
void
InitQueue()
{
g_nHeader
=
g_nTail
=
-1;
}
void
AddToTail(tagCustom
aCustom)
{
g_nTail++;
g_CustomQueue[g_nTail]
=
aCustom;
}
bool
RemoveFromHeader(tagCustom*
pCustom)
{
if(g_nHeader
<
g_nTail)
{
g_nHeader++;
(*pCustom)
=
g_CustomQueue[g_nHeader];
return
true;
}
return
false;
}
//
功能:模拟用户的随机到来
void
GenerateCustom()
{
tagCustom
aCustom;
for(int
nCounter
=
0;
nCounter
<
g_nCustomsNum;
nCounter++)
{
aCustom.m_nID
=
nCounter;
aCustom.m_nArrivalTime
=
rand()
%
g_nWorkTime
;
aCustom.m_nProcessTime
=
(rand()
%
g_nServiceRange
+
1)
*
6;
aCustom.m_nDepartTime
=
-1;
g_aryAllCustoms[nCounter]
=
aCustom;
}
}
void
Init()
{
g_nTellerNum
=
3;
g_nWorkTime
=
200;
g_nCustomsNum
=
30;
g_nArrivalRange
=
18
;
g_nServiceRange
=
5
;
srand((unsigned)time(NULL));
InitQueue();
GenerateCustom();
for(int
nC
=
0;
nC
<
g_nTellerNum;
nC++)
{
g_aryTellers[nC].m_nAllServiceTime
=
0;
g_aryTellers[nC].m_nCustomID
=
-1;
g_aryTellers[nC].m_bBusy
=
false;
g_aryTellers[nC].m_nFinishServiceTime
=
-1;
}
}
H. 数据结构(C语言版):利用队列结构实现银行叫号系统(要求见图)
这样的一个数据收集系统很简单:
银行的叫号系统可以定义开始时间和结束时间.
开始时间就是你拿号的时间.
结束时间就是你接受到服务的时间.
具体的如何分析和改善控制,需要等你的数据收集完了后来分进行分析,不然白说.
I. C语言问题 急
没考虑输入是否合法(例如客户类型只能为Ordinary和VIP,退出用Quit),
时间关系凑合着用,按正确输入的话能实现
#include "stdio.h"
#include "malloc.h"
#include "string.h"
#define null 0
struct List
{
char guesttype[10];
struct List *next;
}List;
struct List * InitList()
{
struct List *head,*p,*q;
head=(struct List *)malloc(sizeof(struct List));
head->next=null;
q=head;
int i;
bool star=true;
char c,InQuit[10],guest[10];
for (i=0;i<10&&(c=getchar())!='\n';i++)
{
if (c==' ')
{
star=false;
i=-1;
continue;
}
if (star)InQuit[i]=c;
else guest[i]=c;
}
guest[i]='\0';
while(InQuit[0]=='I'&&InQuit[1]=='N')
{
p=(struct List *)malloc(sizeof(struct List));
p->next=null;
strcpy(p->guesttype,guest);
q->next=p;
q=p;
star=true;
for (i=0;i<10&&(c=getchar())!='\n';i++)
{
if (c==' ')
{
star=false;
i=-1;
continue;
}
if (star)InQuit[i]=c;
else guest[i]=c;
}
}
return head;
}
void print(struct List *head)
{
struct List *p;
int num=0;
if(head)
{
p=head->next;
while(p)
{
printf("IN:\n");
printf("%d %s %d\n",num+1,p->guesttype,num);
p=p->next;
num++;
}
printf("GOOD BYE!\n");
}
}
void main()
{
struct List *head;
head=InitList();
print(head);
}
J. C语言考试中 求求各位帮帮忙 谢谢
#include <stdio.h>
#include <stdlib.h>
#define ASK_OP(response) puts("INPUT O = IN Ordinary V = IN VIP Q = QUIT");response = getch();
typedef struct _cus{
int no;
char type;
int type_num;
struct _cus *next;
}customer;
int main(int argc, char *argv[])
{
customer * phead = NULL, *pcur = NULL, *ptail = NULL;
int i,j;
char ch;
ASK_OP(ch);
while(('Q' != ch) && ('q' != ch))
{
if('o' == ch || 'O' == ch)
{
if(NULL == phead)
{
if(NULL == (phead = (customer *)malloc(sizeof(customer))))return ;
phead->no = 1;
phead->type = 'o';
phead->type_num = 0;
phead->next = NULL;
pcur = phead;
}
else
{
i=0; //记录类型为 Ordingary 的个数
ptail = phead;
while(!(NULL == ptail->next))
{
if(ptail->type == 'o') i = ptail->type_num;
ptail = ptail->next;
}
if(ptail->type == 'o') i = ptail->type_num;
if(NULL == (pcur = (customer *)malloc(sizeof(customer)))) return ;
ptail->next = pcur;
pcur->no = ptail->no+1;
pcur->type = 'o';
pcur->type_num = i+1;
pcur->next = NULL;
}
printf("\n%d Ordinary %d 前面有%d人等待\n",pcur->no,pcur->type_num,pcur->no-phead->no);
}
if('v' == ch || 'V' == ch)
{
if(NULL == phead)
{
if(NULL == (phead = (customer *)malloc(sizeof(customer)))) return ;
phead->no = 1;
phead->type = 'v';
phead->type_num = 0;
phead->next = NULL;
pcur = phead;
}
else
{
i=0; //记录类型为 Vip 的个数
ptail = phead;
while(!(NULL == ptail->next))
{
if(ptail->type == 'v') i = ptail->type_num;
ptail = ptail->next;
}
if(ptail->type == 'v') i = ptail->type_num;
if(NULL == (pcur = (customer *)malloc(sizeof(customer)))) return ;
ptail->next = pcur;
pcur->no = ptail->no+1;
pcur->type = 'v';
pcur->type_num = i+1;
pcur->next = NULL;
}
printf("\n%d VIP %d 前面有%d人等待\n",pcur->no,pcur->type_num,pcur->no-phead->no);
}
ASK_OP(ch);
}
printf("\n GOOD bye");
system("PAUSE");
return 0;
}