【发布时间】:2017-04-23 09:09:28
【问题描述】:
该程序的目标是模拟具有 6 个“医生队列”的医疗综合体。我试着让它与我完成的 Java 版本足够接近(必须用 3 种语言来做)。此时,当我运行DequeuePatients 和ListPatients 方法时,程序意外终止,没有错误。我已经尝试过调试器,但 eclipse 忽略了我所有的断点。为什么它会终止?
ListPatients 方法都在 Driver 类中:
void ListPatients() {
int x, QueueChoice = 0;
bool exit = false;``
while (!exit) {
for (x = 1; x <= MAX; x++) {
cout << x << ": " << Doctor[x - 1] << "\n";
} // end-for
cout << "Choose a Queue to List From";
cin >> QueueChoice;
if (OpenFlag[QueueChoice - 1] == true) { //open flag for each queue
int i = Complex[QueueChoice - 1]->GetSize();//Global array of queues
//cout <<i<<endl;
-
如果函数被调用,则在此循环中终止
for (x = 1; x <= i; x++) { Patient This = Complex[QueueChoice-1]->GetInfo(x); //Program Terminates here cout << x<< ": " << endl;//This.ID_Number; //<<Complex[QueueChoice - 1]->GetInfo(x + 1).PrintMe() } // end-for } // end-if cout << "Press 1 to List Another Queue, press 2 to exit"; cin >> x; switch (x) { case 1: break; case 2: exit = true; break; }//switch } // end-while } // List Patients`
队列类 GetInfo 和 toArray():
/*Return Patient info from each Node*/
Patient Queue::GetInfo(int Pos) {
Node* ComplexArray= new Node[Length];
ComplexArray = this->toArray();
return ComplexArray[Pos - 1].Info;
}
// The toArray method
Node* Queue::toArray() {
// Copy the information in each node to an array and return the array.
int x = Length;
Node ComplexArray[Length] ={} ;
Node* Current = new Node();
Current = Rear;`
for (x = 0; x<Length;x++) {
ComplexArray[x] = Node();
ComplexArray[x].Modify(Current);
Current = Current->Next;
}
return ComplexArray;
} // End of toArray method
在节点中修改方法:
void Node :: Modify(Node* ThisNode)
{
Info = ThisNode->Info;
Next = ThisNode->Next;
}
【问题讨论】:
-
Complex是什么,GetInfo有什么作用?如果在调试器中运行它会发生什么? -
QueueChoice 不会等于您输入的数字
-
Complex 是一个包含 6 个 Queue 类对象的数组,所有对象都包含节点。每个节点都包含一个 Patient
Info对象和一个指向下一个节点的指针。 GetInfo 应该返回每个 Node 中包含的 Patient 对象。 -
GetInfo调用具有x=0的toArray并设置ComplexArray[x-1]将是0-1开始。 -
...版本控制对这类事情很有帮助
标签: c++ eclipse pointers queue