Banka Sıra Simülasyonu Yapan Program

Bir bankanın günlük sıra işlemlerinin simulasyonunu yapan ve gün sonu istatistiklerini sunan bir program (C++ Linked List yapıları kullanılıyor).

İndir

Dikkat, bu program simülasyon bitmeden kapatılamamaktadır!
Windows 98 gibi Görev Yöneticisi'nden programı kapatamayacağınız işletim sisteminde çalıştırmayın veya çalıştırdığınızda simülasyonun tamamlanmasını bekleyin!
FilenameFilesizeLast modified
BankQueueSimulator.cpp9.0 KiB2019/05/08 21:25
BankQueueSimulator.exe111.4 KiB2019/05/08 21:25
BankQueueSimulator.txt4.7 KiB2019/05/08 21:25
bankqueuesimulator1.jpg14.6 KiB2019/05/08 21:25
bankqueuesimulator2.jpg17.2 KiB2019/05/08 21:25

Kaynak Kodu:

Bir bankanın günlük sıra işlemlerinin simulasyonunu yapan ve gün sonu istatistiklerini sunan bir program (C++ Linked List yapıları kullanılıyor).

#include <iostream.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
 
template <class T>
class Node //a  node class is defined for the link list
{
	private:
		Node<T> *next;  //next node is private
	public :
		T data;    //data is public
 
		Node (const T& item, Node <T>* ptrnext = NULL);
 
		void InsertAfter(Node<T> *p);
 
		Node<T> *DeleteAfter(void);
 
		Node<T> *NextNode(void) const; //used to access *next
};
 
template <class T>
Node<T>::Node(const T& item,Node<T>* ptrnext):data(item),next(ptrnext){}
 
template <class T>
Node<T> *Node<T>::NextNode(void) const   //it returns next of the Node
{
	return next;
}
 
template <class T>
void Node<T>::InsertAfter(Node<T> *p)  //to add an item after the current node
{
	p->next=next;
	next=p;
}
 
template <class T>
Node<T> *Node<T>::DeleteAfter(void)
{
	Node<T> *temp=next;
 
	if(next==NULL)
		return NULL;
 
	next=temp->next;
 
	return temp;
}
 
template <class T>
Node<T> *GetNode(const T item, Node<T> *nextPtr =NULL)//used to allocate a new Node
{
	Node<T> *newNode;
 
	newNode= new Node<T>(item,nextPtr);  //dynamic memory allocation
 
	if(newNode==NULL)          //if it is not successful an error is output.
	{
	cout<<"allocation error"<<endl;
	}
	return newNode;
}
 
template<class T>
void InsertRear(Node<T>* head, const T& item) //Adds a node at the end of the linked list
{                                             //it takes the head of the linked list
	Node<T> *newNode, *currPtr=head;
 
	while(currPtr->NextNode()!= NULL)
	currPtr=currPtr->NextNode();       //goes at the end of the list
 
	newNode=GetNode(item);            //GetNode defines a new node;
	currPtr->InsertAfter(newNode);    //inserted at the end of the list
}
 
