-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathU_DIC.CPP
More file actions
executable file
·238 lines (218 loc) · 4.98 KB
/
U_DIC.CPP
File metadata and controls
executable file
·238 lines (218 loc) · 4.98 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
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
//DICTIONARY APPLICATION
#include "MACROS.CPP"
#define WL "wlist.db"
#define ML "mlist.db"
void dic_about()
{
clrscr();
cout << "------------------------------- DICTIONARY -----------------------------------\n\n"
<< "\tDICTIONARY is a product of the OSCorp Corporation.\n"
<< "\tAny attempt to copy the copyrighted products eg. the functional\n"
<< "\talgorithms, or the functional technique is liable to punishable offence.\t"
<< "\n\tAll rights reserved."
<< "\n\n\tThis product is licensed under the OSCorp Software License Terms"
<< "\n\tto the product owner.";
GETCH_MSG;
getch();
}
class DB
{
char *word;
char *meaning;
public:
DB();
void write();
void read();
void read_full();
void clear_db();
};
void DB::clear_db()
{
ifstream file(ML);
file.seekg(0, ios::end);
int size=file.tellg();
file.close();
while(1)
{
clrscr();
cout << "\nAre you sure to clean up the entire Dictionary database?\n"
<< "\t[Size of Dictionary database:\t"<< size <<" Byte(s)]\n"
<< "\n\n[Press 'y' for Yes and 'n' for No]\n"
<< "Your choice:\t";
switch(getche())
{
case 'y':
{
if(size==0)
{
cout << "\n\nError: Dictionary Database is already empty! [Size = 0 Byte]\n";
GETCH_MSG;
getch();
return;
}
ofstream filew(WL);
ofstream filem(ML);
filew.close();
filem.close();
cout << "\n\nDatabase cleared! Current Database size: 0 Byte";
GETCH_MSG;
getch();
return;
}
case 'n': {return;}
default:
{
cout << "\nError: Wrong input entered! Please try again!\n\n";
GETCH_MSG;
getch();
}
}
}
}
void DB::read_full()
{
clrscr();
ifstream file(ML);
file.seekg(0, ios::end);
if(file.tellg()==0)
{
cout << "\n\nError: Dictionary Database is empty!\n";
GETCH_MSG;
getch();
return;
}
cout << "----------The contents of the dictionary are:-------------\n\n";
file.seekg(0, ios::beg);
char ch;
while(file.eof()==0)
{
file.get(ch);
cout.put(ch);
}
cout << "\n\n--------------End of the Dictionary Database!-------------";
GETCH_MSG;
getch();
file.close();
return;
}
DB::DB()
{
fstream filew(WL, ios::app);
fstream filem(ML, ios::app);
filew.close();
filem.close();
}
void DB::read()
{
char query[80];
while(1)
{
clrscr();
cout << "\nEnter the word:\t";
cin.getline(query, 80);
if(strcmp(query, "")==0)
{
cout << "\nError: Please enter a non-null input.";
GETCH_MSG;
getch();
}
else
break;
}
int len=(strlen(query)+1); int pos=0;
ifstream ifile(ML);
ifile.seekg(0, ios::beg);
char temp[200];
while(ifile.eof()==0)
{ pos=ifile.tellg();
ifile.getline(temp, 200);
if(strncmp(query, temp, len)==0)
{
ifile.seekg(pos, ios::beg);
//ifile.getline(temp, 200);
cout << "\n\n[ Word : Meaning ]\n";
char ch;
do
{
ifile.get(ch);
cout.put(ch);
}while(ch!='\n');
GETCH_MSG;
getch();
return;
}
}
cout << "\n\nWord is not present in the Database!"; GETCH_MSG;
getch();
return;
}
void DB::write()
{
clrscr();
cout << "\nEnter the word:\t";
char *temp;
cin.getline(temp, 80);
word = new char[strlen(temp)+1];
strcpy(word, temp);
cout << "Enter the meaning:\t";
cin.getline(temp, 200);
meaning = new char[strlen(temp)+1];
strcpy(meaning, temp);
//Checking for duplicacy
fstream filew(WL, ios::app);
ifstream file(WL);
file.seekg(0, ios::beg);
file.getline(temp, 80); //cout << "\nword: " << word << " temp: " << temp << endl; int i=0;
while(file.eof()==0)
{ //cout << "\nRound: " << i++;
if(strcmp(temp, word)==0)
{
cout << "\nError: Word is already present in the database!"; GETCH_MSG;
file.close();
filew.close();
getch();
return;
}
else
{
file.getline(temp, 80);
}
}
fstream filem(ML, ios::app);
filew.seekp(0, ios::end);
filem.seekp(0, ios::end);
filew.write(word, (strlen(word)+1)); filew << endl;
filem.write(word, (strlen(word)+1)); filem << ":\t";
filem.write(meaning, (strlen(meaning)+1)); filem << endl;
cout << "\n\tSuccessfully entered into the database!\n";
GETCH_MSG;
getch();
filew.close();
filem.close();
return;
}
void dictionary()
{
DB dic;
while(1)
{ clrscr();
cout << "\n----------------------- Welcome to DICTIONARY -------------------------------\n\n"
<< "1. Enter in Dictionary database\n"
<< "2. Search Dictionary for word meaning\n"
<< "3. Read entire Dictionary database\n"
<< "4. Clear Dictionary database\n"
<< "5. About Dictionary.EXE\n"
<< "6. Exit program\n\n"
<< "Enter your choice:\t";
switch(getche())
{
case '1': { dic.write(); break; }
case '2': { dic.read(); break;}
case '3': { dic.read_full(); break; }
case '4': { dic.clear_db(); break; }
case '5': { dic_about(); break; }
case '6': return;
default: {cout << "\nSorry! Wrong input entered! Please try again!"; sleep(2); }
}
}
}