Question
Cash Register C++: I have been trying to tackle this problem all week with no success, I understand how classes work and are implemented using
Cash Register C++:
I have been trying to tackle this problem all week with no success, I understand how classes work and are implemented using one header and cpp file but am having trouble getting it to work with two. I am a beginner learning and teaching myself so any help to figure this out without getting to professional would be helpful in allowing me to understand how using two header and cpp class files can work in the same program. Comments help a lot. Thanks in advance!
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 InventoryItem class that has been provided. The program should display a list of items that are available to purchase.
The program will ask the user for the item and quantity being purchased. It will then get the cost of the item from the InventoryItem object. It will add 30% profit to the cost of the item to get the items unit price. It will then multiply the unit price times the quantity being purchased to get the purchase subtotal.
The program will then compute a 6% sales tax on the subtotal to get the purchase total. It should then display the purchase subtotal, tax and total on the screen. The program will then subtract the quantity being purchased from the onHand variable of the Inventory Item class object. InventoryItem will need to be modified to handle this.
Validation: Do not accept a negative value for the quantity of items being purchased.
========================
Inventory Header File
========================
#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
=====================
Inventory CPP File
=====================
#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; }
t { return cost; } int InventoryItem::getUnits() const { return units; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started