First I'll explain what I'm trying to do. I am programming an airline check-in line. I am using a queue ADT to represent a the line. The data type of the a queue is a pointer to my Customer class. In my Customer class, whenever a customer leaves the line, a method in the Customer class named talk will print out a canned response. Here is what it looks like:
string Customer::talk()
{
cout << firstName << ' ' << lastName
<< " says, \"This is the worst airline!\"." << endl;
}
All the data is read in from an input file. It includes a command 'add' to add the customer to the queue. When I try to remove customers from the queue, talk only prints out the last customer read in however many times a customer was added. So I get something like this:
John Malkovich says, "This is the worst airline!".
John Malkovich says, "This is the worst airline!".
John Malkovich says, "This is the worst airline!".
John Malkovich says, "This is the worst airline!".
John Malkovich says, "This is the worst airline!".
John Malkovich says, "This is the worst airline!".
I believe my problem is in main:
Queue q;
Customer c;
Customer *cp = &c;
string command, fname, lname, stat;
while(infile >> command)
{
//After reading in the command, calling the approprate function
if(command == "add")
{
infile >> fname;
c.setFirstName(fname);
cout << fname << ' ';
infile >> lname;
c.setLastName(lname);
cout << lname << ' ';
infile >> stat;
c.setStatus(stat);
cout << stat << endl;
q.enqueue(cp);
}
}
while(!q.isEmpty())
{
q.getFront(cp);
cp->talk();
q.dequeue();
}
is with my pointers and the way I'm storing my data. Could someone please help?