Question: WHAT TO DO: Create three Queue objects: one of integers, one of strings, and one of a custom data type (ideally the type you created

 WHAT TO DO: Create three Queue objects: one of integers, one

WHAT TO DO:

Create three Queue objects: one of integers, one of strings, and one of a custom data type (ideally the type you created in Project 1).

Demonstrate that the Queue methods work correctly by calling methods on the objects and printing out to the console when appropriate.

Below is the Queue class. The Queue class uses the Node class, which is also listed.

UPDATE: I'm not quite sure what is meant when you say Node.h needs to be specified more. It was pre-written by my professor specifically to write the Queue class.

Node.h:

#ifndef NODEB_NODE_H #define NODEB_NODE_H /** Represents one node to be used in a linked list  Contains data (object) and reference to next in list */  templatetypename Object> class Node { private: Object item; Node* next; public: Node(Object newItem) { item = newItem; next = nullptr; } Node(Object newItem, Node* nextNode) { item = newItem; next = nextNode; } void setItem(Object newItem) { item = newItem; } Object getItem() const { return item; } void setNext(Node* nextNode) { next = nextNode; } Node* getNext() const { return next; } }; #endif //NODEB_NODE_H

Queue.h:

 #ifndef NODEB_QUEUE_H #define NODEB_QUEUE_H /*  * Queue class  * Functionality: push, pop, peek, isEmpty, print  */  #include "Node.h" #include  using namespace std; templatetypename Object> class Queue { private: // Store the address of the top Node in the Queue  Node* top; Node* down; public: // Constructor  Queue() { // Queue is empty. Top doesn't point at anything.  top = nullptr; down = nullptr; } // Deconstructor / Destructor  ~Queue() { // Pop all the Nodes left in the Queue  while (!isEmpty()) { pop(); } } bool isEmpty() const { return (top== nullptr); } void push(Object item) { if (isEmpty()) { // This is the first Node in the Queue  // Allocate memory in the heap to store the new Node  Node* newNode = new Node(item); // Update top  top = newNode; down=top; } else { // There is already at least one Node in the Queue  Node* newNode = new Node(item); // Update down  down->setNext(newNode) down = newNode; } } Object pop() { if (isEmpty()) { // There is no Node to pop. Return the default Object.  // Note: This assumes the Object has a default constructor.  return Object(); } else { // There is at least one Node in the Queue.  // Store a copy of the Object to be returned  Object copy = top->getItem(); // Store a copy of top  Node* topCopy = top; // Update top to point at whatever the Node we are about to delete is pointing at  top = top->getNext(); // Delete the Node from heap memory  // Use the delete keyword with a pointer to the memory you want to deallocate from the heap  delete topCopy; // Return the Object  return copy; } } bool exists(Object item) const { Node* curr = top; while (curr != nullptr) { // Note: This assumes the Object can use the == operator  if (curr->getItem() == item) { // Found the item in the Stack  return true; } curr = curr->getNext(); } // Did not find the item in the Stack  return false; } void printQueue() const { Node* curr = top; while (curr != nullptr) { // Note: This assumes that the Object can use the  cout getItem() getNext(); } } }; #endif //NODEB_QUEUE_H 

Now, the directions also reference a Project 1. Below is the code for that. Basically, I wrote code that takes a text file containing information on different football players and their combine results and stores those players as a vector of objects of the class.

Combine.h:

#include #include #include #include #include #include using namespace std; class Combine { private: string name, college, pos; int height, weight; float dash, bench; public:  Combine() { name = "John Smith"; college = "University"; pos = "player"; height = 0; weight = 0; dash = 0; bench = 0; } Combine(string name, string college, string pos, int height, int weight, float dash, float bench) { this->name = name; this->college = college; this->pos = pos; setHeight(height); setWeight(weight); setDash(dash); setBench(bench); }   string getName() const { return name; } string getCollege() const { return college; } string getPos() const { return pos; } int getHeight() const { return height; } int getWeight() const { return weight; } float getDash() const { return dash; } float getBench() const { return bench; }   void setName(string name) { this->name = name; } void setCollege(string college) { this->college = college; } void setPos(string pos) { this->pos = pos; } void setHeight(int height) { if (height //Default value  this->height = 0; } else { this->height = height; } } void setWeight(int weight) { if (weight   this->weight = 0; } else { this->weight = weight; } } void setDash(float dash) { if (dash   this->dash = 0; } else { this->dash = dash; } } void setBench(float bench) { if (bench //Default value  this->bench = 0; } else { this->bench = bench; } }   friend ostream& operator void getPlayersFromFile(string filename, vector &players) { ifstream inFile;  inFile.open("../" + filename);   string name = "", college = "", pos = "", header = ""; string temp; int height = 0, weight = 0; float dash = 0, bench = 0; char comma = ',';   if (inFile) {  getline(inFile, header);  while (inFile && inFile.peek() != EOF) {  getline(inFile,temp);  stringstream ss(temp);  getline(ss,name,',');  getline(ss,college,',');  getline(ss,pos,',');  getline(ss,temp,','); height = atoi(temp.c_str());  getline(ss,temp,','); weight = atoi(temp.c_str()); if(ss.good()) {  getline(ss,temp,','); dash = atof(temp.c_str()); } else{ dash=0; } if(ss.good()) {  getline(ss,temp,','); bench = atof(temp.c_str()); } else{ bench=0; }  players.push_back(Combine(name, college, pos, height, weight, dash, bench)); } } else { cerr  float avgWeight(vector &players) { float total = 0; getPlayersFromFile("CombinePlayers.txt", players); for (int i = 0; i   } cout  

CombinePlayers.txt:

Name, College, POS, Height (in), Weight (lbs), 40 Yard, Bench Press Johnathan Abram, Mississippi State, S, 71, 205, 4.45, 0 Paul Adams, Missouri, OT, 78, 317, 5.18, 16 Nasir Adderley, Delaware, S, 72, 206, , 0 Azeez Al-Shaair, Florida Atlantic, LB, 73, 234, , 16 Otaro Alaka, Texas A&M, LB, 75, 239, 4.82, 20 Dakota Allen, Texas Tech, LB, 73, 232, 4.77, 23 Josh Allen, Kentucky, EDG, 77, 262, 4.63, 28 Zach Allen, Boston College, DE, 76, 281, 5, 24
Create three Queue objects: one of integers, one of strings, and one of a custom data type (ideally the type you created in Project 1). Demonstrate that the Queue methods work correctly by calling methods on the objects and printing out to the console when appropriate. Create three Queue objects: one of integers, one of strings, and one of a custom data type (ideally the type you created in Project 1). Demonstrate that the Queue methods work correctly by calling methods on the objects and printing out to the console when appropriate

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!