Inventory Class Design an Inventory class that can hold information and calculate data for items in a retail store’s inventory. itemNumber, quantity, cost and totalCost (calculated as quantity times cost). Constructor 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. SetItemNumber 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.
getItemNumber 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.
#include "stdafx.h"
#include <iostream>
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 itemNumber, int quantity, double cost)
{
itemNumber = getItemNumber();
quantity = getQuantity();
cost = getCost();
setTotalCost(quantity, cost);
}
void setItemNumber(int)
{
itemNumber = itemNumber;
}
void setQuantity(int)
{
quantity = quantity;
}
void setCost(double)
{
cost = cost;
}
void setTotalCost(int, double)
{
totalCost = quantity * cost;
}
int getItemNumber()
{
return itemNumber;
}
int getQuantity()
{
return quantity;
}
double getCost()
{
return cost;
}
double getTotalCost()
{
return totalCost;
}
};
int main()
{
int itemNumber;
int quantity;
double cost;
double totalCost;
cout << "Enter the Item Number: ";
cin >> itemNumber;
while (itemNumber < 0)
{
cout << "Please enter a positive value for the Item Number: ";
cin >> itemNumber;
}
cout << "Enter the Quantity of the item: ";
cin >> quantity;
while (quantity < 0)
{
cout << "Please enter a positive value for the Quantity of the item: ";
cin >> quantity;
}
cout << "Enter the Cost of the item: ";
cin >> cost;
while (cost < 0)
{
cout << "Please enter a positive value for the Cost of the item: ";
cin >> cost;
}
Inventory information(itemNumber, quantity, cost);
totalCost = information.getTotalCost();
itemNumber = information.getItemNumber();
cost = information.getCost();
quantity = information.getQuantity();
cout << "The Item Number is: " << itemNumber << endl;
cout << "The Quantity is: " << quantity << endl;
cout << "The Cost is: " << cost << endl;
cout << "The Total Cost is: " << totalCost << endl;
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
Comments
Leave a comment