該程序的目標是模擬具有6個「醫生隊列」的醫療綜合體。我試着保持它足夠接近我已完成的Java版本(必須以3種語言進行)。此時,當我運行DequeuePatients
和ListPatients
方法時,程序意外終止,沒有錯誤。我試過調試器,但eclipse忽略了所有的斷點。爲什麼它終止?程序意外終止C++
的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和指定者():
/*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'嗎?如果在調試器中運行它會發生什麼? – doctorlove
QueueChoice將不會與您輸入的數字相同 – Jay
Complex是一個由6個隊列類對象組成的數組,它們都包含節點。每個節點都包含一個Patient'Info'對象和一個指向下一個節點的指針。 GetInfo應返回每個節點中包含的Patient對象。 – user3412695