Inventoryh Ifndef Inventoryh Define Inventoryh Class Inventory Private Int Itemnumber Int Q34221828

6. Inventory Class Design an Inventory class that can hold information and calculate data for items in a retail stores inventory. The class should have the following private member variables: Variable Name ecription quantity cost totalCost An int that holds the items item number An int for holding the quantity of the items on hand. A double for holding the wholesale per-unit cost A double for holding the total inventory cost of the item (cal- culated as quantity times cost) of the item The class should have the following public member functions: Member Function Default Constructor Constructor #2 Sets all the member variables to 0. Accepts an items number, cost, and quantity as arguments. The function should copy these values to the appropriate member variables and then call the setTotalCost function. Accepts an integer argument that is copied to the itemNumber member variable. setItemNumber Accepts an integer argument that is copied to the quantity member variable. setQuantity Accepts a double argument that is copied to the cost member variable. setCost Calculates the total inventory cost for the item (quantity times cost) and stores the result in totalCost. Returns the value in itemNumber. setTotalCost getItemNumber getQuantity getCost getTotalCost Returns the value in quantity Returns the value in cost. Returns the value in totalcost. Demonstr Input Validation: Do not accept negative values for item number, quantity, or cost. rate the class in a driver program.

———————————————————————————————————————————————————————

//Inventory.h

#ifndef INVENTORY_H
#define INVENTORY_H

class Inventory
{
private:
   int itemNumber;
   int quantity;
   double cost;
   double totalCost;
public:
   // default constructor
   Inventory()
   {
       itemNumber = 0;
       quantity = 0;
       cost = 0.0;
       totalCost = 0.0;
   }

   // overload constructor
   Inventory(int, int, double);
   // mutator
   void setItemNumber(int itemNumber);
   void setQuantity(int quantity);
   void setCost(double cost);
   void setTotalCost()
   {totalCost = quantity * cost;}

   // accessor
   int getItemNumber()
   {return itemNumber;}
   int getQuantity()
   {return quantity;}
   double getCost()
   {return cost;}
   double getTotalCost()
   {return totalCost;}
}; #endif

//Inventory2.cpp

#include <iostream>
#include <iomanip>
#include <string>
#include “Inventory.h”
using namespace std;

Inventory::Inventory(int i, int q, double c)
{
   int itemNumber;
   int quantity;
   double cost;
   itemNumber = i;
   quantity = q;
   cost = c;
   setTotalCost();
}
  
void Inventory::setQuantity(int q)
{
   quantity = q;
}

void Inventory::setCost(double c)
{
   cost = c;
}

void Inventory::setItemNumber(int num)
{
   itemNumber = num;
}

//Inventory.cpp

#include <iostream>
#include <iomanip>
#include <string>
#include “Inventory.h”
#include “Inventory2.cpp”
using namespace std;

int main()
{
   int itemNum = 0;
   int qty = 0;
   double cs = 0.0;
   double tc = 0.0;
   cout << “Enter item number: “;
   cin >> itemNum;
   while (itemNum < 0)
   {
       cout << “Error. Invalidentry. Enter item number: “;
       cin >> itemNum;
   }
   cout << “Enter item quantity: “;
   cin >> qty;
   while (qty < 0)
   {
       cout << “Error. Invalidentry. Enter item quantity: “;
       cin >> qty;
   }
   cout << “Enter item cost: $”;
   cin >> cs;
   while (cs < 0)
   {
       cout << “Error. Invalidentry. Enter item cost: “;
       cin >> cs;
   }

   Inventory inv(itemNum, qty, cs);

   tc = inv.getTotalCost();
   itemNum = inv.getItemNumber();
   cs = inv.getCost();
   qty = inv.getQuantity();

   cout << ” You entered…” <<endl;
   cout << “Item number: ” << itemNum<< endl;
   cout << “Quantity: ” << qty <<endl;
   cout << “Cost: $” << cs <<endl;
   cout << “Total cost: $” << fixed <<setprecision(2) << tc << endl;

   system(“pause”);
   return 0;
}

This is my code for the Inventory class programming challengefor C++ chapter 13.6 in the Tony Gaddis book (8th edition). Asshown, I have three different files as part of my final program.When the output is produced, a bunch of random numbers appear.What’s wrong with my code?

6. Inventory Class Design an Inventory class that can hold information and calculate data for items in a retail store’s inventory. The class should have the following private member variables: Variable Name ecription quantity cost totalCost An int that holds the item’s item number An int for holding the quantity of the items on hand. A double for holding the wholesale per-unit cost A double for holding the total inventory cost of the item (cal- culated as quantity times cost) of the item The class should have the following public member functions: Member Function Default Constructor Constructor #2 Sets all the member variables to 0. Accepts an item’s number, cost, and quantity as arguments. The function should copy these values to the appropriate member variables and then call the setTotalCost function. Accepts an integer argument that is copied to the itemNumber member variable. setItemNumber Accepts an integer argument that is copied to the quantity member variable. setQuantity Accepts a double argument that is copied to the cost member variable. setCost Calculates the total inventory cost for the item (quantity times cost) and stores the result in totalCost. Returns the value in itemNumber. setTotalCost getItemNumber getQuantity getCost getTotalCost Returns the value in quantity Returns the value in cost. Returns the value in totalcost. Demonstr Input Validation: Do not accept negative values for item number, quantity, or cost. rate the class in a driver program. Show transcribed image text

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *