Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We need to create a queue of items defined by the following structure. struct Qu

ID: 3848929 • Letter: W

Question

We need to create a queue of items defined by the following structure.

struct QueueItem

{

string fname;

string lname;

double salary;

QueueItem *next;

};

Use the following class definition to create a queue.

class Queue

{

private:

QueueItem *front;

QueueItem *back;

bool isempty;

public:

Queue()

{

front=NULL;

back=NULL;

isempty=true;

}

void enque(QueueItem *item);

void deque();

};

Write definition for the enque and deque function. Use the following main function to test your code.

int main()

{

ifstream fin;

fin.open("HW3Data.dat");

Queue my_queue;

string fname, lname;

double salary;

QueueItem *item=new QueueItem;

while(fin>>fname>>lname>>salary)

{

item->fname=fname;

item->lname=lname;

item->salary=salary;

my_queue.enque(item);

}

for (int i=0;i<9;++i)

my_queue.deque();

return 0;

}

You must get the following output.

John Harris 50000

Lisa Smith 75000.5

Adam Johnson 68500.1

Sheila Smith 150000

Tristen Major 75800.8

Yannic Lennart 58000.6

Lorena Emil 43000

Tereza Santeri 48000

Queue is empty. Nothing to remove.

Explanation / Answer

#include<iostream>

#include<string>

#include<fstream>

using namespace std;

struct QueueItem

{

   string fname;

   string lname;

   double salary;

   QueueItem *next;

};

class Queue

{

   private:

      QueueItem *front;

      QueueItem *back;

      bool isempty;

   public:

      Queue()

      {

          front=NULL;

          back=NULL;

          isempty=true;

      }

      void enque(QueueItem *item);

      void deque();

};

void Queue::enque(QueueItem* item) {

  QueueItem *newItem = new QueueItem;

  *newItem = *item;

  if (back == NULL) //inserting 1st item in the queue

      front = back = newItem;

  else    //inserting item when the queue is not empty

      back = back->next = newItem;

  back->next = NULL; //this makes sure that 'back' node marks end of the queue

}

void Queue::deque(){

  if (front == NULL) { //if the queue is empty

      cout << "Queue is empty. Nothing to remove." << endl; //print error msh

      return;

  }

  cout << front->fname << " " << front->lname << " " << front->salary << endl; //print details of front node

  front = front->next;

  if (front == NULL) //if queue becomoes empty

      back = NULL; //Nullify back also

}


int main()

{

   ifstream fin;

   fin.open("HW3Data.dat");

   Queue my_queue;

   string fname, lname;

   double salary;

   QueueItem *item=new QueueItem;

   while(fin>>fname>>lname>>salary)

   {

      item->fname=fname;

      item->lname=lname;

      item->salary=salary;

      my_queue.enque(item);

   }

   for (int i=0;i<9;++i)

   my_queue.deque();

   return 0;

}

These are the two functions you need. I have commented the code to make things easy, and I hope you like them. Let me know if you need any guidance. I shall be glad to help you.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote