Question
--------------------------------------------------------------------------------------------------------------------------------------------------------------------- //Inventory.h #ifndef INVENTORY_H #define INVENTORY_H class Inventory { private: int itemNumber; int quantity; double cost; double totalCost; public: // default constructor Inventory() { itemNumber
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//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
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
int main() { int itemNum = 0; int qty = 0; double cs = 0.0; double tc = 0.0; cout > itemNum; while (itemNum > itemNum; } cout > qty; while (qty > qty; } cout > cs; while (cs > cs; }
Inventory inv(itemNum, qty, cs);
tc = inv.getTotalCost(); itemNum = inv.getItemNumber(); cs = inv.getCost(); qty = inv.getQuantity();
cout
system("pause"); return 0; }
This is my code for the Inventory class programming challenge for C++ chapter 13.6 in the Tony Gaddis book (8th edition). As shown, 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 programStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started