Problem; Item Number (identification), Quantity, and Cost of item are all displaying large negative values at the end of program.
Prompt; Design an Inventory class that can hold information for an item in a retail store’s inventory.
ItemNumber -> An int that holds the item’s number.
Quantity -> An int that holds the quantity of the item on hand.
Cost -> A double that holds the wholesale per-unit cost of the Item
setItemNumber -> Accepts int argument & copies it into the ItemNumber
setQuantity -> Accepts int argument & copies it into the Quantity
setCost -> Accepts double argument & copies it into the Cost
getItemNumber -> Returns the value in ItemNumber
getQuantity -> Returns the value in Quantity
getCost -> Returns the value in Cost
getTotalCost -> Computes and returns the TotCost
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#include <iostream>
using namespace std;
class Inventory
{
private:
int ItemNumber;
int Quantity;
double Cost;
double TotCost;
public:
Inventory()
{
ItemNumber = 0;
Quantity = 0;
Cost = 0;
TotCost;
}
Inventory(int EndItemNumber, int EndQuantity, double EndCost)
{
EndItemNumber = getItemNumber();
EndQuantity = getQuantity();
EndCost = getCost();
setTotCost(Quantity, Cost);
}
void setItemNumber(int)
{
ItemNumber = ItemNumber;
}
void setQuantity(int)
{
Quantity = Quantity;
}
void setCost(double)
{
Cost = Cost;
}
void setTotCost(int, double)
{
TotCost = Quantity*Cost;
}
int getItemNumber()
{
return ItemNumber;
}
int getQuantity()
{
return Quantity;
}
double getCost()
{
return Cost;
}
double getTotCost()
{
return TotCost;
}
};
int main()
{
int ItemNumber;
int Quantity;
double Cost;
double TotCost;
cout << "Please enter the Item Number: ";
cin >> ItemNumber;
while (ItemNumber < 0)
{
cout << "Only enter positive values for the Item Number: ";
cin >> ItemNumber;
}
cout << "Please enter the Quantity of this Item: ";
cin >> Quantity;
while (Quantity < 0)
{
cout << "Only enter positive values for the Quantity: ";
cin >> Quantity;
}
cout << "Please enter the Cost of this Item: ";
cin >> Cost;
while (Cost < 0)
{
cout << "Only enter positive values for the Cost: ";
cin >> Cost;
}
Inventory Info(ItemNumber, Quantity, Cost);
TotCost = Info.getTotCost();
ItemNumber = Info.getItemNumber();
Cost = Info.getCost();
Quantity = Info.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: " << TotCost << endl;
system("pause");
return 0;
}
|