View difference between Paste ID: gneT021S and 5yT2PyBj
SHOW: | | - or go back to the newest paste.
1
/*Inventory Schildt*/
2
3
#include "stdafx.h"
4
#include <iostream>
5
#include <cctype>
6
#include <cstring>
7
#include <cstdlib>
8
#include <conio.h>
9
using namespace std;
10
11
const int SIZE = 2;
12
13
struct int_type {
14
	char item[40];
15
	double cost;
16
	double retail;
17
	int on_hand;
18
	int lead_time;
19
} invtry[SIZE];
20
21
int status = 0;
22
void enter(), init_list(), display();
23
void update(), input(int i);
24
int menu();
25
26
int find_product();
27
void delete_product(), remove_sklad();
28
int testEmpty();
29
30
31
int main() {
32
	
33
	char choice;
34
35
	init_list();
36
37
	choice = menu();
38
39
	for (;;) {
40
		switch (choice)
41
		{
42
		case 'e': enter();
43
			break;
44
		case 'd': display();
45
			break;
46
		case 'u': update();
47
			break;
48
		case 'f': find_product();
49
			break;
50
		case 'w': delete_product();
51
			break;
52
		case 'r': remove_sklad();
53
			break;
54
		case 'q': return 0;
55
		}
56
		
57
58
		if (status == -1) {
59
			cout << "Choise a new comand: " << endl;
60
			choice = menu();
61
		}
62
		
63
	}
64
65
	return 0;
66
}
67
68
void init_list() {
69
	for (int i = 0; i < SIZE; i++) {
70
		*invtry[i].item = '\0';
71
	}
72
}
73
74
int menu() {
75
	char ch;
76
77
	do {
78
		cout << "(E)nter" << endl;
79
		cout << "(D)isplay" << endl;
80
		cout << "(U)pdate" << endl;
81
		cout << "(F)ind product" << endl;
82
		cout << "(W)ithdrawal product" << endl;
83
		cout << "(R)emove inventory" << endl;
84
		cout << "(Q)uit" << endl << endl;
85
		if(status != -1) cout << "Choise a comand: ";
86
		cin >> ch;
87
	} while (!strchr("eduqfwr", tolower(ch)));
88
	
89
	return tolower(ch);
90
}
91
92
void enter() {
93
	int i;
94
95
	for (i = 0; i < SIZE; i++) {
96
		if (!*invtry[i].item) break;
97
	}
98
99
	if (i == SIZE) {
100
		cout << "List is full" << endl << endl;
101
		status = -1;
102
		return;
103
	}
104
105
	input(i);
106
}
107
108
void input(int i) {
109
	cout << "Name: ";
110
	cin >> invtry[i].item;
111
112
	cout << "Cost: ";
113
	cin >> invtry[i].cost;
114
115
	cout << "Retail cost: ";
116
	cin >> invtry[i].retail;
117
118
	cout << "On hand: ";
119
	cin >> invtry[i].on_hand;
120
121
	cout << "Time: ";
122
	cin >> invtry[i].lead_time;
123
	cout << endl;
124
}
125
126
void update() {
127
	int i;
128
	i = find_product();
129
130
	if (i != -1) {
131
		cout << "Enter new information's." << endl;
132
		input(i);
133
	}
134
}
135
136
void display() {
137
	if (testEmpty() == 1) {
138
		for (int i = 0; i < SIZE; i++) {
139
			if (*invtry[i].item) {
140
				cout << invtry[i].item << endl;
141
142
				cout << "Cost: " << invtry[i].cost << endl;
143
144
				cout << "Retail cost: " << invtry[i].retail << endl;
145
146
				cout << "On hand: " << invtry[i].on_hand << endl;
147
148
				cout << "Time: " << invtry[i].lead_time << endl << endl;
149
150
			}
151
		}
152
	}
153
	else {
154
		cout << "Inventory is empty." << endl << endl;
155
	}
156
}
157
158
int find_product() {
159
	int i;
160
	char name[40];
161
162
	cout << "Enter name of product: ";
163
	cin >> name;
164
165
	for (i = 0; i < SIZE; i++) {
166
		if (!strcmp(name, invtry[i].item)) break;
167
	}
168
169
	if (i == SIZE) {
170
		cout << "Product is not found" << endl << endl;
171
		return -1;
172
	}
173
	else {
174
		cout << "Product is found. His index: " << i << endl << endl;
175
		return i;
176
	}
177
178
}
179
180
void delete_product() {
181
	int index;
182
	cout << "Deliting product. ";
183
	index = find_product();
184
185
	if (index != -1) {
186
		*invtry[index].item = '\0';
187
	}
188
189
}
190
191
void remove_sklad() {
192
	for (int i = 0; i < SIZE; i++) {
193
		*invtry[i].item = '\0';
194
	}
195
}
196
197
int testEmpty() {
198
	int i;
199
	for (i = 0; i < SIZE; i++) {
200
		if (*invtry[i].item) break;
201
	}
202
	if (i == SIZE) {
203
		status = -1;
204
		return -1;
205
	}
206
	else return 1;
207
}