Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NEED HELP WITH C++ The objective of this programming assignment is to continue to practice your C++ programming skills. In this programming assignment, you will

NEED HELP WITH C++

The objective of this programming assignment is to continue to practice your C++ programming skills. In this programming assignment, you will implement an abstract data type queue, and test its functionality by writing some test programs in main.cpp.

A queue is a container of objects that are inserted and removed according to the first-in-first-out principle. The header file Qqueue.h will be provided to you. Qqueue.h is the header file that specifies the interface of the abstract data type queue that you need to implement. You must implement all the functions in Qqueue.h. The following basic operations and some other supportive operations must be supported by the ADT Queue.

Enqueue -- Add an element to the end (rear, back) of the queue

Dequeue -- Remove an element from the front of the queue

front -- return the element that is on the front of the queue (DO NOT remove it)

back -- return the element that is on the end of the queue (DO NOT remove it)

isEmpty -- Check whether the queue is empty or not

size: returns the number of elements stored in the queue

A queue can be implemented in many ways. Here, we consider implementing the queue using a dynamic array of a given size, i.e., there is a limit on the number of objects the queue can hold. The size of the queue should be specified by the programmer or using a default size while creating the queue.

To test the queue of the string type, a file all.last.txt with a lot of last names is provided to you. In your main.cpp, you will write code to test all the member functions of the queue ADT. In your main.cpp, you should first create a queue of type string whose capacity is specified by you (should be in the order of 100 or larger). Then read the last names from all.last.txt and enqueue the last names to the queue. In other words, in the beginning of your main() function, you should open the input file, create a queue: prompt the user for the capacity of the queue (should be in the order of 100 or larger). Then read the specified number (10 90) of the last names from the input file, all.last.txt, and enqueuer these last names into the stack. The number of last names enqueued to the queue should be less than the capacity of the queue. After you enqueue the last names onto the queue, you should test ALL the other functions in queue.h. You should print out a message describing the operation you tested.

Then you should create a queue using the copy constructor with the specified capacity. After you modify the second queue by enqueue and dequeuer operations, then you can test the equal( ) function.

To reiterate, in your main() function, you will test the queue ADT stated as follows:

1. Enqueue: prompt user for a last name, and enqueue it to the back (end) of the queue if the queue is not full.

2. Dequeue: dequeue the element from the back (rear) of the queue (if the queue is not empty), and print the element to the screen.

3.Front: return the element from the front of the queue (if the queue is not empty), and print the element to the screen.

4. Back: return the element from the back (rear) of the queue (if the queue is not empty), and print the element to the screen.

5. Equal: Returns true if the two queues contain the same elements in the same order.

6. Print: Print all the elements in the queue onto the screen.

7. Save: save all the elements in the queue to a file on the disk.

Header file content Qqueue.h

****************************************************************************

****************************************************************************

#ifndef _QueueClass_ #define _QueueClass_

#include #include

class Qqueue { public: // Constructor Qqueue( int cap);

// Copy Constructor Qqueue( const Qqueue& s );

~Qqueue( ); //destructor // The member function enqueue: Precondition: the queue is not full. If the queue is full, this function signals an error. //add value to the end of the queue void enqueue ( const std::string& s);

// The member function dequeue: Precondition: the queue is not empty. If the queue is empty, this function signals an error. // Removes and returns the first item in the queue. std::string dequeue ();

// The member function front: Precondition: the queue is not empty. std::string& getfront () const; // The member function back: Precondition: the queue is not empty. std::string& getback () const;

bool IsEmpty () const;

//printing all the elements in the queue void print() const;

int size() const;

int getCapacity() const;

//Returns true if the two queues contain exactly the same element values in the same order. Identical in behavior to the == operator. bool equals(const Qqueue& q) const; // Usage: if (q.equals(q2)) ...

private: int Capacity; // Capacity is the maximum number of items that a queue can hold std::string* DynamicQueue; int num; // How many items are stored in the queue int front; int back; };

#endif

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_2

Step: 3

blur-text-image_3

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

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

Define organisational structure

Answered: 1 week ago

Question

Define line and staff authority

Answered: 1 week ago

Question

Define the process of communication

Answered: 1 week ago

Question

Explain the importance of effective communication

Answered: 1 week ago

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago