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

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

ID: 3588999 • Letter: N

Question

Need C++ program with .h and .cpp

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

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

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.

Explanation / Answer

RegisterCashMain.cpp

// RegisterCashMain.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <iostream>

#include <iomanip>

#include "CashRegister.h"

#include "InventoryItem.h"

using namespace std;

int main()

{

int numSelected;//int variable holds number selected

int qtySelected;//double 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

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

}

Cashregister.h
#ifndef CASHREGISTER_H

#define CASHREGISTER_H
#inclue "InventoryItem.h"
const double TAX_RATE = 0.06;

const double MARKUP = .30;

class CashRegister

{

private:

InventoryItem* item;

int quantity;
int cost;

public:

CashRegister(InventoryItem*);

CashRegister(InventoryItem*, double);

CashRegister(InventoryItem*, int);

void setItem(InventoryItem*);

void setCost(InventoryItem*, double);

void setQuantity(InventoryItem*, int);

void updateInventory();

int getQuantity(InventoryItem*, int) const;

double getCost(InventoryItem*, double c) 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

{

char *description; //item description

double cost; //item cost

int units; //Number of units on hand

int qtySold;

// 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(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;

}

//constructor #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

InventoryItem.cpp
#include "stdafx.h"
#include "CashRegister.h"
#include<iostream>
#include "InventoryItem.h"

using namespace std;
CashRegister::CashRegister(InventoryItem* i)
{
item = i;
}
CashRegister::CashRegister(InventoryItem* i, double c)
{
item=i;
double cost = c;

}

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::setCost(InventoryItem* , double c)

{

double cost;

cost = c;

}

void CashRegister::setQuantity(InventoryItem* , int q)

{

quantity = q;

}

int CashRegister::getQuantity(InventoryItem* , int q) const

{

return quantity;

}

double CashRegister::getCost(InventoryItem* i, double c) const

{

double cost;

return cost;

}

double CashRegister::getUnitPrice() const

{


double cost=item->getCost();
double price;


price = cost + cost * MARKUP;

//price = CashRegister::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;

}

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