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

QUEUE ENQUEUE, DEQUEUE THIS IS C++ PROGRAMMING ASSIGNMENT: You have been supplie

ID: 3575110 • Letter: Q

Question

QUEUE ENQUEUE, DEQUEUE

THIS IS C++ PROGRAMMING ASSIGNMENT:

You have been supplied an IQueue Class with the following characteristic:

1. It holds only integers.

2. It is almost identical with QueueElement typedef'd to int

You have been supplied a file with a data in it (data1.txt). Each line contains a symbol (A or D) and an integer. If an A is read, the following integer should be enqueued. If a D is read, the following integer is ignored and an item is dequeued. When your program reached end of file, it should print out the contents of the queue. With the supplied data1.txt file, the output should be:

5 9 7

Your grader may, of course replace data1.txt with a file of his choice to check the code if it works the right way.

MORE INSTRUCTIONS:

CURRENT PROGRAM:

DATA1.TXT FILE:

Problem 4. Queue enqueue, dequeue You have been supplied an IQueue class with the following characteristics 1. It holds only integers 2. It is almost identical to the textbook's Fig 8. 1, with the Queue Element type def'd to int You have been supplied a file with data in it (datal.txt) Each line contains a symbol (A or D) and an integer If an A is read, the following integer should be enqueued. If a D is read, the following integer is ignored and an item is de queued. When your program reaches end of file, it should print out the contents of the queue. With the supplied datal. txt file, the output should be (not including the comment marks, of course) Your grader may of course, replace datal. txt with a file of his own, to make sure you haven't faked out" the code

Explanation / Answer

IQueue.h :-

#include<iostream>
using namespace std;

struct node{

    int info;

    struct node *next;

};

class Queue{

    private:

        node *rear;

        node *front;

    public:

        Queue();

        void enqueue(int );

        void dequeue();

        void display();

};

Queue::Queue(){

    rear = NULL;

    front = NULL;

}

void Queue::enqueue(int data){

    node *temp = new node;


    temp->info = data;

    temp->next = NULL;

    if(front == NULL){

        front = temp;

    }else{

        rear->next = temp;

    }

    rear = temp;

}

void Queue::dequeue(){

    node *temp = new node;

    if(front == NULL){

        cout<<" Queue is Emtpty ";

    }else{

        temp = front;

        front = front->next;

        delete temp;

    }

}

void Queue::display(){

    node *p = new node;

    p = front;

    if(front == NULL){

        cout<<" Nothing to Display ";

    }else{

        while(p!=NULL){

            cout<<p->info << " ";
            p = p->next;

        }

    }

}

current.cpp :-

#include<iostream>
#include<fstream>
#include "IQueue.h"
#include<cstdlib>

using namespace std;


int main(){

    Queue queue;

    int choice;
   string line;
   ifstream myfile ("Data1.txt");
if (myfile.is_open())
{
   while ( getline (myfile,line) )
    {
    if(line[0] == 'A'){
           queue.enqueue(line[2]-48);
      }
      else{
           queue.dequeue();
      }
   }
    myfile.close();
    queue.display();
}
else cout << "Unable to open file";

    return 0;

}