큐를 이용한 은행시뮬레이션에 질문이요
소심한여자
질문 제목 : 큐를 이용한 은행 시뮬레이션에 질문이요질문 요약 :은행직원이 2인일때
질문 내용 :아래처럼 되도록 프로그램하라는데 어떻게 해야하는지 가닥좀 잡아주세요;;1명일때 소스는
#include stdlib.h
#include stdio.h
#include math.h
#define TRUE 1
#define FALSE 0
#define MAX_QUEUE_SIZE 100
typedef struct {
int id;
int arrival_time;
int service_time;
} element;
typedef struct {
element queue[MAX_QUEUE_SIZE];
int front, rear;
} QueueType;
QueueType queue;
//
void error(char *message)
{
fprintf(stderr,%s\n,message);
exit(1);
}
void init(QueueType *q)
{
q-front = q-rear = 0;
}
int is_empty(QueueType *q)
{
return (q-front == q-rear);
}
int is_full(QueueType *q)
{
return((q-rear+1)%MAX_QUEUE_SIZE == q-front);
}
//삽입함수
void enqueue(QueueType *q, element item)
{
q-queue[q-rear] = item;
q-rear++;
}
//삭제함수
element dequeue(QueueType *q)
{
return q-queue[q-front++];
}
//삭제함수
element peek(QueueType *q)
{
return q-queue[q-front++];
}
double random()
{
return rand()/(double)RAND_MAX;
}
int durattion;
double arrival_prob=0.7;
int max_serv_time=5;
int clock;
int customers;
int served_customers;
int waited_time;
int is_customer_arrived()
{
if(random() arrival_prob)
return TRUE;
else return FALSE;
}
void insert_customer(int arrival_time)
{
element customer;
customer.id = ++customers;
customer.arrival_time = arrival_time;
customer.service_time=(int)(max_serv_time*random()) + 1;
enqueue(&queue, customer);
printf(고객 %d이 %d분에 들어옵니다.서비스시간은 %d분입니다.\n,customer.id, customer.arrival_time,customer.service_time);
}
int remove_customer()
{
element customer;
int service_time=0;
if (is_empty(&queue)) return 0;
customer = dequeue(&queue);
service_time = customer.service_time-1;
served_customers++;
waited_time += clock - customer.arrival_time;
printf(고객 %d이 %d분에 서비스를 시작합니다.대기시간은 %d분이었습니다.\n,
customer.id, clock,
clock - customer.arrival_time);
return service_time;
}
void print_stat()
{
printf(서비스받은 고객수 = %d\n, served_customers);
printf(전체 대기 시간 = %d분\n, waited_time);
printf(1인당 평균 대기 시간 = %f분\n,(double)waited_time/served_customers);
printf(아직 대기중인 고객수 = %d\n,customers-served_customers);
}
int main()
{
int service_time=0;
printf(처리시간을 입력해주세요 (단위는 분): );
scanf(\n%d, &durattion);
clock=0;
while(clock durattion){
clock++;
printf(현재시각=%d\n,clock);
if (is_customer_arrived()) {
insert_customer(clock);
}
if (service_time 0)
service_time--;
else {
service_time = remove_customer();
}
}
print_stat();
system(pause);
}
여기서 추가하고 수정해서 예처럼 나오게 하려는데요 어디를 어떻게 수정하면 예처럼 나오게 할수있는지 좀 알려주세요
그리고 연결큐랑 원형큐랑 구현하는 법도 부탁드릴께요
-
바르고
네...교재에 있는 소스보고 할려고했는데;;완전새로해야하는군요;;
-
시내
아무래도 새로 짜셔야 할거같은데요
큐에저장해서 순차적으로 나오는게 아니라 바로 반환해서
전역변수로 계산하는거같은데요 ?
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2655440 | test파일이 안 되요. (2) | 리라 | 2024-05-19 |
2655416 | 고수님들 도움이 절실합니다. (2) | 세리 | 2024-05-19 |
2655361 | 엔터 입력받을때까지 기다리는 getchar (1) | 큰모음 | 2024-05-19 |
2655328 | 함수에서 포인터 (3) | 모아 | 2024-05-18 |
2655299 | 아이콘바꾸는법..? | 소 | 2024-05-18 |
2655271 | scanf 입력받으면 쭉 실행되는.. (5) | ComeOn | 2024-05-18 |
2655184 | 이 세개 프로그램좀 해결해주실.... 고수님들???? (3) | 말달리자 | 2024-05-17 |
2655129 | 다차원 배열 원소들 주소계산하는거 질문이요~ | 터전 | 2024-05-17 |
2655103 | AVRstudio MoveAxis. MoveLine 함수질문 | 앨버트 | 2024-05-16 |
2655072 | 콘솔창의 위치와 크기를 정하고 싶습니다. | 딥레드 | 2024-05-16 |
2655044 | 자료구조랑 online judge site에 대해서 질문있습니다... (1) | 뽀송뽀송 | 2024-05-16 |
2655016 | 별찍기 문제 중 이해안되는 부분이 있어요... | 도전중 | 2024-05-16 |
2654986 | 입력받은 성적을 배열에 저장하기 (3) | 안녕나야 | 2024-05-15 |
2654959 | ===========-이런거 미리 지정하는법 (1) | 김자영 | 2024-05-15 |
2654930 | 도와주십시요 ㅜㅜ 자료구조 ㅜㅜ | 도널드 | 2024-05-15 |
2654881 | PID 모듈 검색 부분 질문합니다 . | 이름없음 | 2024-05-14 |
2654850 | 조건에 만족하는 다음 수를 찾고 싶습니다. | 초엘 | 2024-05-14 |
2654790 | 두파일간 byte단위 txt파일 복사 中 | 슬찬 | 2024-05-14 |
2654768 | 사전만들기 입니다. | 여우By | 2024-05-13 |
2654716 | c언어 고수님들 답좀적어주세요 급합니다 ㅠㅠ | 한말글 | 2024-05-13 |