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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
const int invSize = 2;
void getInventory(ifstream& infile, vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice);
void displayMenu(vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice);
void sellItem(vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice);
void itemSearch(vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice);
void printReport(vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice);
int main()
{
vector<int> itemQuantity;
vector<string> itemID;
vector<string> itemName;
vector<int> pOrdered;
vector<int> pInStore;
vector<int> pSold;
vector<double> manufPrice;
vector<double> sellingPrice;
int itemNumber;
ifstream infile;
infile.open("C:\\inventory.txt");
if (!infile)
{
cout << "C:\\inventory.txt not read." << endl;
system("pause");
return 1;
}
getInventory(infile, itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);
displayMenu(itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);
infile.close();
return 0;
}
void getInventory(ifstream& infile, vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice)
{
unsigned int i;
string line;
for (i = 0; i < itemID.size(); i++)
{
infile >> itemID[i]
>> itemName[i]
>> pOrdered[i]
>> manufPrice[i]
>> sellingPrice[i];
pInStore[i] = pOrdered[i];
}
pSold[0] = 0;
}
void displayMenu(vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice)
{
char outputResponce;
cout << "Type 'C' to check whether or not an item is in stock." << endl;
cout << "Type 'S' to sell an item to a customer." << endl;
cout << "Type 'R' to print an inventory report." << endl;
cin >> outputResponce;
if (outputResponce == 'C' ||outputResponce == 'c')
itemSearch(itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);
if (outputResponce == 'S' ||outputResponce == 's')
sellItem(itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);
if (outputResponce == 'R' ||outputResponce == 'r')
printReport(itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);
}
void sellItem(vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice)
{
int amtBought;
double cash;
char verifyItem;
int i;
int itemNumber;
for (i = 0; i < 5; i++)
{
cout << "What is being purchased? Input item number. ";
cin >> itemNumber;
i = itemNumber;
if (i != -1)
{
cout << "Selling " << itemName[i] << ", at a costs of $" << sellingPrice[i]
<< ". OK ? (Y/N)" << endl;
cout << endl;
cin >> verifyItem;
if (verifyItem == 'N' || verifyItem == 'n')
{
cout << "Enter what is being sold by item number? " << endl;
cin >> itemNumber;
}
cout << "How many items are required? " << endl;
cin >> amtBought;
if (amtBought < 1)
cout << "Number purchased!" << endl;
else
{
if (pInStore[i] < amtBought)
cout << "Item not available" << pInStore[i] << " can be sold." << endl;
else
{
cout << "Total" << amtBought * sellingPrice[i] << endl;
cout << "Funds tendered" << endl;
cin >> cash;
if (cash < (amtBought * sellingPrice[i]))
{
cout << "Insufficient funds tendered." << endl;
continue;
}
else
{
pInStore[i] = pInStore[i] - amtBought;
cout << "Return" << cash - (amtBought * sellingPrice[i]) << "change." << endl;
}
}
}
}
}
}
void itemSearch(vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice)
{
int number;
cout << "Which would you like to check?" << endl;
cout << endl;
cin >> number;
if (pInStore[number] > 0)
cout << "Currently you have " << pInStore[number] << "of that item in house." << endl;
}
void printReport(vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice)
{
unsigned int i;
int totalItems = 0;
double totalInventory = 0;
cout << "Friendly Hardware Store" << endl << endl;
cout << "itemID ItemName pOrdered pInStore pSold manufPrice sellingPrice" << endl;
cout << fixed << showpoint;
cout << setprecision(2);
for (i = 0; i < itemID.size(); i++)
{
cout << left;
cout << setw(15) << itemID.at(i);
cout << setw(15) << itemName.at(i);
cout << right;
cout << setw(15) << pOrdered.at(i);
cout << setw(15) << pInStore.at(i);
cout << setw(15) << pSold.at(i);
cout << setw(15) << manufPrice.at(i);
cout << setw(15) << sellingPrice.at(i) << endl;
totalInventory += pInStore.at(i) * sellingPrice.at(i);
totalItems += pInStore.at(i);
}
cout << endl;
cout << "Total Inventory: $" << totalInventory << endl;
cout << "Total number of items in the store: " << totalItems << endl;
}
|