C++ C++;控制台应用程序;牙科诊所情况下的时间优化队列

C++ C++;控制台应用程序;牙科诊所情况下的时间优化队列,c++,queue,console-application,C++,Queue,Console Application,我正在尝试解决作业中需要的队列问题 详情如下: -我被要求创建一个自动化的强大排队子系统(请注意,每个牙科诊所有2名医生和4张牙医椅,其场地上有1台x光机) -时间优化算法(不同类型的治疗)。例如,蛀牙需要30分钟,体检只需要15分钟,等等。 -每个诊所预计每天上午和下午分别约有20名和15名患者。 -门诊时间为上午8时至下午12时,下午2时至6时 在询问我的讲师时,他说我需要2个队列(每个医生),x光机将是一个即时过程,根本不需要时间。最后,当比较这2个队列时,总持续时间的差异几乎相等 我一直

我正在尝试解决作业中需要的队列问题

详情如下: -我被要求创建一个自动化的强大排队子系统(请注意,每个牙科诊所有2名医生和4张牙医椅,其场地上有1台x光机) -时间优化算法(不同类型的治疗)。例如,蛀牙需要30分钟,体检只需要15分钟,等等。 -每个诊所预计每天上午和下午分别约有20名和15名患者。 -门诊时间为上午8时至下午12时,下午2时至6时

在询问我的讲师时,他说我需要2个队列(每个医生),x光机将是一个即时过程,根本不需要时间。最后,当比较这2个队列时,总持续时间的差异几乎相等

我一直试图解决这个问题,但没有结果。有人能解释一下如何解决这些问题吗

编辑:

我已经创建了队列实现和一个应该排队到队列中的访问类。我需要弄清楚的是如何安排所有这些访问的算法,这样队列将具有时间效率

访问h

#ifndef Visit_H
#define Visit_H

#include "MC.h"
#include "Doctor.h"
#include "Assistant.h"
#include "Condition.h"
#include "Medicine.h"
#include "Treatment.h"

class Visit
{
private:
    std::string date;
    std::string time;
    double duration;
    Staff staff;
    MC mc;
    bool xRayStatus;
    List<Treatment> treatmentList;
    List<Condition> conditionList;
    List<Medicine> medicineList;
public:
    Visit();
    Visit(std::string, std::string, double);
    std::string getDate();
    void addStaff(Staff);
    Staff getStaff();
    void setMC(MC);
    MC getMC();
    void addXRay();
    bool getXRayStatus();
    void addCondition(Condition c);
    void addMedicine(Medicine m);
    void addTreatment(Treatment t);
    List<Treatment> getTreatmentList();
    List<Medicine> getMedicineList();
    List<Condition> getConditionList();
};
#endif
\ifndef访问
#定义访问
#包括“MC.h”
#包括“医生h”
#包括“Assistant.h”
#包括“条件h”
#包括“Medicine.h”
#包括“治疗h”
课堂参观
{
私人:
std::字符串日期;
std::字符串时间;
双倍持续时间;
工作人员;
MC;
布尔X射线状态;
列表治疗列表;
列表条件列表;
药物清单;
公众:
访问();
访问(std::string,std::string,double);
std::string getDate();
工作人员(工作人员);
Staff getStaff();
无效setMC(MC);
MC getMC();
void addXRay();
bool getXRayStatus();
无效条件(条件c);
医学(医学m);
无效治疗(治疗t);
List getTreatmentList();
List getMedicineList();
List getConditionList();
};
#恩迪夫
Visit.cpp

#ifndef Visit_CPP
#define Visit_CPP

#include "Visit.h"

Visit::Visit()
{

}

Visit::Visit(std::string d, std::string t,  double dur)
{
    date = d;
    time = t;
    duration = dur;
}

std::string Visit::getDate()
{
    return date;
}

void Visit::addStaff(Staff s)
{
    staff = s;
}

Staff Visit::getStaff()
{
    return staff;
}

void Visit::setMC(MC m)
{
    mc = m;
}

MC Visit::getMC()
{
    return mc;
}

void Visit::addXRay()
{
    xRayStatus = true;
}

bool Visit::getXRayStatus()
{
    return xRayStatus;
};


void Visit::addCondition(Condition c)
{
    conditionList.add(c);
}

void Visit::addMedicine(Medicine m)
{
    medicineList.add(m);
}

void Visit::addTreatment(Treatment t)
{
    treatmentList.add(t);
}

List<Treatment> Visit::getTreatmentList()
{
    return treatmentList;
}

List<Medicine> Visit::getMedicineList()
{
    return medicineList;
}

List<Condition> Visit::getConditionList()
{
    return conditionList;
};

#endif
\ifndef访问CPP
#定义访问CPP
#包括“访问h”
Visit::Visit()
{
}
就诊::就诊(标准::字符串d、标准::字符串t、双dur)
{
日期=d;
时间=t;
持续时间=dur;
}
std::string Visit::getDate()
{
返回日期;
}
无效访问::添加工作人员(工作人员)
{
staff=s;
}
员工访问::getStaff()
{
返回工作人员;
}
无效访问::setMC(MC m)
{
mc=m;
}
MC访问::getMC()
{
返回mc;
}
无效访问::addXRay()
{
x光状态=真;
}
bool Visit::getXRayStatus()
{
返回x光状态;
};
无效访问::添加条件(条件c)
{
条件清单。添加(c);
}
无效访问::addMedicine(医学m)
{
药物清单。添加(m);
}
无效就诊::添加治疗(治疗t)
{
治疗列表。添加(t);
}
列表访问::getTreatmentList()
{
退货处理清单;
}
列表访问::getMedicineList()
{
返回药单;
}
列表访问::getConditionList()
{
返回条件列表;
};
#恩迪夫
队列.h

