当前位置:编程学习 > C#/ASP.NET >>

恳请大家帮忙deque iterator not dereferencable错误

customer.h
#ifndef _CUSTOMER_H_
#define _CUSTOMER_H_
#include <iostream>
#include <iomanip>
using namespace std;
class customer
{
private:
    int arrive_time;        //arrive time       
int service_time;               //service time
    int state;                //if state==0 customer is not serviced
public:                                //if state==1 customer is serviced
customer()                         
{
this->arrive_time=0;
this->service_time=0;
this->state=0;
}
    void set_arr_time(int arrive_time)
{
this->arrive_time=arrive_time;
}
void set_ser_time(int service_time)
{
     this->service_time=service_time;    
    }
void set_serviced()
{
this->state=1;   
    }
    void set_droped()
    {
        this->state=0;  
    } 
    int get_arr_time()
{
return arrive_time;
}
int get_ser_time()
{
return service_time;
}
    int get_state()
{
return state;
}
};                                      
#endif _CUSTOMER_H_

station.h

#ifndef _STATION_H_
#define _STATION_H_
#include <iostream>
#include <iomanip>
using namespace std;
class station
{
private:
int service_time;       //the service_time left      
int service_state;       //if service_state==0 station is avaible
public:
station()
{
this->service_time=0;
this->service_state=0;
}
void set_time(int service_time)
{
this->service_time=service_time;
this->service_state=1;
}
void set_avaible()
{
this->service_state=0;
}
void provide_service(int time)
{
if(service_time>time)
{
service_time-=time;
service_state=1;
}
            
        else
            service_state=0;   
    }
int get_state()
{
return service_state;
}
};                                    
#endif _STATION_H_


main.cpp

//==============================================================================
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream> 
#include <cmath>
#include <queue>
#include <time.h>
#include "customer.h"
#include "station.h"
#define avg_ser 10.0                          //the avg_service_time second
#define avg_csm 12.0                          //the avg_customer_arrive_dis
#define num_csm 100                       //the arrived customer number 
#define num_ser 6                           //the service station number
#define num_wait 20                         //the waited customer num
using namespace std;
//==============================================================================
int main(void)
{
    station *ser_que;
    customer *csm_que;
    ser_que=new station[num_ser];
    csm_que=new customer[num_csm];
    queue<int> que_wait;   
//==============================================================================    
    int csm_dis,ser_dis;            
    double y; 
    srand((unsigned)time(NULL));   
    for(int i=0;i<num_csm;i++)              //generating customer arrive_dis
    {
        csm_dis=0;
srand((unsigned)time(NULL));          
double b=1,a=exp(-avg_csm);
            do
            {
                y=(rand()%1000)/1000.0;             
                b*=y;
                if(b>=a)
                csm_dis++;                   
            }while(b>=a); 
        csm_que[i].set_arr_time(csm_dis); 
cout<<csm_que[i].get_arr_time()<<endl;
    }   
    for(int i=0;i<num_csm;i++)              //generating service_dis
    {
        ser_dis=0;
        double b=1,a=exp(-avg_ser);
            do
            {
                y=(rand()%1000)/1000.0;                   
                b*=y;
                if(b>=a)
                ser_dis++;                   
            }while(b>=a);   
        csm_que[i].set_ser_time(ser_dis);        
    } 

//==============================================================================
cout<<que_wait.size()<<endl;
int usr=0;
while(usr<num_csm)
{
for(int ser=0;ser<num_ser;ser++)
{
ser_que[ser].provide_service(csm_que[usr].get_ser_time());
}
if(que_wait.size()<num_wait)
{
que_wait.push(usr);
int size=que_wait.size();
cout<<size<<endl;
for(int s=0;s<size;s++)
{
for(int ser=0;ser<num_ser;ser++)
{
if(ser_que[ser].get_state()==0)
{
int usr_que=que_wait.front();
ser_que[ser].set_time(csm_que[usr_que].get_ser_time());
csm_que[usr_que].set_serviced();
if(!que_wait.empty())
{
que_wait.pop();
}
// continue;   
}
}
}
usr++;
}
else
{
csm_que[usr].set_droped();
usr++;

}
cout<<que_wait.size()<<endl;
//==============================================================================
    for(int i=0;i<num_csm;i++)              
    {
        cout<<csm_que[i].get_state();
    }
    system("PAUSE");
    return 0;
}
//==============================================================================


--------------------编程问答-------------------- aiya ~~~
补充:.NET技术 ,  VC.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,