void wait ( double seconds )   //used to obtain a delay
{
  clock_t endwait;
  endwait = clock () + seconds * CLK_TCK ;
  while (clock() < endwait) {}
}
 
 
int main(void)
{
 
srand ( time(NULL) );    //used to randomize rand()
Node<int> *head1,*Ptr,*Ptr2;
 
float rnum;
 
int rtask,timet;
int m,h;
 
 
head1=GetNode(2);
 
int teller1,teller2,teller3,teller4;
int busy=1;
int free=0;
int CurrTask;
int tA_Duration=0,tB_Duration=0,tC_Duration=0,tD_Duration=0;
int total_tA_Dur=0,total_tB_Dur=0,total_tC_Dur=0,total_tD_Dur=0;
int TotalCustA,TotalCustB,TotalCustC,TotalCustD;
float M_ServiceTimeA,M_ServiceTimeB,M_ServiceTimeC,M_ServiceTimeD;
 
 
teller1=free;
teller2=free;
teller3=free;
teller4=free;
 
TotalCustA=0;
TotalCustB=0;
TotalCustC=0;
TotalCustD=0;
 
  for (h=9; h<17; h++)    //main for loop for hour
  {
	 for (m=0; m<60; m++)   //main for loop for minute
	 {
 
	 Ptr=head1;
			 timet=60*h+m;   //timet is the minute format of the time e.g 9.30=570
 
			 cout<<"Current Time->"<<h<<":"<<m;   //Print current time
 
          if(timet>750&&timet<810)//12,30-13,30
				cout<<"  (Lunch Break)";
 
			 cout<<endl<<endl;
	  for(int t=0;t<2;t++){
			rtask=(rand()%4)+1; //generate a random task between 1 and 4
 
			rnum=(rand()%100);  //generate random number for activity factor between 0 and 1
			rnum=rnum/100;
 
 
			 if(timet>540 && timet<599 && rnum>0.9)//9,00-10,00   new customer insert depend on activity factor and time
					 InsertRear(head1,rtask);  //a customer is inserted at the end of the Customer Queue(at the end of linked list)
 
			 else if(timet>600 && timet<750 && rnum>0.8)//10,00-12,30
					 InsertRear(head1,rtask);//a customer is inserted at the end of the Customer Queue(at the end of linked list)
 
			else if(timet>810 && timet<960 && rnum>0.8)//13,30-16,00
					 InsertRear(head1,rtask);//a customer is inserted at the end of the Customer Queue(at the end of linked list)
 
			 else if(timet>960&&timet<1020 && rnum>0.9)//16,00-17,00
					InsertRear(head1,rtask);//a customer is inserted at the end of the Customer Queue(at the end of linked list)
	 } //for
 
 
 
	 if(head1->NextNode()!=NULL)
		CurrTask=head1->data;  //shows the first customer in the queue if it is not null
 
switch(CurrTask){
			case 1:    //if first element of the linked list is 1 than take it as task A
			if(teller1==free&&(timet<750||timet>810))    //if teller is free than take the customer,also if not lunch break
			{
			TotalCustA++;  //increase total customer for A
			cout<<"t1->bos";
				if(head1->NextNode()!=NULL)
					head1=head1->NextNode();
			teller1=busy;
 
			tA_Duration=(rand()%11)+2;  //generate a random duration for task
			total_tA_Dur=total_tA_Dur+ tA_Duration; //update total duration
			}
			break;
			case 2:
			if(teller2==free&&(timet<750||timet>810)) //if teller is free than take the customer,also if not lunch break
			{
			 TotalCustB++;   //update total customer
				if(head1->NextNode()!=NULL)
					head1=head1->NextNode();   //the first customer is taken make the second customer first
			teller2=busy;
			tB_Duration=(rand()%5)+14;   //generate a random duration for task
			total_tB_Dur=total_tB_Dur+ tB_Duration;   //update total duration
			}
 
			break;
			case 3:
			if(teller3==free&&(timet<750||timet>810))  //if teller is free than take the customer,also if not lunch break
			{
			TotalCustC++;   //update total customer
				if(head1->NextNode()!=NULL)
					head1=head1->NextNode();  //the first customer is taken make the second customer first
			teller3=busy;
			tC_Duration=(rand()%3)+4;    //generate a random duration for task
			total_tC_Dur=total_tC_Dur+ tC_Duration;  //update total duration
			}
			break;
			case 4:
			if(teller4==free&&(timet<750||timet>810)) //if teller is free than take the customer,also if not lunch break
			{
			TotalCustD++;  //update total customer
				if(head1->NextNode()!=NULL)
					head1=head1->NextNode();   //the first customer is taken make the second customer first
			teller4=busy;
			tD_Duration=(rand()%16)+15;   //generate a random duration for task
			total_tD_Dur=total_tD_Dur+ tD_Duration;   //update total duration
			}
			break;
			default:
 
			break;
 
		}//switch
 
 
		cout<<"Teller1:";      //print the name of teller
		cout.width(20);
		cout<<"Teller2:";
		cout.width(20);
		cout<<"Teller3:";
		cout.width(20);
		cout<<"Teller4:"<<endl<<endl ;
 
		if(teller1==busy)     //print the status of teller
			cout<<"Busy";
		else if(teller1==free)
			cout<<"Free";
 
		cout.width(20);
		if(teller2==busy)
			cout<<"Busy";
		else if(teller2==free)
			cout<<"Free";
 
		cout.width(20);
		if(teller3==busy)
			cout<<"Busy";
		else if(teller3==free)
			cout<<"Free";
 
		cout.width(20);
		if(teller4==busy)
			cout<<"Busy"<<endl;
		else if(teller4==free)
			cout<<"Free"<<endl<<endl;
 
 
		cout<<  "Time left:"<<tA_Duration;   //print the left time for the task tobe completed
		cout.width(20);
		cout<<  "Time left:"<<tB_Duration;
		cout.width(20);
		cout<<  "Time left:"<<tC_Duration;
		cout.width(20);
		cout<<  "Time left:"<<tD_Duration<<endl;
 
 
			if(tA_Duration==0)
			teller1=free;  //if the taslk is completed make the teller free
 
			if(tA_Duration>0)
				tA_Duration--;     //update the left duration for the task in every minute
 
			if(tB_Duration==0)
			teller2=free;         //if the taslk is completed make the teller free
 
			if(tB_Duration>0)
				tB_Duration--;      //update the left duration for the task in every minute
 
			if(tC_Duration==0)
			teller3=free;            //if the taslk is completed make the teller free
 
			if(tC_Duration>0)
				tC_Duration--;      //update the left duration for the task in every minute
 
			if(tD_Duration==0)
			teller4=free;            //if the taslk is completed make the teller free
 
			if(tD_Duration>0)
				tD_Duration--;      //update the left duration for the task in every minute
 
 
	int qlength=0;
	 while(Ptr->NextNode()!=0){  //find the length of the queue
		if(qlength<10)
		 switch(Ptr->data){
		  case 1:                 //print the first 10 tasks
		  cout<<"Task A"<<endl;
		  break;
		  case 2:
		  cout<<"Task B"<<endl;
		  break;
		  case 3:
		  cout<<"Task C"<<endl;
		  break;
		  case 4:
		  cout<<"Task D"<<endl;
		  break;
		  default:
		  break;
		 }
 
		qlength++;
		Ptr=Ptr->NextNode();
	 }
	 cout<<endl<<"Queue Length:"<<qlength;
 
 
 
 
		wait (0.3);
		clrscr();
 
 
 
 
 
	}
 
}
 
 
	if(TotalCustA!=0)
		M_ServiceTimeA=float(total_tA_Dur)/float(TotalCustA);    //calculate Mean Service Time
	if(TotalCustB!=0)
		M_ServiceTimeB=float(total_tB_Dur)/float(TotalCustB);
	if(TotalCustC!=0)
		M_ServiceTimeC=float(total_tC_Dur)/float(TotalCustC);
	if(TotalCustD!=0)
		M_ServiceTimeD=float(total_tD_Dur)/float(TotalCustD);
 
  cout<<endl<<"Teller 1 Statistics:"<<endl;         //print the statistics
  cout<<"Total Customer Served: "<<TotalCustA<<endl;
  cout<<"Mean time spent: "<<M_ServiceTimeA<<endl;
  cout<<"Efficiency: "<<M_ServiceTimeA/7<<endl;         //calculate the efficiency
 
  cout<<endl<<"Teller 2 Statistics:"<<endl;
  cout<<"Total Customer Served: "<<TotalCustB<<endl;
  cout<<"Mean time spent: "<<M_ServiceTimeB<<endl;
  cout<<"Efficiency: "<<M_ServiceTimeB/16<<endl;
 
  cout<<endl<<"Teller 3 Statistics:"<<endl;
  cout<<"Total Customer Served: "<<TotalCustC<<endl;
  cout<<"Mean time spent: "<<M_ServiceTimeC<<endl;
  cout<<"Efficiency: "<<M_ServiceTimeC/5<<endl;
 
  cout<<endl<<"Teller 4 Statistics:"<<endl;
  cout<<"Total Customer Served: "<<TotalCustD<<endl;
  cout<<"Mean time spent: "<<M_ServiceTimeD<<endl;
  cout<<"Efficiency: "<<M_ServiceTimeD/22.5<<endl;
 
 return 0;
}
 
 
 

  • projelerim/programlama/cplusplus/bank_queue_simulator.txt
  • Son değiştirilme: 2019/05/08 21:25
  • (Dışarıdan düzenle)