Need some polishing advice or direction on this project.

I used "//" needing attention and direction.
This program will compile if anyone is interested in giving it a whirl.
Any advice pertaining to my situation would be great.
See http://www.cplusplus.com/forum/general/97739/ for previous post.


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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<iostream>
#include<iomanip>
#include<sstream>	
#include<string>
#include<fstream>
#include<Windows.h>
#include<winspool.h>
#include<ctime>


using namespace std;

class InvBin
{
private:
	string description;
	int qty;

public:
	InvBin(string d = "empty", int q = 0)
	{ description = d; qty = q;}

	void setDescription(string d)
	{description = d;}

	string getDescription() const
	{
		string s = description;
		return s;
	}

	void setQty(int q)
	{qty =q;}

	int getQty() const
	{return qty;}
};

const int MAX_BINS = 30;

class BinManager
{
private:
	InvBin bin[MAX_BINS];
	int numBins;
	string toString(int) const;

public:
	BinManager()
	{numBins = 0;}

	BinManager(int, string[], int[]);

	string getDescription(int binNum) const
	{return bin[binNum-1].getDescription();}

	int getQuantity(int binNum) const
	{return bin[binNum-1].getQty();}

	string displayAllBins() const;

	bool addParts(int, int);
	bool removeParts(int, int);
};

BinManager::BinManager(int size, string d[], int q[])
{
	numBins = size;

	for (int item = 0; item < numBins; item++)
	{bin[item].setDescription(d[item]);
	bin[item].setQty(q[item]);
	}
}

string BinManager::displayAllBins()const
{
	string binInfo = "";

	for (int binNum =1; binNum <= numBins; binNum++)
	{
		binInfo +=" " + toString(binNum) + "   " +
			bin[binNum-1].getDescription()+"    "+
			toString(bin[binNum-1].getQty())+"\n";
	}

	return binInfo;
}

string BinManager::toString(int num) const
{
	ostringstream ss;
	ss<<num;
	return ss.str();
}

bool BinManager::addParts(int binNum, int numToAdd)
{
	int loc = binNum -1;

	if (numToAdd > 0)
	{
		bin[loc].setQty(bin[loc].getQty()+numToAdd);
		return true;
	}
	else
		return false;
}

bool BinManager::removeParts(int binNum, int numToRemove)
{
	int loc = binNum -1;

	if (numToRemove > 0 && numToRemove <= bin[loc].getQty())
	{
		bin[loc].setQty(bin[loc].getQty()-numToRemove);
		return true;
	}
	else
		return false;
}

void displayMenu();
int getChoice(int);
void addParts(BinManager &);
void removeParts(BinManager &);
void displayBins(const BinManager &);

const int	BINS_IN_USE = 9,
			MAX_CHOICE = 4,
			QUIT = 4;

int main()
{
int choice;

string itemNames[]={"Regular Pliers     ", "N. Nose Pliers     ",
	"Screwdriver        ", "P. Head Screwdriver", "Wrench-Large       ",
	"Wrench-Small       ", "Drill              ", "Cordless Drill     ",
	"Hand Saw           "};

int quantity[] ={25, 5, 25, 5, 7, 18, 51, 16, 12};

BinManager inventory(9, itemNames, quantity);

displayBins(inventory);

do
{
	displayMenu();
	choice = getChoice(MAX_CHOICE);

	switch (choice)
	{
	case 1: addParts(inventory);
		break;
	case 2: removeParts(inventory);
		break;
	case 3: displayBins(inventory);
		break;
	}
} while(choice != QUIT);

system("cls");


HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(screen,127+12);

cout<<"    **********************    \n"
	<<"     End Of Day Inventory     \n"
	<<"    **********************    \n";
SetConsoleTextAttribute(screen,15);
	displayBins(inventory); 
	
	//I want to output displayBins(inventory) to outputFile see below...
	//Is there a better more efficient way?
	

	ofstream outputFile; 
	outputFile.open("InventoryUpdateSheet.txt");
	time_t now = time(0);
    char* dt = ctime(&now);

	outputFile<< "            "<< dt <<"\n\n"
	<<"            **********************    \n"
	<<"             End Of Day Inventory     \n"
	<<"            **********************    \n"
	<<"____________________________________________________"<<endl
	<<"1.	Regular Pliers          "<<quantity<<endl//Not sure what code here to update output qty to text file?
	<<"2.	N. Nose Pliers          "<<quantity<<endl//Not sure what code here to update output qty to text file?
	<<"3.	Screwdriver             "<<quantity<<endl//Not sure what code here to update output qty to text file?
	<<"4.	P. Head Screwdriver     "<<quantity<<endl//Not sure what code here to update output qty to text file?
	<<"5.	Wrench-Large            "<<quantity<<endl//Not sure what code here to update output qty to text file?
	<<"6.	Wrench-Small            "<<quantity<<endl//Not sure what code here to update output qty to text file?
	<<"7.	Drill                   "<<quantity<<endl//Not sure what code here to update output qty to text file?
	<<"8.	Cordless Drill          "<<quantity<<endl//Not sure what code here to update output qty to text file?
	<<"9.	Hand Saw                "<<quantity<<endl//Not sure what code here to update output qty to text file?
	<<"____________________________________________________\n\n"<<endl
	<<"            Press [Ctrl+P] to print\n";
	
	outputFile.close();
	
	cout<<"\n\nFile opened for printing...\n\n";
	system( "notepad.exe InventoryUpdateSheet.txt" );
	
	system("pause");
	return 0;
}

