Question

Subject: C++ I have created a class called QueueOfIntegers in a file called QueueOfIntegers.h, which is...

Subject: C++

I have created a class called QueueOfIntegers in a file called QueueOfIntegers.h, which is here:

#ifndef QueueOfIntegers_H
#define QueueOfIntegers_H

class QueueOfIntegers {
public:
   int elements[100]; //Array to store integers in the queue
   int size; // Number of integers in the queue

   QueueOfIntegers(); // Construct an empty queue
   bool IsEmpty(); // Returns true if the queue is empty
   int Peek(); // Returns the integer at the beginning of the Queue without removing it
   void Enqueue(int value); // Adds an integer to the end of the Queue
   int Dequeue(); // Remove and returns the object at the beginning of the Queue.
   int GetSize(); // Returns the number of integers in the queue
};
#endif

I also have another file called QueueOfIntegers.cpp that defines the functions which will need to be filled out:

#include "QueueOfIntegers.h"

QueueOfIntegers::QueueOfIntegers()
{
}

bool QueueOfIntegers::IsEmpty()
{
   if (size = 0) {
       return true;
   }
}

int QueueOfIntegers::Peek()
{
   return 0;
}

void QueueOfIntegers::Enqueue(int value)
{
   return 0;
}

int QueueOfIntegers::Dequeue()
{
   return 0;
}

int QueueOfIntegers::GetSize()
{
   return size;
}

I need to make an int main() function file called MainQueueOfIntegers.cpp and it needs to do the following:

  1. Add 10 random integers to the queue
  2. Use a loop to print out all integers in the queue (use IsEmpty() function)

Will be working on this tonight and tomorrow night but I could use some outside assistance. Thanks!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is your answer...code in c++

QueueOfIntegers.h

#ifndef QueueOfIntegers_H
#define QueueOfIntegers_H

class QueueOfIntegers {
public:
   int elements[100]; //Array to store integers in the queue
   int size; // Number of integers in the queue

   QueueOfIntegers(); // Construct an empty queue
   bool IsEmpty(); // Returns true if the queue is empty
   int Peek(); // Returns the integer at the beginning of the Queue without removing it
   void Enqueue(int value); // Adds an integer to the end of the Queue
   int Dequeue(); // Remove and returns the object at the beginning of the Queue.
   int GetSize(); // Returns the number of integers in the queue
};
#endif

QueueOfIntegers.cpp

#include "QueueOfIntegers.h"
QueueOfIntegers::QueueOfIntegers()
{
size=0;
}

bool QueueOfIntegers::IsEmpty()
{
if (size ==0) {
return true;
}
return false;
}

int QueueOfIntegers::Peek()
{
return elements[2];
}

void QueueOfIntegers::Enqueue(int value)
{
size++;
elements[size]=value;
}

int QueueOfIntegers::Dequeue()
{
int dq=elements[1];
for(int i=2;i<=size;i++)
elements[i-1]=elements[i];
size--;
return dq;
}

int QueueOfIntegers::GetSize()
{
return size;
}

MainQueueOfIntegers.cpp

#include <iostream>
#include "QueueOfIntegers.cpp"
#include "QueueOfIntegers.h"
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
//create QueueOfIntegers object
QueueOfIntegers Que;
//seed to generate different different random number
srand(unsigned(time(0)));
//Enqueue 10 random number
cout<<"\n**************Enqueue Queue element*************************************\n"<<endl;
for(int i=0;i<10;i++)
{
int randomInt=rand();
cout<<randomInt<<" ";
Que.Enqueue(randomInt);
}
//print queue element
cout<<"\n\n****************print Queue element************************************************\n"<<endl;
while(!Que.IsEmpty())
{
cout<<Que.Dequeue()<<" ";
}
cout<<endl;
return 0;
}

//output

