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
|
#include "InventoryClass.h"
#include "InventoryCostClass.h"
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
const int SIZE = 6;
struct Edit {
int itID;
string code, edit;
};
int menu();
void displayInv(InventoryCost[]);
void createFile(fstream&, string);
void printFile(fstream&, string, InventoryCost[]);
int main() {
InventoryCost itemInv[SIZE] =
{ InventoryCost(209875, "Global - Designed Wrench : catalog 145HN - 89", 1056,
14.67, 23.99, 10, 13, 2014),
InventoryCost(176524, "Steeheel Chainsaw - 120 H - P: catalog 133NM - 65", 2654,
234.67, 299.99, 10, 13, 2014),
InventoryCost(340965, "Plurers Pliers with Sure - Grip: catalog 764TW - 12", 1043,
11.45, 19.98, 10, 13, 2014),
InventoryCost(453285, "Rapid Recoil Hand Tape Measure : catalog 127UY - 32", 3316,
8.56, 15.99, 10, 13, 2014),
InventoryCost(893167, "Steady Built Steel Saw Horses : catalog 564HG - 34", 764,
45.54, 79.99, 10, 13, 2014),
InventoryCost(597895, "Big Boy Bib Overalls - L - XL - XXL: catalog 278LG - 45", 5032,
19.76, 39.99, 10, 13, 2014) };
int ch = 0;
fstream file;
string filename, name, extension = ".dat";
cout << " *Choose a name for the update file: ";
cin >> name;
filename = name + extension;
do {
ch = menu();
if (ch != 6) {
switch (ch)
{
case 1:
displayInv(itemInv);
break;
case 2:
createFile(file, filename);
break;
case 3:
printFile(file, filename, itemInv);
break;
case 4:
break;
case 5:
break;
}
}
} while (ch != 6);
system("pause");
return 0;
}
int menu() {
int choice;
cout << "**********************************\n"
<< "*________MENOCU TOOL SHOP________*\n"
<< "**********************************\n"
<< "* 1. Display Inventory *\n"
<< "* 2. Create a Transaction File *\n"
<< "* 3. Update Inventory *\n"
<< "* 4. Display Updated Inventory *\n"
<< "* 5. Compute Profit Projection *\n"
<< "* 6. EXIT *\n"
<< "**********************************\n"
<< " Menu Choice: ";
cin >> choice;
return choice;
}
void displayInv(InventoryCost itemInv[SIZE]) {
for (int i = 0; i < SIZE; i++) {
cout << "Item #" << i+1 << ": " << endl;
itemInv[i].print();
}
}
void createFile(fstream &file, string filename) {
Edit ed;
int num;
file.open(filename, ios::out | ios::binary);
if (!file) {
cout << "ERROR opening file!\n";
}
cout << "How many records to ammend: ";
cin >> num;
cout << "Her are the Transaction Codes: \n"
<< "\tAI: Add to Inventory\n"
<< "\tRI: Reduce from Inventory\n"
<< "\tCW: Change Wholesale Cost\n"
<< "\tCR: Change Retail Price\n"
<< "\tCD: Change Description\n\n";
for (int i = 0; i < num; i++) {
cout << "Enter the ItemID #: ";
cin >> ed.itID;
cout << "Enter the Transaction Code: ";
cin.ignore();
getline(cin, ed.code);
cout << "Enter New Data: ";
getline(cin, ed.edit);
file.write(reinterpret_cast<char *>(&ed.itID), sizeof(ed.itID));
file.write(ed.code.c_str(), ed.code.length());
file.write(ed.edit.c_str(), ed.edit.length());
}
file.close();
}
void printFile(fstream &file, string filename, InventoryCost inv[SIZE]) {
Edit it;
file.open(filename, ios::in | ios::binary);
if (!file) {
cout << "ERROR opening file!\n";
}
file.clear();
file.read(reinterpret_cast<char *>(&it), sizeof(it));
while (!file.eof()) {
cout << it.itID << " " << it.code << " " << it.edit << endl;
for (int i = 0; i < SIZE; i++) {
if (inv[i].getID() == it.itID) {
if (it.code == "AI") {
int add = (stoi(it.edit));
inv[i].setQty(add);
}
else if (it.code == "RI") {
int sub = (stoi(it.edit));
inv[i].setQty(sub);
}
else if (it.code == "CW")
inv[i].setWCost(stof(it.edit));
else if (it.code == "CR")
inv[i].setRCost(stof(it.edit));
else if (it.code == "CD")
inv[i].setDesc(it.edit);
else
cout << "Invalid Transaction Code\n";
}
}
file.read(reinterpret_cast<char *>(&it), sizeof(it));
}
file.close();
}
|