void displayMenu()
{
	HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(screen,3);
	cout<<"\n\n    Inventory Control Menu \n\n";
	SetConsoleTextAttribute(screen,15);
	cout <<" 1   Add parts to a bin\n";
	cout <<" 2   Remove parts from a bin\n";
	cout <<" 3   Display bin status report\n";
	cout <<" 4   Quit\n\n";
	cout <<"Choose [1-4]: ";
}

int getChoice(int maxChoice)
{
	int choice;
	cin>>choice; // keep to a number, else loop again


	while (choice < 1 || choice > maxChoice)
	{
		cin.clear();
		HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleTextAttribute(screen,4);
		cout<<"Choice must be between 1 and "<<maxChoice
			<<". Re-enter choice: ";
		SetConsoleTextAttribute(screen,15);
		cin>>choice; 
	}
return choice;
}

void addParts(BinManager &inventory)
{
	int binNum,
		numToAdd;

	cout<<"\nEnter bin Number (1- " << BINS_IN_USE << "): ";
	binNum = getChoice(BINS_IN_USE);

	cout<<"\nCurrent status of bin #"<<binNum<<": "
		<<inventory.getDescription(binNum)<<"   "
		<<inventory.getQuantity(binNum)<<"\n\n";
	cout<<"Enter number of parts to be added: ";
	cin>>numToAdd; // keep to a number, else loop again

	if(inventory.addParts(binNum, numToAdd))
	{
		HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleTextAttribute(screen,128);
		cout<<"\nNew status of bin #" <<binNum<<":     "
		<<inventory.getDescription(binNum)<<"   "
		<<inventory.getQuantity(binNum)<<"\n\n", 
		displayBins(inventory);
	}
	else
	{
		HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleTextAttribute(screen,4);
		cout<<"Invalid quanity. Add was not performed.\n";
	}
}

void removeParts(BinManager &inventory)
{
	int binNum,
	numToRemove;

	cout<<"Enter bin Number(1-)" << BINS_IN_USE << "): ";
	binNum = getChoice(BINS_IN_USE);

	cout<<"\nCurrent status of bin #"<<binNum<<": "
		<<inventory.getDescription(binNum)<<"   "
		<<inventory.getQuantity(binNum)<<"\n\n";
	cout<<"Enter number of parts to be removed: ";
	cin>>numToRemove;

	if(inventory.removeParts(binNum, numToRemove))
		{
		HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleTextAttribute(screen,128);
		cout<<"\nNew status of bin #" <<binNum<<":     "
		<<inventory.getDescription(binNum)<<"   "
		<<inventory.getQuantity(binNum)<<"\n\n", 
		displayBins(inventory);
	}
	else
	{
		HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleTextAttribute(screen,4);
		cout<<"Invalid quanity. Add was not performed.\n";
	}
}

void displayBins(const BinManager &inventory)
{
	HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleTextAttribute(screen,5);
	cout<<"______________________________\n"
		<<"Bin        Part            Qty \n"
		<<"______________________________\n";
	SetConsoleTextAttribute(screen,15);
	cout<< inventory.displayAllBins();
}
Last edited on
Topic archived. No new replies allowed.