수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

큐를 이용한 은행시뮬레이션에 질문이요

소심한여자

2023.04.01

질문 제목 : 큐를 이용한 은행 시뮬레이션에 질문이요질문 요약 :은행직원이 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);
}

여기서 추가하고 수정해서 예처럼 나오게 하려는데요 어디를 어떻게 수정하면 예처럼 나오게 할수있는지 좀 알려주세요
그리고 연결큐랑 원형큐랑 구현하는 법도 부탁드릴께요

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

  • 바르고

    네...교재에 있는 소스보고 할려고했는데;;완전새로해야하는군요;;

  • 시내

    아무래도 새로 짜셔야 할거같은데요
    큐에저장해서 순차적으로 나오는게 아니라 바로 반환해서
    전역변수로 계산하는거같은데요 ?

번호 제 목 글쓴이 날짜
2704391 자료 유형에 관련된 문제입니다. (2) 늘솜 2025-08-09
2704365 c언어 문제안되서물어봅니다 (3) 맑은가람 2025-08-09
2704338 다항식의 뺄셈에 대해 질문드립니다... (1) 여자 2025-08-09
2704311 센서를 이용한 라인 주행인데 명령어좀 알려주세요 ㅠ_ㅠ (3) 초록이 2025-08-09
2704284 배열for문;; (3) 은솜 2025-08-08
2704255 readline(int fd, char *buf, int nbytes)함수를 구현하는법좀..ㅠㅠ 파라나 2025-08-08
2704196 간단한 c언어좀 만들어주세요 (2) 슬S2아 2025-08-08
2704118 성적에서 등수 구하기 (4) 딥레드 2025-08-07
2704062 알고리즘 알려주세요 나리 2025-08-06
2704035 답은 나오는데 과정에서 `` 약간 이상합니다.ㅎㅎ 답만나와버려요 핫블랙 2025-08-06
2703979 문자열 EEPROM 작성 방법 문의드립니다. 그녀는귀여웠다 2025-08-06
2703954 키보드를 입력하면 캐릭터를 움직이기 질문 (7) 좋아해 2025-08-05
2703924 계속 에러가... (4) 눈꽃 2025-08-05
2703897 배열의 최댓값과 최솟값 차이 구하기 (1) 하늬 2025-08-05
2703869 C언어 질문입니다 급해용!!! ㅠㅠ (2) 덕이 2025-08-05
2703814 C로 프로그램을 만들때 도스창 말고 다르게 만드는방법이 있을까요? (2) 소심한여자 2025-08-04
2703785 fread로 읽은 bin파일을 구조체로 저장할때 관해서 질문드립니다. (1) 감추어왔던 2025-08-04
2703758 오름차순으로 정렬하는 프로그램인데 잘 안되요.. (2) 해긴 2025-08-04
2703730 Deep copy 질문드립니다 (3) 원술 2025-08-03
2703700 평균 시간복잡도 구하는 방법을 잘모르겟어요 sin 2025-08-03
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com