Question: Need C++ program with .h and .cpp The first file to work with is InventoryItem.cpp and is below: #include InventoryItem.h // Private member function. void

Need C++ program with .h and .cpp

Need C++ program with .h and .cpp The first file to work

with is InventoryItem.cpp and is below: #include "InventoryItem.h" // Private member function.

The first file to work with is InventoryItem.cpp and is below:

#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]; // Store a value in the memory. strcpy(description, 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) { strcpy(description, 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; } 

The second file to work with is InventoryItem.h and is below:

#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; }; #endif 

Cash Register. This program will use two classes: one of the classes is provided in the assignment description for week 7 in the course site. Write a class name CashRegister, with the class declaration in a file called CashRegister.h and the implementation in a file called CashRegister.cpp. This class will interact with the Inventoryltem class that has been provided. The program should display a list of items that are available to purchase

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!