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

C++ programming. I am getting error please help In this program you will use the

ID: 3809905 • Letter: C

Question

C++ programming. I am getting error please help

In this program you will use the stack class you created in Assignment 1. First you will create a class called InventoryItem. This class will have its class declaration in InventoryItem.h and its implementation in InventoryItem.cpp. It will have three private data members, an integer serialNum which holds the part’s serial number, manufactDate which should be a string that holds the date the item was manufactured, then lotNum which will be an integer that holds the part’s lot number. The program should then create a stack with a data type of InventoryItem (stack). The program should loop asking the user to enter in new items to the inventory stack or to remove an item from the inventory stack. The loop should continue until the user indicates they are done. This should be menu driven. When adding an item, the program should ask the user for the information it needs for the 3 data members of the InventoryItem class and add a new item to the stack. When removing an item from the stack, the program should display all of the information in the InventoryItem object that was popped off the stack. When the program ends, it should pop all of the remaining items off the stack and display the data that is in the Inventory items as it pops them off. There should be 3 utility functions that main uses.

void popItem(DynStack* stack) // pops the item off the stack and displays it.

void pushItem(DynStack* stack) // pushes the item onto the stack

int menu(); // displays the menu and returns the user’s choice.

This is what I have. Please help me fix error.

//For Main.cpp

#include "DynStack.h"

#include "InventoryItem.h"

#include <iostream>

using namespace std;

void popItem(DynStack<InventoryItem>*);

void pushItem(DynStack<InventoryItem>*);

int menu(); // displays and returns the choice of the user.

int main()

{

   DynStack<InventoryItem>* invStack;

   invStack = new DynStack<InventoryItem>;

   // Holds the menu selection from menu()

   int menuChoice = 0;

   // Variable for menu loop

   bool valid = true;

   // Values for switch statement

   const int ADDITEM = 1;

   const int REMITEM = 2;

   const int EXIT = 3;

   // Used when printing out contents upon program exit

   InventoryItem temp;

   while (valid)

   {

       menuChoice = menu();

       switch (menuChoice)

       {

       case ADDITEM: // to add items to the stack

           pushItem(invStack);

           valid = true;

           break;

       case REMITEM: // to remove items from the stack and display their contents

           popItem(invStack);

           valid = true;

           break;

       case EXIT:

           // On exit, any inventory must be popped off the stack and

           // printed, in sequence. Otherwise the program simply ends.

           if (invStack->isEmpty() != true)

           {

               cout << "Here are the remaining items in inventory: ";

               while (invStack->pop(temp) == true) // Loop runs until stack is empty

               {

                   cout << "Lot Number: " << temp.getLotNum() << " ";

                   cout << "Serial Number: " << temp.getSerNum() << " ";

                   cout << "Manufacturing Date: " << temp.getManDate() << " ";

               }

               // Display msg once all nodes are popped off

               if (invStack->isEmpty() == true)

                   cout << "No further inventory. ";

           }

           else

               cout << "No inventory to display; exiting program. ";

           return 0;

       }

   }

   return 0;

}

// For popItem

void popItem(DynStack<InventoryItem>* stack)

{

   InventoryItem temp;

   char repeat = 'y'; // to control the loop

                     

   while (repeat == 'y' || repeat == 'Y')

   {

       if (stack->pop(temp) == true)

       {

  

           cout << " Remove Item ";

           cout << "Lot Number: " << temp.getLotNum() << " ";

           cout << "Serial Number: " << temp.getSerNum() << " ";

           cout << "Manufacturing Date: " << temp.getManDate() << " ";

           cout << "Remove and display another item y/n? ";

           cin >> repeat;

       }

       else // If stack is empty, display error message

       {

           cout << "No items in Remaining. ";

           repeat = 'n'; // Set repeat to n to return to main menu

       }

   }

}

// For pushItem

void pushItem(DynStack<InventoryItem>* stack)

