Question: ****Please do not use pre-compiled headers***** ?This program will use two classes; one of the classes is provided in the assignment description for week 7
****Please do not use pre-compiled headers*****
?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 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.

The inventory files are provided below:
InventoryItem.cpp
#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; }InventoryItem.h
#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; }; #endifThis is my main, CashRegister.cpp and Cash Register.h files I have tried so far but get many errors I don't quite understand.
Main.cpp
#include
#include
#include "CashRegister.h"
#include "InventoryItem.h"
using namespace std;
void displayMenu(InventoryItem[], int, int&, int&);
void getOrder(int&, int&, InventoryItem[], int size);
void displayTotal(CashRegister);
bool buyAgain();
int main()
{
const int SIZE = 5;
int menuNumber, numUnits;
InventoryItem tools[SIZE] = {
InventoryItem("Adjustable Wrench", 15.00, 10),
InventoryItem("Screwdriver", 5.00, 20),
InventoryItem("Pliers", 7.00, 35),
InventoryItem("Ratchet", 10.00, 10),
InventoryItem("Socket Wrench", 12.00, 7) };
displayMenu(tools, SIZE, menuNumber, numUnits);
cout
system("pause");
return 0;
}
// this function displays the menu with quanities of items and then calls the getOrder function
void displayMenu(InventoryItem array[], int size, int &menuNumber, int &numUnits)
{
for (int i = 0; i
cout
cout
for (int i = 0; i
cout
for (int i = 0; i
{
cout
}
getOrder(menuNumber, numUnits, array, size);
}
// this function prompts the user which item they would like to buy and how many. it will validate the
// item and quantity for proper entries
void getOrder(int &menu, int &units, InventoryItem array[], int size)
{
bool checksGood = false, // over all test
testOne = false, // test if units is above 0
testTwo = false; // test if units is less than or equal to the quantity left in stock
cout
cin >> menu;
while (menu 5)
{
cout
cout
cin >> menu;
}
cout
cin >> units;
while (!checksGood)
{
while (units
{
cout
cout
cin >> units;
if (units > array[(menu - 1)].getUnits())
testTwo = false;
}
testOne = true;
// if units is greater than how many are left in stock
while (units > array[(menu - 1)].getUnits())
{
cout
cout
cin >> units;
if (units
testOne = false;
}
testTwo = true;
// if both tests come back true, pass the function
if (testOne == true && testTwo == true)
checksGood = true;
}
CashRegister price(array[(menu - 1)].getCost(), units);
displayTotal(price);
array[(menu - 1)].setUnitsSold(units);
if (buyAgain())
displayMenu(array, size, menu, units);
}
// this function displays the subtotal tax and total
void displayTotal(CashRegister totals)
{
cout
cout
}
// this function prompts the user if they would like to make another purchase
bool buyAgain()
{
bool again = false;
char let = '0';
if (!again)
{
cout
cin >> let;
}
if (toupper(let) == 'Y')
again = true;
cout
return again;
}
CashRegister.h
#ifndef CASHREGISTER_H
#define CASHREGISTER_H
#include "InventoryItem.h"
class CashRegister
{
private:
double cost;
int units;
double unitPrice;
double subtotal;
double salesTax;
double purchaseTotal;
public:
// constructor
CashRegister(double, int);
// setters
void setUnitPrice();
void setSubtotal();
void setSalesTax();
void setPurchaseTotal();
// getters
double getUnitPrice() const;
double getSubtotal() const;
double getSalesTax() const;
double getPurchaseTotal() const;
};
#endif
CashRegister.cpp
#include "CashRegister.h"
#include "InventoryItem.h"
// constructor
CashRegister::CashRegister(double c, int u)
{
cost = c;
units = u;
setUnitPrice();
setSubtotal();
setSalesTax();
setPurchaseTotal();
}
// this setter function assigns the unit price to the cost with 30% profit
void CashRegister::setUnitPrice()
{
unitPrice = (cost * 0.30) + cost;
}
// this setter function assigns the subtotal to the unit price times the quantity
void CashRegister::setSubtotal()
{
subtotal = unitPrice * units;
}
// this setter function sets the sales tax to the subtotal times 6%
void CashRegister::setSalesTax()
{
salesTax = subtotal * .06;
}
// this setter function sets the purchase total to the subtotal plus the sales tax
void CashRegister::setPurchaseTotal()
{
purchaseTotal = subtotal + salesTax;
}
// getter functions return their respective attributes
double CashRegister::getUnitPrice() const
{
return unitPrice;
}
double CashRegister::getSubtotal() const
{
return subtotal;
}
double CashRegister::getSalesTax() const
{
return salesTax;
}
double CashRegister::getPurchaseTotal() const
{
return purchaseTotal;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
