main.cpp

来自「购物商场中模拟排队的程序」· C++ 代码 · 共 55 行

CPP
55
字号
//   By Jenhsun Lo (Andy)
//
//   simulate a store shop problem.
//   image that we have three service . But only has two lines (queue)
//   4 people go into two queue per minute. and the third service will check which line is
//   the longest one.And then get one person out of that queue into the 3rd server. 


#include "implement.cpp"

#define M 2   //2 Queue
#define N 4   //4 persons per minute


void main()
{ 	
	char ans;

    do{
	int each1=0,each2=0,each3=0,total1=0,total2=0,rest1=0,rest2=0,minute=0,times;
	float average=0;
	Q queues[M];

	initQueue(queues);  //Inital two Queues
	srand(time(NULL));
	
	printf("Please input number of minutes to simulate=>");  //Input # minutes
	scanf("%d",&times);

	for(int j=0;j<times;j++)

	{
        printf("\nThe steps of putting elements into two Queues");
        printf("\n----------------------------------------");
        int N1=N;
		bool check=false;
		check=checkQueue(queues,&total1,&total2,&N1);
		while(check)
		{putQueue(queues,&total1,&total2,&N1);check=false;}
         Calculate(&each1,&each2,&total1,&total2,&rest1,&rest2);
     	 getOnefromLongQueue(queues,&rest1,&rest2,&each3,&total1,&total2);
		 get2Queue(queues,&each1,&each2,&minute);
         Calculate(&each1,&each2,&total1,&total2,&rest1,&rest2);
		 outPutcalculate(&rest1,&rest2,&average,&minute);
         Layout(&rest1,&rest2,&each1,&each2,&each3,&total1,&total2,&average);

	}
    printf("\n\n ('Y' or 'y' to continue)=>");
	getchar();
	scanf("%c",&ans);
	}while(ans=='Y'||ans=='y');
        
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?