good day. i have a problem with my program. this is designed for small clinics to basically
record the patients information for an appointment. so here is my problem, at first it was
working but whenever im going to input infos for the 3rd patient(3rd node), after inputting
the name it will go on an error. this is a queue. `
#include <iostream>
using namespace std;
struct clnc_hrs
{
std:: string name;
std:: string symptms;
int age;
int cont_num;
clnc_hrs *next;
};
class List{
private:
clnc_hrs *rear;
clnc_hrs *front;
public:
List();
void BookAppointment();
void DeletePrevious();
void DisplaySchedule();
};
List::List(){
rear = NULL;
front = NULL;
}
void List::BookAppointment ()
{
std:: string N;
std:: string S;
int A;
int CN;
clnc_hrs *newnode = (clnc_hrs*)malloc(sizeof(clnc_hrs));
fflush(stdin);
cout<<"enter name of the patient:";
std::getline(cin, N);
newnode->name = N;
fflush(stdin);
cout<<"enter age of the patient:";
cin>>A;
newnode->age = A;
fflush(stdin);
cout<<"enter contact number of the patient:";
cin>>CN;
newnode->cont_num = CN;
fflush(stdin);
cout<<"enter the complaints or symptoms of the patient:";
std::getline(cin, S);
newnode->symptms = S;
newnode->next = NULL;
if(front == NULL)
{
fflush(stdin);
front = newnode;
fflush(stdin);
}
else
{
fflush(stdin);
rear->next = newnode;
fflush(stdin);
}
rear = newnode;
}
void List::DisplaySchedule ()
{
clnc_hrs *disp = (clnc_hrs*)malloc(sizeof(clnc_hrs));
disp = front;
if(front == NULL)
{
cout<<"there's no appointment for today"<<endl;
}
else
{
while(disp != NULL)
{
cout<<endl;
cout<<"name:"<<disp->name<<endl;
cout<<"age:"<<disp->age<<endl;
cout<<"contact number:"<<disp->cont_num<<endl;
cout<<"symptoms/complaints:"<<disp->symptms<<endl;
cout<<endl;
disp = disp->next;
}
}
}
void List::DeletePrevious()
{
clnc_hrs *newnode = (clnc_hrs*)malloc(sizeof(clnc_hrs));
if(front == NULL)
{
cout<<"no appointments today"<<endl;
}
else
{
newnode = front;
front = front->next;
cout<<"The previous patient is: "<<endl;
cout<<newnode->name<<endl;
cout<<newnode->age<<endl;
cout<<newnode->cont_num<<endl;
cout<<newnode->symptms<<endl;
delete newnode;
}
}
int main ()
{
List list;
int ans;
while(true)
{
cout<<"press 1 for booking an appointment\npress 2 to delete previous patients info \npress 3 for display"<<endl;
cin>>ans;
if(ans == 1)
{
list.BookAppointment();
}
else if(ans == 2)
{
list.DeletePrevious();
}
else if(ans == 3)
{
list.DisplaySchedule();
}
}
system("pause");
}
`
i hope someone here can help me. i am using dev c++ 4.9.9.2