{

   InventoryItem temp;

   int lNum, sNum;

   string manDate;

   char repeat = 'y'; // to control the loop

   while (repeat == 'y' || repeat == 'Y')

   {

       cout << "| Add Item | ";

       cout << "Enter lot number: ";

       // Verifing the input

       cin >> lNum;

       while (lNum < 0)

       {

           cout << "Lot number must be a non-negative number. ";

           cout << "Enter lot number: ";

           cin >> lNum;

       }

       cout << "Enter serial number: ";

       cin >> sNum;

       while (sNum < 0)

       {

           cout << "Serial number must be a non-negative number. ";

           cout << "Enter serial number: ";

           cin >> sNum;

       }

       cout << "Enter manufacturing date in MM/DD/YYYY format: ";

       cin >> manDate;

       temp.setLotNum(lNum);

       temp.setSerNum(sNum);

       temp.setManDate(manDate);

       stack->push(temp);

       cout << "Add another item to inventory y/n? ";

       cin >> repeat;

   }

}

int menu() // displays the menu and returns the user’s choice.

{

   int choice;

   cout << "------------------------- ";

   cout << "| Inventory item Menu | ";

   cout << "------------------------- ";

   cout << "1) Add item to the Inventory ";

   cout << "2) Remove item from Inventory ";

   cout << "3) Exit program ";

   cout << "Selection number: ";

   cin >> choice;

   // Check that it's a valid choice

   while (choice <= 0 || choice > 3)

   {

       cout << "Invalid choice. Pick 1, 2, or 3: ";

       cin >> choice;

   }

   return choice;

}

//For DynStack.h

#pragma once

// Declaration file for the DynStack class. This class is a template version of

// a dynamic stack class.

#ifndef DYNSTACK_H

#define DYNSTACK_H

template <class T>

class DynStack

{

private:

   // Struct for stack nodes

   struct StackNode {

       T value; // holds the node's value

       StackNode *next; // ptr to next node

   };

   StackNode *top; // ptr to stack top

public:

   // Constructor

   DynStack();

   // Destructor

   ~DynStack();

   // Stack operations

   void push(T);

   bool pop(T &);

   bool isEmpty();

   void displayStack() const;

};

#endif

//For DynStack.cpp

/************ DynStack.h ***********/

/* This file contains the decleration of DynStack class */

// Declaration file for the DynStack class. This class is a template version of

// a dynamic stack class.

#ifndef DYNSTACK_H

#define DYNSTACK_H

template <class T>

class DynStack

{

private:

   // Struct for stack nodes

   struct StackNode {

       T value; // holds the node's value

       StackNode *next; // ptr to next node

   };

   StackNode *top; // ptr to stack top

public:

   // Constructor

   DynStack();

   // Destructor

   ~DynStack();

   // Stack operations

   void push(T);

   bool pop(T &);

   bool isEmpty();

   void displayStack() const;

};

#endif

/************ DynStack.cpp ***********/

// This file contains Implementation for the DynStack class. This class is a template version of

// a dynamic stack class.

#include "DynStack.h"

// Default constructor

template <class T>

DynStack<T>::DynStack()

{

   top = nullptr;

}

// Destructor - deletes the stack node by node

template <class T>

DynStack<T>::~DynStack()

{

   StackNode *nodePtr;

   StackNode *nextNode;

   // aim nodePtr at top of stack

   nodePtr = top;

   // travel list and delete each node

   while (nodePtr != nullptr)

   {

       nextNode = nodePtr->next;

       delete nodePtr;

       nodePtr = nextNode;

   }

}

///////////////////////

// Stack operations //

/////////////////////

// push() adds the argument onto the stack

template <class T>

void DynStack<T>::push(T item)

{

   StackNode *newNode = nullptr;

   // Creates a new node and stores argument there

   newNode = new StackNode;

   newNode->value = item;

   // If the list is empty, make newNode the first node

   if (isEmpty() == true)

   {

       top = newNode;

       newNode->next = nullptr;

   }

   else

   {

       newNode->next = top;

       top = newNode;

   }

}

// If the stack is empty, then pop() simply returns false.

// If a node exists, pop() returns the top item, deletes it from the stack,

// and then returns true.

template <class T>

bool DynStack<T>::pop(T &item)

{

   StackNode *temp = nullptr;

   bool status;

   // Check that the stack isn't empty

   if (isEmpty() == true)

   {

       status = false;

   }

   else // Pop value off top of stack

   {

       item = top->value;

       temp = top->next;

       delete top;

       top = temp;

       status = true;

   }

   return status;

}

