首先,我将解释课程及其目的:ClinicQueue(Queue类,旨在创建患者队列),ClinicNode(典型节点类,Queue必需),ClinicPatient(存储队列中患者的数据),和ClinicDriver(用于构建主应用程序)。我需要做的是显示队列的内容 - 每个节点都有一个数据成员" info"这是ClinicPatient的一个实例,包含患者的数据。在我目前的代码中,我只能让一个病人打印,我知道我的逻辑出现了问题,但是经过3个小时的同样问题和各种尝试解决它后,我只能看不到那是什么问题。如何修复代码或编写新代码以执行必要的任务?以下是显示功能以及用于获取患者信息的功能。
ClinicPatient ClinicQueue::getInfo(int pos) //get information on patients
{
ClinicNode* Current = front;
for(int i = 0; i < pos; i++)//for pos +/- 1 only outputs
//"patient 1: "(a cout in driver)
{
Current = Current -> next;
}
return Current -> info; //blows up
}
显示功能:
void ClinicDriver::Peekaboo() //breaks with more than one patient, skips last patient
{
bool cont = true;
int QueueChoice;
while (cont == true)
{
string temp;
cout << "Select a Doctor by number." << endl;
cin >> QueueChoice;
if (status[QueueChoice - 1] == true)
{
cout << "Queue is open." << endl;
string OutputS = "";
for (int a = 1; a <= Clinic[QueueChoice - 1].getSize(); a++)
{
cout << "Patient " << a << " : " << endl; //new, debugging
OutputS += Clinic[QueueChoice - 1].getInfo(a-1).tostring();//breaks here, works on 1 patient
OutputS += "\n";
}
cout << OutputS << endl;
}
else
{
cout << "Queue is empty." << endl;
}
cout << "Do you wish to continue?" << endl;
cin >> temp;
if (temp == "Yes" || temp == "yes")
{
cont = true;
}
else
{
cont = false;
}
}
}
非常感谢任何和所有帮助。