수다닷컴

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

왜 오류가..나는건지..도통모르겠어요

작약

2023.04.01

질문 제목 : 왜 오류가..나는건지..도통모르겠어요제가 자료구조에 있는 은행서비스 시물레이션 프로그램을 돌리던 도중 난 오류질문 내용 : 자료구조에 있는 책을 보며 과제를 하려던도중..

대기시간이 3분 미만이 될수 있게(입장인원 렌덤, 시간은 2시간) 테이블의 갯수를 구하는 문제입니다. 2인용..각 대기시간, 서비스시간등 그리고 총 몇명 평균대기시간등등을 알아와야하는 과제 입니다..

그래서 마침 자료구조 책 중간쯤 은행서비스시뮬레이션 프로그램이 있는데..생략된 부분 채워넣고 돌렸는데..

오료가 17개나 떴습니다..분명 맞는거 같은데..아무리 봐도 뭐가 뭔지 모르겠..초보인지라..

참고로 6++ 프로그램 사용합니다^^아 그리고 죄송하지만 조언좀 부탁드릴께요 ㅠ

제가 해야할 문제를 해결하려면 대기시간을 3분 미만..입장인원이 렌덤이며 시간은 2시간동안 이루어집니다. 2인용테이블이 몇개가 있어야 대기시간이 3분미만이 될수 있을까요? 라는 문제인데..조언좀 부탁드려요..아하하.ㅜ

include stdio.h
#include stdlib.h
#include math.h
#define true 1
#define false 0
#define max_queue_size 100
typedef struct
{
int id;
int arrival_time;
int servise_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)
{
if(is_full(q))
error(큐가 포화상태입니다.);
q-rear = (q-rear+1) %max_queue_size;
q-queue[q-rear] = item;
}
element dequeue(queuetype *q)
{
if(is_empty(q))
error(큐가 공백상태입니다.);
q-front = (q-front+1)%max_queue_size;
return q-queue[q-front];
}
element peek(queuetype *q)
{
if(is_empty(q))
error(큐가 공백상태입니다);
return q-queue[(q-front+1)%max_queue_size];
}
double random()
{
return rand()/(double)rand_max;
}
int duration = 10;
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.servise_time = (int)(max_serv_time*random()) +1;
enqueue(&queue, customer);
printf(고객 %d이 %d분에 들어옵니다. 서비스시간은 %d분입니다\n,customer.id,customer.arrival_time,customer.servise_time);
}
int remove_customer()
{
element customer;
int service_time=0;
if(is_empty(&queue)) return 0;
customer = dequeue(&queue);
service_time = customer.servise_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;
}
/* print_stat()
{
printf(서비스받는 고객수 = %d\n, served_customers);
printf(전체 대기 시간 =%d분\n, waited_time);
printf(평균 대기 시간 = %f분 \n,(double)waited_time/served_customers);
printf(아직 대기 중인 고객수 = %d\n, customers-served_customers);
}*/
void main()
{
int service_time = 0;
clock = 0;
while(clock duration)
{
clock++;
printf(현재 시각 =%d\n, clock);
if(is_customer_arrived())
{
insert_customer(clock);
}
if (service_time 0)
service_time--;
else
{
service_time = remove_customer();
}
}

printf(서비스받는 고객수 = %d\n, served_customers);
printf(전체 대기 시간 =%d분\n, waited_time);
printf(평균 대기 시간 = %f분 \n,(double)waited_time/served_customers);
printf(아직 대기 중인 고객수 = %d\n, customers-served_customers);
}

#include stdio.h
#include stdlib.h
#include math.h
#define true 1
#define false 0
#define max_queue_size 100
typedef struct
{
int id;
int arrival_time;
int servise_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)
{
if(is_full(q))full(q))
error(큐가 포화상태입니다.);
q-rear = (q-rear+1) %max_queue_size;
q-queue[q-rear] = item;
}
element dequeue(queuetype *q)
{
if(is_empty(q))
error(큐가 공백상태입니다.);
q-front = (q-front+1)%max_queue_size;
return q-queue[q-front];
}
element peek(queuetype *q)
{
if(is_empty(q))
error(큐가 공백상태입니다);
return q-queue[(q-front+1)%max_queue_size];
}
double random()
{
return rand()/(double)rand_max;
}
int duration = 10;
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.servise_time = (int)(max_serv_time*random()) +1;
enqueue(&queue, customer);
printf(고객 %d이 %d분에 들어옵니다. 서비스시간은 %d분입니다\n,customer.id,customer.arrival_time,customer.servise_time);
}
int remove_customer()
{
element customer;
int service_time=0;
if(is_empty(&queue)) return 0;
customer = dequeue(&queue);
service_time = customer.servise_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;
}
/* print_stat()
{
printf(서비스받는 고객수 = %d\n, served_customers);
printf(전체 대기 시간 =%d분\n, waited_time);
printf(평균 대기 시간 = %f분 \n,(double)waited_time/served_customers);
printf(아직 대기 중인 고객수 = %d\n, customers-served_customers);
}*/
void main()
{
int service_time = 0;
clock = 0;
while(clock duration)
{
clock++;
printf(현재 시각 =%d\n, clock);
if(is_customer_arrived())
{
insert_customer(clock);
}
if (service_time 0)
service_time--;
else
{
service_time = remove_customer();
}
}

printf(서비스받는 고객수 = %d\n, served_customers);
printf(전체 대기 시간 =%d분\n, waited_time);
printf(평균 대기 시간 = %f분 \n,(double)waited_time/served_customers);
printf(아직 대기 중인 고객수 = %d\n, customers-served_customers);
}

신청하기





COMMENT

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

번호 제 목 글쓴이 날짜
2700150 꼭좀 도와주세요ㅠㅠㅠ 호습다 2025-07-02
2700095 연산문제...질문... 오빤테앵겨 2025-07-01
2700070 while문 , 3의배수 출력하는 프로그램좀 짜주세욤. 횃불 2025-07-01
2700041 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? 헛장사 2025-07-01
2700012 배열// (1) 전갈자리 2025-07-01
2699895 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) 선아 2025-06-30
2699842 질문을 너무 많이 하네여.....죄송.... (2) 해님꽃 2025-06-29
2699816 오류 질문입니다.. (1) 해비치 2025-06-29
2699763 질문입니다 ! 꼭 좀 도와주세요ㅠㅠ (2) 미라 2025-06-28
2699555 c언어 다항식을 입력을 했는데 왜 출력이 안될까요? 피스케스 2025-06-27
2699528 C언어 포인터연산 질문입니다. (3) 안녕나야 2025-06-26
2699476 끌어올림;;달력 짜봤는데요 이 소스 줄일 수 있나요? - 스샷첨부 (2) 클라우드 2025-06-26
2699444 [좀 급함] system("explorer [주소] ") 문에 변수를 사용할 수 있나요? 알 2025-06-26
2699415 파일//read//와 배열 아란 2025-06-25
2699386 구조체 안에 일부분만 char 배열에 복사하려면 어떻게 해야하나요? (1) 미즈 2025-06-25
2699361 연결리스트 정렬하는 부분에 대해서 질문 드립니다 아이처럼 2025-06-25
2699304 [기초]아직 안주무시는분 계신가요..?포인터배열? 좀 도와주세요. 놀리기 2025-06-24
2699272 printf() 함수이용해서 프로그램 만들기 질문요! (5) 다가 2025-06-24
2699221 PUSH와 POP코드를 더 간단하게 어떻게 해야할까요? 파라미 2025-06-24
2699192 설치오류가 자꾸 나요 한번봐주세여~ (1) 소녀틳향기 2025-06-23
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

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