// isEmpty() returns true if stack is empty; otherwise it returns false.

template <class T>

bool DynStack<T>::isEmpty()

{

   bool status;

   if (!top)

       status = true;

   else

       status = false;

   return status;

}

// displayStack() simply prints each item in a given stack.

template <class T>

void DynStack<T>::displayStack() const

{

   StackNode *nodePtr;

   nodePtr = top;

   if (nodePtr == nullptr)

       cout << "Stack is empty.";

   else

   {

       while (nodePtr)

       {

           cout << nodePtr->value << endl;

           nodePtr = nodePtr->next;

       }

   }

}

//For InventoryItem.h

#pragma once

#ifndef INVENTORYITEM_H

#define INVENTORYITEM_H

#include <string>

using namespace std;

class InventoryItem

{

private:

   int serialNum;

   string manufactDate;

   int lotNum;

public:

   // Default Constructor

   InventoryItem();

   // Parameterized Constructor - serialNum, manufactDate, lotNum

   InventoryItem(int, string, int);

   // Methods to read the data from user

   int getSerNum() const;

   string getManDate() const;

   int getLotNum() const;

   // Methods to set the data

   void setSerNum(int);

   void setManDate(string);

   void setLotNum(int);

};

#endif

//For Inventoryitem.cpp

#include "InventoryItem.h"

// Default constructor

InventoryItem::InventoryItem()

{

}

// Parameterized Constructor - serialNum, manufactDate, lotNum

InventoryItem::InventoryItem(int Snum, string ManD, int Lnum)

{

   serialNum = Snum;

   manufactDate = ManD;

   lotNum = Lnum;

}

// get functions or Accessors

int InventoryItem::getLotNum() const

{

   return lotNum;

}

int InventoryItem::getSerNum() const

{

   return serialNum;

}

string InventoryItem::getManDate() const

{

   return manufactDate;

}

// set functions or Mutators

void InventoryItem::setLotNum(int lNum)

{

   lotNum = lNum;

}

void InventoryItem::setSerNum(int sNum)

{

   serialNum = sNum;

}

void InventoryItem::setManDate(string manu)

{

   manufactDate = manu;

}

Explanation / Answer

#include "DynStack.h"
#include "InventoryItem.h"
#include &lt;iostream&gt;

using namespace std;

void popItem(DynStack&lt;InventoryItem&gt;*);
void pushItem(DynStack&lt;InventoryItem&gt;*);
int menu(); // displays and returns the selection of the user.

int main()
choice from menu()
int menuChoice = 0;

// Variable for menu loop
bool valid = true;

// Values for switch statement
const int ADDITEM = 1;
const int REMITEM = 2;
const int EXIT = 3;

// Used once printing out contents upon program exit
InventoryItem temp;

whereas (valid)
to feature things to the stack
pushItem(invStack);
valid = true;
break;

case REMITEM: // to get rid of things from the stack and show their contents
popItem(invStack);
valid = true;
break;

case EXIT:
// On exit, any inventory should be popped off the stack and
// printed, in sequence. Otherwise the program merely ends.

if (invStack-&gt;isEmpty() != true)
worker.getLotNum() &lt;&lt; " ";
cout &lt;&lt; "Serial Number: " &lt;&lt; temporary worker.getSerNum() &lt;&lt; " ";
cout &lt;&lt; "Manufacturing Date: " &lt;&lt; temporary worker.getManDate() &lt;&lt; " ";
}
// show flavoring once all nodes ar popped off
if (invStack-&gt;isEmpty() == true)
cout &lt;&lt; "No more inventory. ";
}
else
cout &lt;&lt; "No inventory to display; exiting program. ";

return 0;
}
}

return 0;
}

// For popItem
void popItem(DynStack&lt;InventoryItem&gt;* stack)
to manage the loop


whereas (repeat == 'y' || repeat == 'Y')
to regulate the loop

whereas (repeat == 'y' || repeat == 'Y')
price; // holds the node's value
StackNode *next; // ptr to next node
};
StackNode *top; // ptr to stack high
public:
// creator
DynStack();

// Destructor
~DynStack();

