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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct invRecord
{
string delDate;
int MID, qtyOnHand, qtyOrdered;
float price, priceChng;
bool includeinNewMaster;
};
struct transRecord
{
string actionCode, delDate;
int TID, qtyOnHand, qtyOrdered;
float price, priceChng;
};
void checktoAdd(invRecord inventory[], string actionCode);
void checktoDelete(invRecord inventory[], string actionCode);
void checktoEdit1(invRecord inventory[], string actionCode);
void checktoEdit2(invRecord inventory[], string actionCode);
void checktoEdit3(invRecord inventory[], string actionCode);
void checktoEdit4(invRecord inventory[], string actionCode);
int main()
{
//Read in records from Master.txt and count them
invRecord inventory[100];
ifstream readIn1;
readIn1.open("Master.txt");
int count = 0;
//No need to sort the records, as they are already in proper order
while (!readIn1.eof())
{
readIn1 >> inventory[count].MID >> inventory[count].qtyOnHand >> inventory[count].qtyOrdered >> inventory[count].delDate >> inventory[count].price >> inventory[count].priceChng;
inventory[count].includeinNewMaster = true;
count = count + 1;
}
ifstream readIn2;
ofstream writeFile;
transRecord transaction;
int index = 0;
while (!readIn2.eof())
{
readIn2.open("Transactions.txt");
readIn2 >> transaction.actionCode >> transaction.TID >> transaction.qtyOnHand >> transaction.qtyOrdered >> transaction.delDate >> transaction.price >> transaction.priceChng;
checktoAdd(inventory, transaction.actionCode);
checktoDelete(inventory, transaction.actionCode);
checktoEdit1(inventory, transaction.actionCode);
checktoEdit2(inventory, transaction.actionCode);
checktoEdit3(inventory, transaction.actionCode);
checktoEdit4(inventory, transaction.actionCode);
index++;
}
//Need to get the next record from Transactions.text; how do we do that?
//Cleanup:
//Merge Master.txt with Master2.txt and create NewMaster.txt
//Read in Master2.txt into an array of structs (transRecords).
ifstream readIn;
transRecord master2[100];
readIn.open("Master2.txt");
int count2 = 0;
readIn >> master2[count2];
while (!readIn.eof())
{
count2++;
readIn >> master2[count2];
}
int size1 = count;
int size2 = count2;
writeFile.open ("NewMaster.txt");
int i=0, j=0;
while ((i<count) && (j<count2))
{
if ((inventory[i].MID < master2[j].TID) && (inventory[i].includeinNewMaster = true))
{
writeFile << inventory[i++];
}
else writeFile << master2[j++];
{
if (i == count)
{
while (count2 <= size2)
writeFile << master2[count2];
}
else
{
while (count <= size1)
writeFile << inventory[count];
}
}
};
readIn.close();
readIn1.close();
readIn2.close();
writeFile.close();
return 0;
}
void checktoAdd(invRecord inventory[], string actionCode)
{
if (transaction.actionCode = A)
{
if (inventory[index].MID = transaction.TID)
{
writeFile.open ("ErrorLog.txt");
writeFile << "Record " << inventory[index].MID << " already exists." << endl;
writeFile.close;
}
else
{
writeFile.open ("Master2.txt");
writeFile << inventory[index] << endl;
writeFile.close;
}
}
return;
}
void checktoDelete(invRecord inventory[], string actionCode)
{
if (transaction.actionCode = D)
{
if (inventory[index].MID = transaction.TID)
{
inventory[index].includeinNewMaster = false;
}
else
{
writeFile.open ("ErrorLog.txt");
writeFile << "Record " << inventory[index].MID << " does not exist in Master.txt." << endl;
writeFile.close;
}
}
return;
}
void checktoEdit1(invRecord inventory[], string actionCode)
{
if (transaction.actionCode = E1)
{
if (inventory[index].MID = transaction.TID)
{
inventory[index].qtyOnHand = (inventory[index].qtyOnHand + transaction.qtyOnHand);
}
else
{
writeFile.open ("ErrorLog.txt");
writeFile << "Record " << inventory[index].MID << " does not exist in Master.txt." << endl;
writeFile.close;
}
}
return;
}
void checktoEdit2(invRecord inventory[], string actionCode)
{
if (transaction.actionCode = E2)
{
if (inventory[index].MID = transaction.TID)
{
(inventory[index].qtyOrdered = transaction.qtyOnHand);
(inventory[index].delDate = transaction.delDate);
}
else
{
writeFile.open ("ErrorLog.txt");
writeFile << "Record " << inventory[index].MID << " does not exist in Master.txt." << endl;
writeFile.close;
}
}
return;
}
void checktoEdit3(invRecord inventory[], string actionCode)
{
if (transaction.actionCode = E3)
{
if (inventory[index].MID = transaction.TID)
{
(inventory[index].delDate = transaction.delDate);
}
else
{
writeFile.open ("ErrorLog.txt");
writeFile << "Record " << inventory[index].MID << " does not exist in Master.txt." << endl;
writeFile.close;
}
}
return;
}
void checktoEdit4(invRecord inventory[], string actionCode)
{
if (transaction.actionCode = E4)
{
if (inventory[index].MID = transaction.TID)
{
(inventory[index].price = transaction.price);
(inventory[index].priceChng = (transaction.price - inventory[index].price));
}
else
{
writeFile.open ("ErrorLog.txt");
writeFile << "Record " << inventory[index].MID << " does not exist in Master.txt." << endl;
writeFile.close;
}
}
return;
}
|