Inventory Class Design an Inventory class that can hold information and calculat
ID: 3620644 • Letter: I
Question
Inventory ClassDesign an Inventory class that can hold information and calculate data for item in a
retail store’s inventory. The class should have the following private member variables:
Variable Name & Description
itemNumber an int that holds the item’s item number.
quantity an int for holding the quantity of the items on-hand.
cost a double for holding the wholesale per-unit cost of the ii
totalCost a double for holding the total inventory cost of the item
(calculated as quantity times cost).
The class should have the following public member functions:
Default : sets all the member variables to 0.
Constructor
Constructor #2: accepts an item’s number, cost, and quantity as argument the function should copy these values to the appropriate member
variables and then call the setTotalCost function.
setltemNumber : accepts an integer argument that is copied to the itemNumber
member variable.
setQuantity : accepts an integer argument that is copied to the quantity member variable.
setCost: accepts a double argument that is copied to the cost member variable.
setTotalCost : calculates the total inventory cost for the item (quantity times cost) and stores the result in totalcost.
getltemNumber : returns the value in itemNumber.
getQuantity: returns the value in quantity.
getCost : returns the value in cost.
getTotalcost : returns the value in totalcost.
Demonstrate the class in a driver program.
Input Validation: Do not accept negative values for item number, quantity, or cost.
Explanation / Answer
please rate - thanks
#include <iostream>
#include <iomanip>
using namespace std;
class Inventory
{
private:
int itemNumber;
int quantity;
double cost;
double totalCost;
public:
Inventory()
{itemNumber=0;
quantity=0;
cost=0;
totalCost=0;
}
Inventory(int i,int q,double c)
{itemNumber=i;
quantity=q;
cost=c;
setTotalCost();
}
void setItemNumber(int i)
{if(i>=0)
itemNumber=i;
else
{cout<<"invalid entry ";
system("pause");
exit(1);
}
}
void setQuantity(int q)
{if(q>=0)
quantity = q;
else
{cout<<"invalid entry ";
system("pause");
exit(1);
}
}
void setCost(double c)
{
if(c>=0)
cost=c;
else
{cout<<"invalid entry ";
system("pause");
exit(1);
}
}
void setTotalCost()
{totalCost=quantity*cost;
}
int getItemNumber()
{return itemNumber;
}
int getQuantity()
{return quantity;
}
double getCost()
{return cost;
}
double getTotalCost()
{return totalCost;
}
};
int main()
{Inventory a;
cout<<"A ";
cout<<"Item number: "<<a.getItemNumber()<<endl;
cout<<"Quantity: "<<a.getQuantity()<<endl;
cout<<"Cost: $"<<setprecision(2)<<fixed<<a.getCost()<<endl;
cout<<"Total cost: $"<<setprecision(2)<<fixed<<a.getTotalCost()<<endl;
cout<<"B ";
Inventory b(50,5,2.4);
cout<<"Item number: "<<b.getItemNumber()<<endl;
cout<<"Quantity: "<<b.getQuantity()<<endl;
cout<<"Cost: $"<<setprecision(2)<<fixed<<b.getCost()<<endl;
cout<<"Total cost: $"<<setprecision(2)<<fixed<<b.getTotalCost()<<endl;
cout<<"CHANGING B ";
b.setItemNumber(11);
cout<<"New item number: "<<b.getItemNumber()<<endl;
b.setQuantity(1);
cout<<"New quantity: "<<b.getQuantity()<<endl;
b.setCost(4);
cout<<"New cost: $"<<setprecision(2)<<fixed<<b.getCost()<<endl;
b.setTotalCost();
cout<<"New total cost: $"<<setprecision(2)<<fixed<< b.getTotalCost()<<endl;
cout<<"Testing 1 error ";
a.setQuantity(-2);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.