// Stack operations
void push(T);
bool pop(T &amp;);
bool isEmpty();
void displayStack() const;
};

#endif

//For DynStack.cpp
/************ DynStack.h ***********/
/* This file contains the decleration of DynStack category */

// Declaration file for the DynStack category. This category may be a model version of
// a dynamic stack category.
#ifndef DYNSTACK_H
#define DYNSTACK_H
template &lt;class T&gt;
class DynStack
price; // holds the node's value
StackNode *next; // ptr to next node
};
StackNode *top; // ptr to stack high
public:
// creator
DynStack();

// Destructor
~DynStack();

// Stack operations
void push(T);
bool pop(T &amp;);
bool isEmpty();
void displayStack() const;
};

#endif

/************ DynStack.cpp ***********/

// This file contains Implementation for the DynStack category. This category may be a model version of
// a dynamic stack category.

#include "DynStack.h"

// Default creator
template &lt;class T&gt;
DynStack&lt;T&gt;::DynStack()
{
high = nullptr;
}

// Destructor - deletes the stack node by node
template &lt;class T&gt;
DynStack&lt;T&gt;::~DynStack()
{
StackNode *nodePtr;
StackNode *nextNode;

// aim nodePtr at high of stack
nodePtr = top;

// travel list and delete every node
whereas (nodePtr != nullptr)
  
}
///////////////////////
// Stack operations //
/////////////////////

// push() adds the argument onto the stack
template &lt;class T&gt;
void DynStack&lt;T&gt;::push(T item)
a brand new node and stores argument there
newNode = new StackNode;
newNode-&gt;value = item;

// If the list is empty, create newNode the primary node
if (isEmpty() == true)
{
high = newNode;
newNode-&gt;next = nullptr;
}
else
{
newNode-&gt;next = top;
high = newNode;
}
}

// If the stack is empty, then pop() merely returns false.
// If a node exists, pop() returns the highest item, deletes it from the stack,
// and so returns true.
template &lt;class T&gt;
bool DynStack&lt;T&gt;::pop(T &amp;item)
{
StackNode *temp = nullptr;
bool status;

// ensure the stack is not empty
if (isEmpty() == true)
standing = false;
}
else // Pop price off high of stack
{
item = top-&gt;value;
temporary worker = top-&gt;next;
delete top;
high = temp;
standing = true;
}

come status;
}

// isEmpty() returns true if stack is empty; otherwise it returns false.
template &lt;class T&gt;
bool DynStack&lt;T&gt;::isEmpty()
{
bool status;

if (!top)
standing = true;
else
standing = false;

come status;
}

// displayStack() merely prints every item in a very given stack.
template &lt;class T&gt;
void DynStack&lt;T&gt;::displayStack() const
{
StackNode *nodePtr;

nodePtr = top;

if (nodePtr == nullptr)
cout &lt;&lt; "Stack is empty.";
else
{
whereas (nodePtr)
  
}
}

//For InventoryItem.h

#pragma once
#ifndef INVENTORYITEM_H
#define INVENTORYITEM_H

#include &lt;string&gt;
using namespace std;

class InventoryItem
{
private:
int serialNum;
string manufactDate;
int lotNum;
public:
// Default creator
InventoryItem();

// Parameterized creator - serialNum, manufactDate, lotNum
InventoryItem(int, string, int);

// strategies to browse the information from user
int getSerNum() const;
string getManDate() const;
int getLotNum() const;


// strategies to line the information
void setSerNum(int);
void setManDate(string);
void setLotNum(int);
};

#endif

//For Inventoryitem.cpp

#include "InventoryItem.h"

// Default creator
InventoryItem::InventoryItem()


// Parameterized creator - serialNum, manufactDate, lotNum
InventoryItem::InventoryItem(int Snum, string ManD, int Lnum)


// get functions or Accessors
int InventoryItem::getLotNum() const
{
come lotNum;
}

int InventoryItem::getSerNum() const
{
come serialNum;
}

string InventoryItem::getManDate() const
{
come manufactDate;
}

// set functions or Mutators
void InventoryItem::setLotNum(int lNum)


void InventoryItem::setSerNum(int sNum)


void InventoryItem::setManDate(string manu)

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