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

C++ programming help I\'m trying to show that the symbols read are \"A\" and \"D

ID: 656682 • Letter: C

Question

C++ programming help

I'm trying to show that the symbols read are "A" and "D" and  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 reaches end of file, it should print out the contents of the queue. Using enqueue and dequeue.

My desired output should be: 5 9 7

Here is my code:

#include <iostream>
#include <fstream>
#include "IQueue.h"
using namespace std;

int main(int argc, char* argv[])
{
// need some help here I'm also trying to do this at the time.

return 0;
}

Explanation / Answer

#include <iostream>
#include <fstream>
#include "IQueue.h"
using namespace std;
int main(int argc, char* argv[])
{
// need some help here I'm also trying to do this at the time.
ifstream inf(argv[1]);
if (!inf)
{
cerr << "Can't open input file " << argv[1] << endl;
return 1;
}
// I need some HELP here with code it needs to also close the file..
IQueue intQueue; // Assuming IStack is stack of integers.
char ch; int k;
while(!inf.eof()){
   inf >> ch >> k;
   if(ch == 'A')
       intQueue.enque(k);
   else if(ch=='D')
       intQueue.deque();
}
inf.close(); // close file.
while(!intQueue.empty()){    // print remaining elements of stack.
   cout << intQueue.top() << " ";
   intQueue.deque();
}
cout << endl;

return 0;
}

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