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
|
/*---------------------------------------------------------------------------
Program: P09.cpp
Author: Your Name
---------------------------------------------------------------------------*/
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <fstream>
#include <assert.h>
using namespace std;
using namespace System;
const char *INFILEM = "P09M.DAT";
const char *INFILET = "P09T.DAT";
const char *AUTHOR = "Joshua Lefelhocz Assignment 9";
const char *HEAD1 = "OLD INVENTORY";
const char *HEAD2 = "NEW INVENTORY";
const char *HEAD3 = "ITEM NO QUANTITY";
const char *MESS = "Invalid Part# ";
void PrintMaster(const int Parts[], const int OldStock[], const int size);
void PrintMaster(const int Parts[], const int OldStock[],
const int NewStock[], const int size);
// The function, PrintMaster(), is Overloaded
int FindMatchIndex(const int Parts[], const int size, const int partNum);
// Complete code for this function is provided
void PrintInvalid(const int Invalid[], const int invalidCount);
// Complete code for this function is provided
void Pause(); // Complete code for this function is provided
void main()
{
int Parts[10], OldStock[10], NewStock[10], Invalid[25];
int k, partNum, quantity, invalidCount = 0;
int matchIndex;
Console::Clear();
//..... Print Headings (First Screen)
ifstream InfileM(INFILEM); //..... Open Master File:
assert(InfileM);
for (k = 0; k<10; k++) {
InfileM >> Parts[k] >> OldStock[k];
NewStock[k] = OldStock[k];
}
//..... Read Master File data and load arrays Parts[] and OldStock[]
//..... Copy OldStock[] to NewStock[]
InfileM.close(); //..... Close Master File:
PrintMaster(Parts, OldStock, 10);
Pause();
//..... Print Headings (Second Screen)
ifstream InfileT(INFILET); //..... Open Transaction File
assert(InfileT);
while (InfileT >> partNum >> quantity)
{
//..... Process Transactions
matchIndex = FindMatchIndex(Parts, 10, partNum);
for (k = 0; k < 25; k++)
{
if (partNum == matchIndex)
{
quantity = NewStock[k] - quantity;
}
else
{
InfileT >> Invalid[k] >> partNum;
}
InfileT >> quantity >> NewStock[k];
while (invalidCount < 5)
invalidCount = invalidCount++;
}
} //while
InfileT.close(); //....... Close Transaction File
PrintMaster(Parts, OldStock, NewStock, 10);
cout << endl << endl;
PrintInvalid(Invalid, invalidCount);
} //main()
/*------------------ Function: Pause() ------------------------------------*/
void Pause()
{
Console::SetCursorPosition(1, 24);
cout << "Hit any key to continue.......";
_getch();
Console::Clear();
} //Pause()
/*------------------ Function: PrintMaster() ------------------------------*/
void PrintMaster(const int Parts[], const int OldStock[], const int size)
{
cout << AUTHOR << endl << HEAD1 << endl << HEAD3 << endl;
for (int i = 0; i<size; i++)
{
cout << setw(5) << Parts[i] << setw(11) << OldStock[i] << endl;
}
} //PrintMaster()
/*------------------ Function: PrintMaster() ------------------------------*/
void PrintMaster(const int Parts[], const int OldStock[],
const int NewStock[], const int size)
{
cout << AUTHOR << endl << HEAD2 << endl << HEAD3 << endl;
for (int i = 0; i<size; i++)
{
cout << setw(5) << Parts[i] << setw(11) << NewStock[i] << endl;
}
} //PrintMaster()
/*------------------ Function: FindMatchIndex() ---------------------------*/
int FindMatchIndex(const int Parts[], const int size, const int partNum)
{
for (int k = 0; k<size; k++) if (Parts[k] == partNum) return k;
return -1;
} //FindMatchIndex()
/*------------------ Function: PrintInvalid() -----------------------------*/
void PrintInvalid(const int Invalid[], const int invCount)
{
for (int k = 0; k<invCount; k++) cout << endl << setw(45) << MESS << Invalid[k];
}
/*------------------ End of File: P09.cpp ---------------------------------*/
|