Add a comment
Know the answer?
Add Answer to:
Subject: C++ I have created a class called QueueOfIntegers in a file called QueueOfIntegers.h, which is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class...

    1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class for integer stacks. 2. (20’) In stackTest.cpp, complete the implementation of function postfixTest(), which use an integer stack to evaluate post-fix expressions. For simplicity, you can assume the post-fix expression is input character by character (i.e., not an entire string), and each operand is a non-negative, single-digit integer (i.e., 0,1,…,9). However, you are supposed to detect invalid/ illegal post-fix expression input, e.g., “4 5...

  • How do I pass values to this function? class DynIntQueue { struct QueueNode { int value;...

    How do I pass values to this function? class DynIntQueue { struct QueueNode { int value; QueueNode *next; QueueNode(int value1, QueueNode *next1 = nullptr) { value = value1; next = next1; } }; // These track the front and rear of the queue QueueNode *front; QueueNode *rear; public: // Constructor and Destructor DynIntQueue(); ~DynIntQueue(); // Member functions void enqueue(int); void dequeue(int &); bool isEmpty() const; void clear(); }; main #include <iostream> #include "DynIntQueue.h" using namespace std; int main() {DynIntQueue list;...

  • Array-based Queue Lecture 6 Two Class Exercises | Class Exercise #1 - Create an array-based queue that holds value...

    Array-based Queue Lecture 6 Two Class Exercises | Class Exercise #1 - Create an array-based queue that holds values of double data type. 1.) Create a program that produces the following output OUTPUT: Q Quit Enter your choice: e Enter an item: 1.1 E Enqueue D Dequeue s-show queue ← showMenuO function called in main) OQuit // screen clears-.. continue enqueuing.screen clearing with each iteration Enter your choice: e Queue is full. E Enqueue D Dequeue s Show queue 0...

  • how do I change my code to generic form *********************************************************************** public class UnboundedStackQueue { //question#3 }...

    how do I change my code to generic form *********************************************************************** public class UnboundedStackQueue { //question#3 } class Stack { Node head; int size; Stack() //default constructor { this.head=null; this.size=0; } //Input = data //Output = void (just adds value to list) // method pushes elements on stack // time: O(1) // space: O(1) public void push(int data) { Node node=new Node(data); node.next=head; head=node; size++; } //Input = none //Output = top of stack // method pops value from top of...

  • I need help fixing my code.   My output should be the following. Hello, world! : false...

    I need help fixing my code.   My output should be the following. Hello, world! : false A dog, a panic in a pagoda : true A dog, a plan, a canal, pagoda : true Aman, a plan, a canal--Panama! : true civic : true If I had a hi-fi : true Do geese see God? : true Madam, I’m Adam. : true Madam, in Eden, I’m Adam. : true Neil, a trap! Sid is part alien! : true Never odd...

  • Create a program named NonZeroNumQueue.java then copy the contents from NonZeroNumQueue.txt. Then implement enqueue method. To...

    Create a program named NonZeroNumQueue.java then copy the contents from NonZeroNumQueue.txt. Then implement enqueue method. To get credit, DO NOT add or alter any data members/methods except the enqueue(int num). The NonZeroNumQueue will NOT accept zero, which mean you can enqueue any whole numbers EXCEPT 0(zero). You have already noticed that the queue is NEVER full, so the isFull() always returns false. given NonZeroNumQueue.txt public class NonZeroNumQueue{ private int[] data; private int total; private int front; private int tail; public...

  • Are based on the following Queue class code segment class QueueFull {/* Empty exception class */};...

    Are based on the following Queue class code segment class QueueFull {/* Empty exception class */}; Class Queue Empty {/* Empty exception class */}; struct Node//Node structure int data;//Holds an integer Node* next;//Pointer to next node in the queue}; Class Queue//Linked node implementation of Queue ADT {Private: Node* front;//Pointer to front node of queue Node* rear;//pointer to last node of queue Public: Queue ()://default constructor initializes queue to be empty -Queue ();//Deallocates all nodes in the queue Void Add (int...

  • e. public class Queue { // Uses the correct Stack class from ME2 Ex 19 private Stack mStack; public Queue() { setStack(new Stack()); } public Queue enqueue(E pData) { getStack().push(pData); return t...

    e. public class Queue { // Uses the correct Stack class from ME2 Ex 19 private Stack mStack; public Queue() { setStack(new Stack()); } public Queue enqueue(E pData) { getStack().push(pData); return this; } public E dequeue() { return getStack().pop(); } public E peek() { return getStack.peek(); } private Stack getStack() { return mStack; } private void setStack(Stack pStack) { mStack = pStack; } } f. public class Queue extends Stack { // Uses the correct Stack class from ME2 Ex...

  • PROBLEM- void CBQueue::printF2B( ) If the queue is empty, the method should print “Queue is empty”,...

    PROBLEM- void CBQueue::printF2B( ) If the queue is empty, the method should print “Queue is empty”, otherwise, this method should print the items in the queue starting at the front of the queue and proceeding to the rear of the queue. The items should be printed one per line. Now that this method is written, you can do a more thorough job of testing enqueue( ). You will want to call printF2B( ) and printB2F( ) after implementing each method...

  • PROBLEM: string CBQueue::dequeue( ) This method should remove and return the item at the front of...

    PROBLEM: string CBQueue::dequeue( ) This method should remove and return the item at the front of the queue- please add comments EXISTING CODE: #include // this allows you to declare and use strings #include using namespace std; struct qNode {   string data;   qNode* next;   qNode* prev; }; class CBQueue {   public:     CBQueue(); int CBQueue::getSize( ); bool CBQueue::isEmpty( );   private:     qNode* front;     qNode* rear;     int size; }; #include "CBQueue.h" CBQueue::CBQueue() { front = NULL; rear = NULL; size = 0; }...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT