c++ program HELP PLEASE Cash Register. This program will use two classes; one of
ID: 3771893 • Letter: C
Question
c++ program HELP PLEASE
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 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 item’s 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.
Explanation / Answer
#ifndef INVENTORYITEM_H
#define INVENTORYITEM_H
#include<cstring> //needed for strlen and strcpy
using namespace std;
//Constant for the descrptions 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)
{//Allocate the default ammount of memory fir description.
description = new char [size*'()'];
//Store a value in the memory.
strcpy(description,value);}
public:
//Constructor #1
InventoryItem()
{//Stotre an empty string in the description of the
//atribute
createDescription(DEFAULT_SIZE, "");
//Initialize cost and units
cost = 0.0;
units = 0; }
//Contructor#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);
//Asssign Values to the 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;}
//Accesor Functions
const char *getDescription()const
{return description;}
double getCost() const
{return cost;}
int getUnits () const
{return units;}
};
#endif
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include "InventoryItem.h"
using namespace std;
int main()
{
const int NUM_ITEMS = 5;
InventoryItem inventory[NUM_ITEMS] = {
InventoryItem("chocolate",6.95, 12),
InventoryItem("biscuit",8.75, 20),
InventoryItem("Cakes",3.75, 10),
InventoryItem("Juices",7.95, 14),
InventoryItem("coke",2.50, 22) };
cout<<setw(14)<<"Inventory Item"
<<setw(8)<<"Cost"<<setw(8)
<<setw(16)<<"Units on Hand ";
cout<<"------------------------------------- ";
for (int i = 0;i< NUM_ITEMS;i++)
{
cout<<setw(14)<<inventory[i].getDescription();
cout<<setw(8)<<inventory[i].getCost();
cout<<setw(7)<<inventory[i].getUnits()<<endl;
}
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.