⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.h

📁 c++写的实现数学排队论的算法程序
💻 H
字号:
#ifndef SERVER_H
#define SERVER_H
	
#include <iostream>
#include <iomanip>

using namespace std;

const int NOBODY = -1;
//class invariantfor the service class:

//A server object represents a station where a person receives
//  a service (banking, haircut, etc., etc.).

//A server object contains:
//  1)  a person number, that represents the person getting the service.
//  2)  a timer, that records how long the person has been getting the servic.
//  3)  a service time, that is the limit of the time a person gets service.
//         When the timer reaches the service time, then the person is removed
class server
{
   friend ostream& operator<< (ostream& out, server& service)
{
    if (!service.isAvailable ())
        out << setw (WIDTH) << service.person;
        
    else
        cout << setw (WIDTH) <<"   ";
          
    return out;
}
      
public:
//Initialize the person to empty, the time to 0, and set the length of
//  the service time.
   server (int time)      
   {
     person      = NOBODY; 
     timer       = 0;
     serviceTime = time;
   }
        
   void setservertime(int servertime_ar)
   {
     serviceTime = servertime_ar;
   }    

   bool isAvailable  ()
   {
    bool returnVal = false;
    
    if (person == NOBODY) 
       returnVal = true; 
     
    return returnVal;
   }
     
   //n is the number of the person to be serviced.  Since service is 
   //  starting, set the timer to 0.
    void StartService (int n)
   {
    person = n; 
    timer  = 0;
	servicetime[person] = serviceTime;
   }
        
   //Add a minute to the timer.  If the service time is reached, then
   //  the person being serviced is done, so remove him/her, and reset
   //  the time to 0.

    void Update ()
	{

		timer++; 
         
		if (timer == serviceTime)   
		{   
			person = NOBODY;
			timer  = 0;
		}
	}
        
private:
    int person;
    int timer;
    int serviceTime;
	int servicetime[MAXSIZE];
};

#endif

⌨️ 快捷键说明

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