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

c++ simple help Dequeue one employee at a time from original queue. If her/his s

ID: 3775248 • Letter: C

Question

c++ simple help

Dequeue one employee at a time from original queue. If her/his salary is less than 50000, enqueue that emplyee in the demandsalaryincrease queue. Otherwise move to the next employee

Heres what I got:

It isnt working properly as problem says it should do, I'm sure its an easy fix but I can't figure it out.

int main() {

   DynEmpQueue originalqueue;
   originalqueue.enqueue(123, "John Smith", 65000.0);
   originalqueue.enqueue(129, "Jane Smith", 55000.0);
   originalqueue.enqueue(154, "Johnson Smith", 76000.0);
   originalqueue.enqueue(223, "Janet Smith", 19000.0);
   originalqueue.enqueue(823, "Joe Smith", 94000.00);

   DynEmpQueue demandsalaryincrease;
   int v;
   string n;
   float s;

   if (!originalqueue.isEmpty())
   {
       originalqueue.dequeue(v, n, s);

       if (s<50000) {
      
           demandsalaryincrease.enqueue(v, n, s);
       }
   };

   demandsalaryincrease.dequeue(v, n, s);
}

Heres que class for your convenience if you wanna see what it does.

class DynEmpQueue {
private:
   struct queueNode {
       int val;
       string name;
       float salary;
       queueNode *next;
   };

   queueNode *front, *rear;

public:

   DynEmpQueue() {
       front = NULL;
       rear = NULL;
   }

   bool isEmpty() {
       return(!front && !rear);
   }

   void enqueue(int v, string n, float s) {
       queueNode *newnode;
       newnode = new queueNode;
       newnode->val = v;
       newnode->name = n;
       newnode ->salary = s;
       newnode->next = NULL;
       if (isEmpty()) {
           front = newnode;
           rear = newnode;
       }
       else {
           rear->next = newnode;
           rear = newnode;
       }
   }

   void dequeue(int &v, string &n, float &s) {
       if (!isEmpty()) {
           v = front->val;
           n = front->name;
           s = front->salary;
           queueNode *tempnode;
           tempnode = front->next;
           delete front;
           front = tempnode;
       }
       else {
           cout << "Que empty cant dequeue";
       }
   }
};

Explanation / Answer

You need to use while to call it again and again

int main() {

   DynEmpQueue originalqueue;
   originalqueue.enqueue(123, "John Smith", 65000.0);
   originalqueue.enqueue(129, "Jane Smith", 55000.0);
   originalqueue.enqueue(154, "Johnson Smith", 76000.0);
   originalqueue.enqueue(223, "Janet Smith", 19000.0);
   originalqueue.enqueue(823, "Joe Smith", 94000.00);

   DynEmpQueue demandsalaryincrease;
   int v;
   string n;
   float s;

while(!originalqueue.isEmpty())
   {
       originalqueue.dequeue(v, n, s);

       if (s<50000) {
           demandsalaryincrease.enqueue(v, n, s);
       }
   }

}

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