-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.cpp
More file actions
175 lines (167 loc) · 3.79 KB
/
common.cpp
File metadata and controls
175 lines (167 loc) · 3.79 KB
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
#include<iostream>
#include<fstream>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include <windows.h>
#include<limits>
#include<ctype.h>
#define KEY_SPACE 32 //Space Bar
#define KEY_x 120 //x key
#define KEY_X 88 //X key
#define KEY_0 48 //0
#define KEY_1 49 //1
#define KEY_2 50 //2
#define KEY_3 51 //3
#define KEY_4 52 //4
#define KEY_5 53 //5
#define KEY_6 54 //6
#define KEY_7 55 //7
#define KEY_8 56 //8
#define KEY_9 57 //9
using namespace std;
#ifndef INVENTORY
#define INVENTORY
class inventory
{
private:
int sno; //serial number
char nam[30]; //name of item
char typ[20]; //type of item
float cst; //cost
int qnt; //quantity
//date of manufacture
int dd;
int mm;
int yy;
public:
int serial() //accessor funtion for serial number
{
return sno;
}
char*type()
{
return typ;
}
char*name()
{
return nam;
}
void input() //takes input from user
{
cout << "SERIAL NUMBER: "; cin >> sno;
while (cin.fail() || cin.peek() != '\n') //int input validation
{
cin.clear();
cin.ignore();
cout << "You have entered wrong input. Re-Enter: ";
cin >> sno;
}
cin.ignore();
cout << "TYPE OF ITEM: "; cin.getline(typ,20);
cout << "NAME OF ITEM: "; cin.getline(nam,30);
cout << "COST OF ITEM: "; cin >> cst;
while (cin.fail() || cin.peek() != '\n') //int input validation
{
cin.clear();
cin.ignore();
cout << "You have entered wrong input. Re-Enter: ";
cin >> cst;
}
cin.ignore();
cout << "QUANTITY OF ITEM: "; cin >> qnt;
while (cin.fail() || cin.peek() != '\n') //int input validation
{
cin.clear();
cin.ignore();
cout << "You have entered wrong input. Re-Enter: ";
cin >> qnt;
}
cin.ignore();
cout << "Enter Date (DD/MM/YY): ";
while (inDates(dd, mm, yy));
}
void output() //displays the details of the data members
{
cout << "SERIAL NUMBER: " << sno << endl;
cout << "TYPE OF ITEM: " << typ << endl;
cout << "NAME OF ITEM: " << nam << endl;
cout << "COST OF ITEM: " << cst << endl;
cout << "QUANTITY OF ITEM: " << qnt << endl;
cout << "Enter Date: " << dd << "/" << mm << "/" << yy << endl;
}
int key() //key input fuction
{
char key = _getch();
int value = key;
while (value != KEY_0 && value != KEY_1 && value != KEY_2 && value != KEY_3 && value != KEY_4 && value != KEY_5 && value != KEY_6 && value != KEY_7 && value != KEY_8 && value != KEY_9 && value != KEY_SPACE && value != KEY_X && value != KEY_x)
{
key = _getch();
value = key;
}
if (value == KEY_0)
return 0;
if (value == KEY_1)
return 1;
if (value == KEY_2)
return 2;
if (value == KEY_3)
return 3;
if (value == KEY_4)
return 4;
if (value == KEY_5)
return 5;
if (value == KEY_6)
return 6;
if (value == KEY_7)
return 7;
if (value == KEY_8)
return 8;
if (value == KEY_9)
return 9;
if (value == KEY_SPACE)
return 11;
if (value == KEY_X || value == KEY_x)
return 22;
}
//dates date;
int inDates(int&d, int&m, int&y) //takes date input in [day of year]/[month]/[year] format
{
cin >> d; // read the day
if (cin.get() != '/') // make sure there is a slash between DD and MM
{
cout << "Expected '/'. Re-Enter Date: ";
return 1;
}
cin >> m; // read the month
if (cin.get() != '/') // make sure there is a slash between MM and YYYY
{
cout << "Expected '/'. Re-Enter Date: ";
return 1;
}
cin >> y; //read the year
return 0;
}
};
inline int isSame(char a[], char b[])
{
int flag = 0;
if (strlen(a) == strlen(b))
{
for (int i = 0; i < strlen(a); i++)
{
if (a[i] != b[i])
{
flag = 1;
break;
}
}
}
else
return 0;
if (flag)
return 0;
else
return 1;
}
#endif // !COMMON