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

This is the InventoryItem.cpp code for you to use: This is the InventoryItem.h f

ID: 3672127 • Letter: T

Question

This is the InventoryItem.cpp code for you to use:

This is the InventoryItem.h for you to use:

Good Afternoon I need the following.cpp and .h files for the program below, to be written in the C++ programming language. please write main.cpp as its own separate entity (from the other two files). please clearly label include good code commentš so that someone with a nontechnical background can understand the code. I appreciate vour efforts and bahe gouid th nduadtad the code. 1 appreciate your efforts and thank you in advance. I am including the necessary files InventoryItem. cpp and InventoryItem.h as pasted text below the program requirements.

Explanation / Answer

/////////////////////////////////////   cashRegister.h ////////////////////////////////////////////

#ifndef CASHREGISTER_H

#define CASHREGISTER_H

#include "InventoryItem.h"

const double TAX_RATE = 0.06;

const double MARKUP = .30;

class CashRegister

{

private:

InventoryItem item;

int quantity;

public:

CashRegister(InventoryItem);

CashRegister(InventoryItem, int);

void setItem(InventoryItem);

void setQuantity(int);

void updateInventory();

int getQuantity() const;

double getCost() const;

double getUnitPrice() const;

double getSubtotal() const;

double getSalesTax() const;

double getTotal() const;

};

#endif

////////////////////////////////////////////////////   Inventoryitem.h /////////////////////////////////////////////////

#ifndef INVENTORYITEM_H

#define INVENTORYITEM_H

#include <cstring> //needed for strlen and strcpy

//constant for description's default size

const int DEFAULT_SIZE = 51;

//InventoryItem class declaration

class InventoryItem

{

private:

char *description; //item description

double cost; //item cost

int units; //Number of units on hand

int qtySold;

// Private member function.

void 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(description, value);

}

public:

//constructor #1

InventoryItem()

{//store an empty string in the description attribute.

createDescription(DEFAULT_SIZE, "");

//initialize cost and units.

cost = 0.0;

units = 0; }

//constrcutor #2

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

{ delete [] description; }

//Mutator functions

void setDescription(char *d)

{ strcpy(description, d); }

void setCost(double c)

{ cost = c; }

void setUnits(int u)

{ units = u; }

void setQtySold(int qs)

{ qtySold = qs;}

//Accessor functions

const char *getDescription() const

{ return description; }

double getCost() const

{ return cost; }

int getUnits() const

{return units; }

void recordSale(int qs)

{

qtySold += qs;

units -= qs;

}

};

#endif

////////////////////////////////////////// Inventory.cpp /////////////////////////////////////////////


#include "cashRegister.h"

using namespace std;

CashRegister::CashRegister(InventoryItem i)

{

item = i;

}

CashRegister::CashRegister(InventoryItem i, int q)

{

item = i;

quantity = q;

}

void CashRegister::updateInventory()

{

item.recordSale(quantity);

}

void CashRegister::setItem(InventoryItem i)

{

item = i;

}

void CashRegister::setQuantity(int q)

{

quantity = q;

}

int CashRegister::getQuantity() const

{

return quantity;

}

double CashRegister::getCost() const

{

return item.getCost();

}

double CashRegister::getUnitPrice() const

{

double price;

price = getCost() + getCost() * MARKUP;

return price;

}

double CashRegister::getSubtotal() const

{

double subtotal;

subtotal = getUnitPrice() * quantity;

return subtotal;

}

double CashRegister::getSalesTax() const

{

double tax;

tax = getSubtotal() * TAX_RATE;

return tax;

}

double CashRegister::getTotal() const

{

double total;

total = getSubtotal() + getSalesTax();

return total;

}

//////////////////////////////////////////////////    answer.cpp //////////////////////////////////////////////

#include <iostream>

#include <iomanip>

#include "CashRegister.h"

#include "InventoryItem.h"

using namespace std;

int main()

{

int numSelected;//int variable holds number selected

int qtySelected;//int variable holds number of items ordered

char again = 'Y';//char variable holds answer (y or n)

double subTotal;

const int NUM_ITEMS = 5; //

//array containing inventory items

InventoryItem inventory[] =

{

InventoryItem("Hammer", 6.95, 12),

InventoryItem("Wrench", 8.75, 20),

InventoryItem("Pliers", 3.75, 10),

InventoryItem("Ratchet", 7.95, 14),

InventoryItem("Screwdriver", 2.50, 22)

};

//format output

cout << fixed << showpoint << setprecision(2);

while (again == 'Y' || again == 'y')

{

//display current inventory

cout << "Listing of current inventory" << endl;

cout << " " << endl;

//table format

cout << setw(7) << "Item Number"

<< setw(17) << "Description"

<< setw(8) << "Cost" << setw(8)

<<setw(17) << "Units on Hand ";

cout << "------------------------------------------------------------ ";

//for loop display allowing to display contents of array into table format

for (int i = 0; i < NUM_ITEMS; i++)

{

cout <<setw(7) << i;

cout << setw(17) << inventory[i].getDescription();

cout << setw(10) << "$" << inventory[i].getCost();

cout << setw(8) << inventory[i].getUnits() << endl;

}

cout << "" << endl;

cout << "" << endl;

//prompt user to input inventory number purchase

cout << "Please enter the item number of the inventory item you wish to purchase: ";

cin >> numSelected;

cout << endl;

//validation loop

while((numSelected < 0) || (numSelected > 4))

{

cout << "Invalid Selection. Please enter an inventory item number 0-4: ";

cin >> numSelected;

}

//prompt for quantity of items wished to purchase

cout << "Please enter the quantity you wish to purchase: ";

cin >> qtySelected;

cout << endl;

//validation loop

while(qtySelected > inventory[numSelected].getUnits() || qtySelected < 1)

{

cout << "Invalid quantity. Please enter quantity less than or equal to " << inventory[numSelected].getUnits() << " units: ";

cin >> qtySelected;

}

CashRegister sale = CashRegister(inventory[numSelected], qtySelected);

cout << " " << endl;

//display subtotal, tax, and total

cout << "Total cost (30% markup on above listed cost included): " << endl;

cout << " " << endl;

//create a sale object for this transaction

//specify the item cost, but use the default

//tax rate of 6 percent

CashRegister sale2(CashRegister sale); //???

// display results

cout << "Subtotal: $" << sale.getSubtotal() << endl;

cout << "Sales tax: $" << sale.getSalesTax() << endl;

cout << "Total: $" << sale.getTotal() << endl;

//update inventory

sale.updateInventory();

//allow user to make another purchase

cout << " Would you like to make another purchase? ";

cin >> again;

}

return 0;

}

run it as

g++ -c answer.cpp

g++ -c InventoryItem.cpp

g++ -o answer answer.o InventoryItem.o

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