欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

C++實現(xiàn)銀行排隊系統(tǒng)

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊: 次

本文實例為大家分享了C++實現(xiàn)銀行排隊系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int cnt=0; //當(dāng)日客流量
int sum=0; //當(dāng)日客戶排隊總時間
typedef struct pnode{
  int number;
  int cometime;
  int leavetime;
  struct pnode *next;
}*person;
typedef struct node{
  person front;
  person rear;
  int   length;
}linkqueue;
linkqueue q[5];
int number,time;
int flag=1;
void initqueue(linkqueue &q){
  q.front=q.rear=(person)malloc(sizeof(pnode));
  if(!q.front||!q.rear)
    exit(0);
  q.front->next=NULL;
  q.length=0;
}
void enterqueue(linkqueue &q,int number,int time){
  person p;
  p=(person)malloc(sizeof(person));
  if(!p) exit(0);
  q.length++;
  p->number=number;
  p->cometime=time;
 // sum+=p->finishtime; //統(tǒng)計每個人的排隊時長
  p->next=NULL;
  q.rear->next=p;
  q.rear=p;
}
void popqueue(linkqueue &q){
  person p;
  if(q.front==q.rear){
    return ;
  }
  p=q.front->next;
  q.front->next=p->next;
  q.length--;
  if(q.rear==p){
    q.front=q.rear;
  }
}
int getmin(linkqueue q[]){
   int temp=q[1].length;
   int j=1;
  for(int i=2;i<=4;i++){
    if(q[i].length<temp){
      temp=q[i].length;
      j=i;
    }
  }
  return j;
}
int getmax(linkqueue q[]){
  int temp=q[1].length;
   int j=1;
  for(int i=2;i<=4;i++){
    if(q[i].length>temp){
      temp=q[i].length;
      j=i;
    }
  }
  return j;
}

void Customer_Come(){
  printf("客戶選隊并排隊\n\n");
    printf("輸入客戶編號:");
    scanf("%d",&number);
    printf("輸入當(dāng)前時間:");
    scanf("%d",&time);
    printf("\n");

   /*
    if(one.length<=two.length&&one.length<=three.length&&one.length<=four.length){
      enterqueue(one,number,time);
    }
    else if(two.length<=one.length&&two.length<=three.length&&two.length<=four.length){
      enterqueue(two,number,time);
    }
    else if(three.length<=one.length&&three.length<=two.length&&three.length<=four.length){
      enterqueue(three,number,time);
    }
    else{
      enterqueue(four,number,time);
    }*/
      printf("%d號顧客來到%d號窗口\n",number,getmin(q));
      enterqueue(q[getmin(q)],number,time);
}
void Customer_Leave(){
    printf("客戶離隊:\n\n");
    printf("輸入要離隊的客戶編號: ");
    scanf("%d",&number);
    printf("輸入當(dāng)前時間:  ");
    scanf("%d",&time);
    //從四個隊的隊首分別去找,因為離隊的只能是隊首。
  /*  if(one.front->next->number==number){
      printf("%d號客戶辦理完成業(yè)務(wù)從1號窗口離開\n",number);
      popqueue(one);
      break;
    }
     if(two.front->next->number==number){
      printf("%d號客戶辦理完成業(yè)務(wù)從2號窗口離開\n",number);
      popqueue(two);
      break;
    }
     if(three.front->next->number==number){
      printf("%d號客戶辦理完成業(yè)務(wù)從3號窗口離開\n",number);
      popqueue(three);
      break;
    }
     if (four.front->next->number==number){
      printf("%d號客戶辦理完成業(yè)務(wù)從4號窗口離開\n",number);
      popqueue(four);
      break;
    } */
    for(int i=1;i<=4;i++){
      if(q[i].front->next->number==number){
        sum+=time-q[i].front->next->cometime;
        printf("%d號客戶辦理完成業(yè)務(wù)從%d號窗口離開\n",number,i);
        popqueue(q[i]);
        flag=0;
      }
    }
    if(flag)
      printf("編號錯誤請重新輸入\n");
}
void Adjust_Queue(linkqueue q[]){
  int m=getmin(q);
  int n=getmax(q);
  person x,y;
  x=(person)malloc(sizeof(pnode));
  y=(person)malloc(sizeof(pnode));
  x=q[n].rear;
  enterqueue(q[m],x->number,x->cometime);
  y=q[n].front;
  while(y->next!=q[n].rear)
    y->next=y->next->next;
  q[n].rear=y;
  free(y->next);
  q[n].length--;
  q[m].length++;
}
void Close_Door(){
  printf("下班時間到,工作結(jié)束。\n");
  printf("今天共接待了%d位客戶\n", cnt);
  printf("每位客戶平均逗留時間為%.2f\n", (float)sum/cnt);
}
void welcome(){
  printf("    **************************   *************************\n");
  printf("    *   模擬銀行排隊系統(tǒng)  *   *  請輸入號碼選擇功能 *\n");
  printf("    **************************   *************************\n");
  printf("     當(dāng)前一號隊列人數(shù):%3d                 \n",q[1].length);
  printf("                     1  客戶選隊并排隊  \n");
  printf("     當(dāng)前二號隊列人數(shù):%3d                 \n",q[2].length);
  printf("                     2   客戶離隊    \n");
  printf("     當(dāng)前三號隊列人數(shù):%3d                 \n",q[3].length);
  printf("                     3   退出系統(tǒng)    \n");
  printf("     當(dāng)前四號隊列人數(shù):%3d                 \n",q[4].length);
  printf("    **************************   *************************\n");
}
int main(){
  //initqueue(one);
  //initqueue(two);
  //initqueue(three);
  //initqueue(four);
  for(int i=1;i<=4;i++){
    initqueue(q[i]);
  }
 while(1){
    welcome();
    int x;
  scanf("%d",&x);
  switch(x){
    case 1:
      cnt++;
      Customer_Come();
      break;
    case 2:
      Customer_Leave();
      while(q[getmax(q)].length-q[getmin(q)].length>=2)
        Adjust_Queue(q);
      break;
    case 3:
      Close_Door();
      exit(0);
      break;
   }
  }
  return 0;
}


以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:數(shù)據(jù)結(jié)構(gòu) 中數(shù)制轉(zhuǎn)換(棧的應(yīng)用)

欄    目:C語言

下一篇:C 語言中strstr函數(shù)實例詳解

本文標(biāo)題:C++實現(xiàn)銀行排隊系統(tǒng)

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/1402.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有