Inventoryitem Stack Please Post New Code Response Need Repost Template Program Use Stack Q24018271

InventoryItem Stack

Please only post new code in response, no need to repost thetemplate or what is below.

In this program, you will use the stack class you created inAssignment 1. First, you will create a class called InventoryItem.This class will have its class declaration in InventoryItem.h andits implementation in InventoryItem.cpp. It will have three privatedata members, an integer serialNum which holds the part’s serialnumber, manufactDate which should be a string that holds the datethe item was manufactured, then lotNum which will be an integerthat holds the part’s lot number. The program should then create astack with a data type of InventoryItem (stack). The program shouldloop asking the user to enter in new items to the inventory stackor to remove an item from the inventory stack. The loop shouldcontinue until the user indicates they are done. This should bemenu driven. When adding an item, the program should ask the userfor the information it needs for the 3 data members of theInventoryItem class and add a new item to the stack. When removingan item from the stack, the program should display all of theinformation in the InventoryItem object that was popped off thestack. When the program ends, it should pop all of the remainingitems off the stack and display the data that is in the Inventoryitems as it pops them off. There should be 3 utility functions thatmain uses. void popItem(DynStack* stack) // pops the item off thestack and displays it. void pushItem(DynStack* stack) // pushes theitem onto the stack int menu(); // displays the menu and returnsthe user’s choice.

Template

https://www.chegg.com/homework-help/Starting-Out-with-C–8th-edition-chapter-18-problem-2PC-solution-9780133888201

//////////////////////////////////////////////////////////////////
//InventoryItem Header
////////////////////////////////////////////////////////////////

#ifndef INVENTORYITEM_H
#define INVENTORYITEM_H
#include    // Needed for strlen and strcpy

// Constant for the description’s default size
const int DEFAULT_SIZE = 51;

class InventoryItem
{
private:
   char *description; // The item description
   double cost;       // The item cost
   intunits;          //Number of units on hand

   // Private member function.
   void createDescription(int size, char *value);

public:
   // Constructor #1
   InventoryItem();

   // Constructor #2
   InventoryItem(char *desc);

   // Constructor #3
   InventoryItem(char *desc, double c, int u);
      
   // Destructor
   ~InventoryItem();

   // Mutator functions
   void setDescription(char *d);

   void setCost(double c);

    
   void setUnits(int u);

   // Accessor functions
   const char *getDescription() const;

       
   double getCost() const;

   int getUnits() const;

};

#endif
//////////////////////////////////////////////////////////////////
//InventoryItem CPP
////////////////////////////////////////////////////////////////
#include “InventoryItem.h”

// Private member function.
void InventoryItem::createDescription(int size, char *value)
{
    // Allocate the default amount of memory fordescription.
    description = new char [size+1];

    // Store a value in the memory.
    strcpy_s(description, size+1, value);

}

// Constructor #1
InventoryItem::InventoryItem()
{
    // Store an empty string in thedescription
    // attribute.
    createDescription(DEFAULT_SIZE, “”);

    // Initialize cost and units.
    cost = 0.0;
    units = 0;
}

// Constructor #2
InventoryItem::InventoryItem(char *desc)
{
    // Allocate memory and store thedescription.
    createDescription(strlen(desc), desc);

    // Initialize cost and units.
    cost = 0.0;
    units = 0;
}

// Constructor #3
InventoryItem::InventoryItem(char *desc, double c, int u)
{
    // Allocate memory and store thedescription.
    createDescription(strlen(desc), desc);

    // Assign values to cost and units.
    cost = c;
    units = u;
}    

// Destructor
InventoryItem::~InventoryItem()
{
    delete [] description;
}

// Mutator functions
void InventoryItem::setDescription(char *d)
{
   if (strlen(description) > 0)
       delete [] description;

   createDescription(strlen(d), d);
}

void InventoryItem::setCost(double c)
{
    cost = c;
}

void InventoryItem::setUnits(int u)
{
    units = u;
}

// Accessor functions
const char *InventoryItem::getDescription() const
{
    return description;
}

double InventoryItem::getCost() const
{
    return cost;
}

int InventoryItem::getUnits() const
{
    return units;
}

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published.