/*************************************************/
// R. A. Hillyard
// inventory01.cpp
// November 2001
//
// inventory class
/*************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
class Inventory
{
public:
void input();
void output();
void set(int newPartNum, int newInStock, double newCost);
int getPartNum();
int getInStock();
double getCost();
private:
int partNum;
int inStock;
double cost;
};
/****************************************************************/
void Inventory::input()
{
cout << "\nenter part number, number in stock, and the cost:\n>";
cin >> partNum >> inStock >> cost;
}
/****************************************************************/
void Inventory::output()
{
cout << setw(6) << partNum << setw(6) << inStock
<< setw(8) << cost << endl;
}
/****************************************************************/
void Inventory::set(int newPartNum, int newInStock, double newCost)
{
partNum = newPartNum;
inStock = newInStock;
cost = newCost;
}
/****************************************************************/
int Inventory::getPartNum()
{ return partNum; }
/****************************************************************/
int Inventory::getInStock()
{ return inStock; }
/****************************************************************/
double Inventory::getCost()
{ return cost; }
/****************************************************************/
int main()
{
Inventory part1;
Inventory part2;
Inventory part3;
part1.set(1234, 542, 12.99);
part3.set(2345, 22, 498.56);
part2.input();
double value = (part1.getInStock() * part1.getCost())
+ (part2.getInStock() * part2.getCost())
+ (part3.getInStock() * part3.getCost());
cout << "\n*** Inventory Database ***\n";
part1.output();
part2.output();
part3.output();
cout << "\nTotal value of inventory: " << value << endl;
}
/****************************************************************/
/**********************Program Output****************************/
enter part number, number in stock, and the cost:
>7634 82 99.99
*** Inventory Database ***
1234 542 12.99
7634 82 99.99
2345 22 498.56
Total value of inventory: 26208.1
/****************************************************************/