I want C++ program with output. please don\'t post that solution that are alread
ID: 3806128 • Letter: I
Question
I want C++ program with output. please don't post that solution that are already in Chegg.
Assignment 1
Write your own version of a class template that will create a dynamic stack of any data type. The pop function must return a bool; it should return a false if it was not able to pop an item off the stack. Otherwise it returns true. The parameter to the pop function is passed by reference and should be the item on the list if it was able to pop something. Create a driver program (main) that shows that the stack works for at least two different data types.
Assignment 2
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.
///////////
Explanation / Answer
#include "InventoryItem.h" // Private member function. void InventoryItem::createDescription(int size, char *value) { // Allocate the default amount of memory for description. 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 the description // attribute. createDescription(DEFAULT_SIZE, ""); // Initialize cost and units. cost = 0.0; units = 0; } // Constructor #2 InventoryItem::InventoryItem(char *desc) { // Allocate memory and store the description. 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 the description. 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; } /////// #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 int units; // 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; }; #endifRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.