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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
[/#include<iostream>
using namespace std;
class Inventory
{
private:
int itemNumber;
int quantity;
double cost;
double totalcost;
public:
Inventory();
Inventory(int, int, double);
void setItemnumber(int);
void setQuantity(int);
void setCost(double);
void setTotalCost(int, double);
int getItemNumber() const;
int getQuantity() const;
double getCost() const;
double getTotalCost() const;
};
Inventory::Inventory()
{
itemNumber=0;
quantity=0;
cost=0;
totalcost=0;
}
Inventory::Inventory(int number, int amount, double Cost)
{
itemNumber=number;
quantity=amount;
cost=Cost;
setTotalCost(quantity, cost);
}
void setItemnumber(int number)
{
itemNumber=number;
}
void setQuantity(int amount)
{
quantity=amount;
}
void setCost(double Cost)
{
cost=Cost;
}
void setTotalCost(int amount, double Cost)
{
totalcost=amount*Cost;
}
int getItemNumber() const
{
return itemNumber;
}
int getQuantity() const
{
return quantity;
}
double getCost() const
{
return cost;
}
double getTotalCost() const
{
return totalcost;
}
int main()
{
int ITEMNUMBER, QUANTITY;
double COST;
cout<<"Welcome, when asked to enter informations please do not enter" <<endl;
cout<<"a negative number. Please enter the first items number: ";
cin>>ITEMNUMBER;
cout<<"Please enter the first items quantity: ";
cin>>QUANTITY;
cout<<"Please enter the first items cost: ";
cint>>COST;
Inventory item1;
item1.setItemnumber(ITEMNUMBER);
item1.setQuantity(QUANTITY);
item1.setCost(COST);
item1.setTotalCost(QUANTITY, COST);
cout<<"Thankyou, now for the second item: " <<endl;
cout<<"Please enter the second items number:";
cin>>ITEMNUMBER;
cout<<"Please enter the second items quantity: ";
cin>>QUANTITY;
cout<<"Please enter the second items cost: ";
cint>>COST;
Inventory item2(ITEMNUMBER, QUANTITY, COST);
cout<<setprecision(2) <<fixed;
cout<<"Here are the two items you have put into inventory:" <<endl;
cout<<"Item numbered " <<item1.getItemNumber <<"has " <<item1.getQuantity;
cout<<" in stock at a price" <<endl;
cout<<"of $" <<item1.getCost <<". In total they are worth $" <<item1.getTotalCost;
cout<<"." <<endl <<endl;
cout<<"Item numbered " <<item2.getItemNumber <<"has " <<item2.getQuantity;
cout<<" in stock at a price" <<endl;
cout<<"of $" <<item2.getCost <<". In total they are worth $" <<item2.getTotalCost;
return 0;
}
|