The code below keeps flagging an error on the head
and tail
in the add_ticket()
function.
I cannot run the program because of these errors. Please, I need help.
I am trying to make a linked list that will take user requests and store them in a queue.
I am still kind of new to the programming world, and I am really interested in learning C++.
#include <iostream>
#include <string>
// include other header files as necessary
// constants, to define the different ticket types (TT) that may exist, e.g., whether it is a support request, bug fix, or feature request
#define TT_UNDEFINED 100 // the ticket type is undefined
#define TT_SUPPORT 101 // the ticket is for a support request
#define TT_BUG 102 // the ticket is a bug report
#define TT_FEATURE 103 // the ticket is a request for a new feature
// data structure to record details of a ticket to be placed on the queue
struct Ticket {
std::string customer_id;
int ticket_type; // will be assigned one of the ticket type values above, e.g., TT_BUG.
Ticket* next;// points to next ticket in queue
Ticket* head;
Ticket* tail;
};
// a class to implement the linked-list data structure for the ticket queue
class TicketQueue
{
private:
Ticket* head; // points to item at head of the queue
Ticket* tail; // points to item at tail of the queue
public:
TicketQueue(); // constructor, initialise the queue to be empty
~TicketQueue(); // destructor, free up any resources that are still in use by the queue
void add_ticket(Ticket*, bool); // adds a new, pre-populated ticket to the queue for a premium (TRUE) or standard (FALSE) customer
Ticket* get_next_ticket(); // remove and return (a pointer to) the next ticket from the queue for processing
void clear(); // clears / removes all tickets from the queue
bool is_empty(); // returns true / false whether the ticket queue is currently empty or not
void display(); // outputs the entire queue of Tickets to cout
void store(std::string); // outputs the entire queue of Tickets to a specified file on disk
};
// IMPLEMENTATION OF THE METHODS DECLARED IN THE TicketQueue CLASS
// your code goes here
TicketQueue::TicketQueue()
{
head = tail = NULL;
}
TicketQueue :: ~TicketQueue()
{
Ticket* current = head;
Ticket* next;
while (current != NULL)
{
next = current->next;
delete current;
current = next;
}
}
void add_ticket(Ticket*, bool)
{
std::string customer_Id;
int ticket_type;
struct Ticket* ptr;
std::cout << std::endl
<< "Adding new Ticket\n"
<< "Enter Customer Id:\n";
std::cin >> customer_Id;
std::cout << "Enter Ticket Type .\n" << std::endl;
std::cin >> ticket_type;
ptr = new Ticket;
ptr->customer_id = customer_Id;
ptr->ticket_type = ticket_type;
ptr->next = NULL;
if (head == NULL)
head = ptr;
else
tail->next = ptr;
tail = ptr;
std::cout << "\nNew item is inserted to the Queue!!!";
}