//Queue.h - - Specification of Queue ADT (implemented using Pointers)

#include<string>
#include<iostream>
#include "Visit.h"
using namespace std;

typedef Visit ItemType;

class Queue
{
  private:
    struct Node
    {
      ItemType item;    // item
      Node     *next;   // pointer pointing to next item
    };

Node *frontNode;    // point to the first item
Node *backNode; // point to the first item


  public:
    // constructor
    Queue();
    //destructor
    ~Queue();


    // check if the queue is empty
    bool isEmpty();

    // enqueue item at the back of queue
    bool enqueue(ItemType& newItem);

    // dequeue item from front of queue
    bool dequeue();

          // dequeue and retrieve item from front of queue
    bool dequeue(ItemType& item);


    // retrieve item from front of queue
    void getFront(ItemType& item); 





}; 
//Queue.h——队列ADT的规范(使用指针实现)
#包括
#包括
#包括“访问h”
使用名称空间std;
typedef访问项目类型;
类队列
{
私人:
结构体类型
{
ItemType item;//item
Node*next;//指向下一项的指针
};
Node*frontNode;//指向第一项
Node*backNode;//指向第一项
公众:
//建造师
队列();
//析构函数
~Queue();
//检查队列是否为空
bool是空的();
//将项目排在队列后面
bool排队(项目类型和新项目);
//从队列前面将项目出列
bool-dequeue();
//退出队列并从队列前面检索项目
bool出列(项目类型和项目);
//从队列前面检索项目
void getFront(项目类型和项目);
}; 
Queue.cpp

/** @file Queue.cpp */

#include <cstddef>   // for NULL
#include <iostream>
#include <new>       // for bad_alloc
#include "Queue.h"  // header file

using namespace std;

Queue::Queue()
{
    backNode = NULL;
    frontNode = NULL;
}  // end default constructor


Queue::~Queue()
{
   while (!isEmpty())
      dequeue();
}  // end destructor

bool Queue::isEmpty()
{
   return backNode == NULL;
}  // end isEmpty

bool Queue::enqueue(ItemType& item)
{
     // create a new node
      Node *newNode = new Node;
      newNode->item = item;
      newNode->next = NULL;

      // insert the new node
      if (isEmpty())
     // insertion into empty queue
         frontNode = newNode;
      else
     // insertion into nonempty queue
         backNode->next = newNode;

      backNode = newNode;  // new node is at back
      return true;
}  // end enqueue

bool Queue::dequeue() 
{
   if(!isEmpty())
   {  // queue is not empty; remove front
      Node *temp = frontNode;
      if (frontNode == backNode)   // special case?
      {  // yes, one node in queue
         frontNode = NULL;
         backNode = NULL;
      }
      else
         frontNode = frontNode->next;

      temp->next = NULL;  
      delete temp;
      temp = NULL;
      return true;
   }  // end if
   else 
   {
       cout << "empty queue, cannot dequeue" << endl;
       return false;
   }

}  // end dequeue

bool Queue::dequeue(ItemType& item)
{
   if (!isEmpty())
   {  // queue is not empty; retrieve front
      item = frontNode->item;
      dequeue();  // delete front
      return true;
   }  // end if
   else 
   {
       cout << "empty queue, cannot dequeue" << endl;
       return false;
   }

}  // end dequeue

void Queue::getFront(ItemType& item)
{
   if (!isEmpty())
      // queue is not empty; retrieve front
      item = frontNode->item;
    else 
        cout << "empty queue, cannot getFront" << endl;
}  // end getFront

// End of implementation file.
/**@file Queue.cpp*/
#包含//表示空
#包括
#包括//用于坏的\u alloc
#包括“Queue.h”//头文件
使用名称空间std;
队列::队列()
{
backNode=NULL;
frontNode=NULL;
}//结束默认构造函数
队列::~Queue()
{
而(!isEmpty())
出列();
}//结束析构函数
bool队列::isEmpty()
{
返回backNode==NULL;
}//结束是空的
bool队列::排队(项目类型和项目)
{
//创建一个新节点
Node*newNode=新节点;
新建节点->项目=项目;
newNode->next=NULL;
//插入新节点
if(isEmpty())
//插入到空队列中
frontNode=newNode;
其他的
//插入到非空队列中
backNode->next=newNode;
backNode=newNode;//新节点在后面
返回true;
}//结束排队
bool Queue::dequeue()
{
如果(!isEmpty())
{//队列不为空;请删除前面的
Node*temp=frontNode;
if(frontNode==backNode)//特殊情况?
{//是,队列中有一个节点
frontNode=NULL;
backNode=NULL;
}
其他的
frontNode=frontNode->next;
temp->next=NULL;
删除临时文件;
温度=零;
返回true;
}//如果结束,则结束
其他的
{

不能您需要将作业视为事件驱动系统。
一个队列将包含需要处理的事件

如果我们有这样一个事件类:

struct Event  
{  
  virtual bool  execute_if_time(const Time& t) = 0;
};
我们可以有一个指向事件的
向量

typedef std::vector< boost::smart_ptr<Event> > Event_Container;
Event_Container events;
调度器将定期执行容器中的事件

注意:这只是一个方案,因为还有许多其他方案就足够了


其余的代码留给读者作为练习。

任何软件项目中最困难和最重要的部分都是理解需求。我认为在开始编码之前,您仍然需要处理这部分。您哪里有问题?如果我们不知道问题是什么,就很难提供帮助。我在imp方面遇到了问题算法的实现,这是需要在
while (1)
{
  Time t = now();
  for (Event_Container::iterator iter = events.begin();
       iter != events.end();
       ++it)
  {
     (*iter)->exeute_if_time(t);
  }
  sleep(/* some duration */)
}