Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Cash Register. Write a class name CashRegister, with the class declaration in a

ID: 3559602 • Letter: C

Question

Cash Register. 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.

InventoryItem.cpp

InventoryItem.h

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 InventoryItem 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.

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+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)

{

    //strcpy(description, d);

            if (strlen(description) != strlen(d))

                        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;

}

Inventory.h

#ifndef INVENTORYITEM_H

#define INVENTORYITEM_H

#include <cstring>   // 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

Explanation / Answer

======================================================================

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote