Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We need this output and fix any code errors. // corre.cpp : Defines the entry point for the console application. // #include stdafx.h #include #include

We need this output and fix any code errors.

// corre.cpp : Defines the entry point for the console application. //

#include "stdafx.h" #include #include using namespace std;

class Queue { private: char *queueArray; int queueSize; int front; int rear; int numItems; public: Queue(int); Queue(const Queue &); ~Queue();

void enqueue(char); void dequeue(char &); bool isEmpty() const; bool isFull() const; void clear(); };

Queue::Queue(int s) { queueArray = new char[s]; queueSize = s; front = -1; rear = -1; numItems = 0; }

Queue::Queue(const Queue &obj) { queueArray = new char[obj.queueSize];

queueSize = obj.queueSize; front = obj.front; rear = obj.rear; numItems = obj.numItems;

for (int count = 0; count < obj.queueSize; count++) queueArray[count] = obj.queueArray[count]; }

Queue::~Queue() { delete[] queueArray; }

void Queue::enqueue(char num) { if (isFull()) cout << "The queue is full. "; else { rear = (rear + 1) % queueSize; queueArray[rear] = num; numItems++; } }

void Queue::dequeue(char &num) { if (isEmpty()) cout << "The queue is empty. "; else { front = (front + 1) % queueSize; num = queueArray[front]; numItems--; } }

bool Queue::isEmpty() const { bool status; if (numItems) status = false; else status = true; return status;

}

bool Queue::isFull() const { bool status;

if (numItems < queueSize) status = false; else status = true; return status;

}

void Queue::clear() { front = queueSize - 1; rear = queueSize - 1; numItems = 0; }

int main() { const int SIZE = 51; char fileName[SIZE]; char ch;

fstream file1; fstream file2;

Queue queue1(30); Queue queue2(30);

cout << "Enter a file name: "; cin >> fileName;

file1.open(fileName, ios::in); if (!file1) { cout << fileName << "could not be opened. "; return 0; } int fcount1 = 0;

file1.get(ch); while (!file1.eof()) { queue1.enqueue(ch); file1.get(ch); fcount1++; } cout << " Entera file name to be compared: "; cin >> fileName;

file2.open(fileName, ios::in); if (!file2) { cout << fileName << "could not be opend. "; return 0; } char c; int fcount2 = 0; file2.get(c); while (!file2.eof()) { queue2.enqueue(c); file2.get(c); fcount2++; }

if (fcount1 == fcount2) { while (!queue1.isEmpty() && !queue2.isEmpty()) { queue2.dequeue(c); queue1.dequeue(ch);

if (c != ch) { cout << "Two files not same" << endl; break; } if (queue1.isEmpty() && queue2.isEmpty()) cout << "countents of files are same" << endl; }

} else cout << "Two files are not same" << endl; cout << endl; file2.close();

system("pause"); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

What is Accounting?

Answered: 1 week ago

Question

Define organisation chart

Answered: 1 week ago

Question

What are the advantages of planning ?

Answered: 1 week ago

Question

Define human resource management.

Answered: 1 week ago