-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathU_WP.CPP
More file actions
executable file
·346 lines (322 loc) · 10.3 KB
/
U_WP.CPP
File metadata and controls
executable file
·346 lines (322 loc) · 10.3 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
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#include "MACROS.CPP"
void about_wp()
{
clrscr();
cout << " -------------------------- WORD PROCESSOR -----------------------------------\n\n"
<< "\tWORD PROCESSOR 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();
}
void read()
{
char name[20];
CHECK:;
cout << "\nEnter the name of the file:\t"; cin >> name;
ifstream file(name);
if(file.bad())
{
file.close();
cout << "\nError: No such file was found!\nPlease check the name of the file you entered!\n";
ASK:;
cout << "\n\nDo you want to enter a new name to the file? [y/n]\nPlease enter a choice:\t";
switch(getche())
{
case 'y': { goto CHECK; }
case 'n': { return; }
default: { cout << "\nError: Wrong choice entered! Please enter a valid input!"; sleep(1); goto ASK; }
}
}
else
{
file.seekg(0, ios::beg);
char ch; int spaces=0, lines=0, characters=0, check_lines=1;
cout << "\n\n--------------------The contents of the file are:---------------------------\n";
while(file)
{
file.get(ch);
cout.put(ch);
characters++;
if(ch==' ')
spaces++;
if(ch=='\n')
{ lines++; check_lines++; }
if(check_lines%20==0)
{
check_lines++;
cout << "\n\n";
gotoxy(1, 25);
textcolor(BLUE);
//textbackground(WHITE);
cprintf("\n\t----------Press any key to continue---------------\t");
textcolor(WHITE);
cout << "\n\n";
getch();
}
}
cout << "\n";
textcolor(YELLOW);
cprintf("\t------------------------- END OF FILE ---------------------------------\t");
textcolor(WHITE);
file.seekg(0, ios::end);
cout << "\n\n[DETAILS: Total number of characters entered: "<< characters
<< "\nTotal number of spaces entered: "<< spaces
<< "\nTotal number of lines entered: " << lines
<< "\n\nTotal size of the current document: "<< file.tellg() << " Byte(s)";
getch();
}
file.close();
}
void write_new()
{
char name[9];
cout << "\nEnter the name of the file with extension [maximum 8 characters]:\t"; cin >> name;
CHECK:;
ifstream ifile(name);
if(ifile.bad()==0)
{
ifile.close();
cout << "\nError: A file of the same name already exists!\nPlease either enter an another name for the file or goto menu and select the\noption [4] Overwrite an existing file.\n";
ASK:;
cout << "\n\nDo you want to enter a new name to the file? [y/n]\nPlease enter a choice:\t";
switch(getche())
{
case 'y': { cout << "\n\nEnter another name for the file:\t"; cin >> name; goto CHECK; }
case 'n': { return; }
default: { cout << "\nError: Wrong choice entered! Please enter a valid input!"; sleep(1); goto ASK; }
}
}
ifile.close();
cout << "\n\nInstruction: Enter the desired contents of the file. Terminate the writing\nprocess to the file by entereing a \"`\" [tilde] symbol.\n\n"
<< "Please enter the contents of the file:\n\n---------------------------------------------------------------------------\n";
char ch; int spaces=0, lines=0, characters=0;
ofstream file(name);
do
{
cin.get(ch);
if(ch!='`')
file << ch;
if(ch!='`')
characters++;
if(ch==' ')
spaces++;
if(ch=='\n')
lines++;
}
while(ch!='`');
cout << "\n---------------------File writing terminated!-------------------------------"
<< "\n\n[DETAILS: Total number of characters entered: "<< characters
<< "\nTotal number of spaces entered: "<< spaces
<< "\nTotal number of lines entered: " << lines
<< "\n\nTotal size of the current document: "<< file.tellp() << " Byte(s)";
getch();
file.close();
return;
}
void append()
{
char name[20];
cout << "\nEnter the name of the file:\t"; cin >> name;
CHECK:;
ifstream ifile(name);
if(ifile.bad()!=0)
{
ifile.close();
cout << "\n\nError: No such file exists!\nPlease either enter the name of the file correctly or goto menu and select\na proper option.";
ASK:;
cout << "\n\nDo you want to enter the name of the file again? [y/n]\nPlease enter a choice:\t";
switch(getche())
{
case 'y': { cout << "\n\nEnter the name of the file:\t"; cin >> name; goto CHECK; break; }
case 'n': { return; }
default: { cout << "\nError: Wrong choice entered! Please enter a valid input!"; sleep(1); goto ASK; }
}
}
ifile.close();
cout << "\n\nInstruction: Enter the desired contents of the file. Terminate the writing process to the file by entereing a \"`\" [tilde] symbol.\n\n"
<< "Please enter the contents of the file:\n\n---------------------------------------------------------------------------\n";
char ch; int spaces=0, lines=0, characters=0;
fstream file(name, ios::app);
do
{
cin.get(ch);
if(ch!='`')
file << ch;
if(ch!='`')
characters++;
if(ch==' ')
spaces++;
if(ch=='\n')
lines++;
}
while(ch!='`');
cout << "\n---------------------File writing terminated!-------------------------------"
<< "\n\n[DETAILS: Total number of characters entered: "<< characters
<< "\nTotal number of spaces entered: "<< spaces
<< "\nTotal number of lines entered: " << lines
<< "\nTotal size of the current document: "<< file.tellp() << " Byte(s)";
getch();
file.close();
return;
}
void overwrite()
{
char name[9];
cout << "\nEnter the name of the file with extension [maximum 8 characters]: "; cin >> name;
CHECK:;
ifstream ifile(name);
if(ifile.bad()!=0)
{
ifile.close();
cout << "\n\nError: No such file found!\nPlease either enter the correct name of the file or goto menu and select\na proper option.";
ASK:;
cout << "\n\nDo you want to enter the name of the file? [y/n]\nPlease enter a choice:\t";
switch(getche())
{
case 'y': { cout << "\nEnter the name of the file:\t"; cin >> name; goto CHECK; break; }
case 'n': { return; }
default: { cout << "\n\nError: Wrong choice entered! Please enter a valid input!"; sleep(1); goto ASK; }
}
}
ifile.close();
cout << "\n\nInstruction: Enter the desired contents of the file. Terminate the writing process to the file by entereing a \"`\" [tilde] symbol.\n\n"
<< "Please enter the contents of the file:\n\n---------------------------------------------------------------------------\n";
char ch; int spaces=0, lines=0, characters=0;
ofstream file(name);
do
{
cin.get(ch);
if(ch!='`')
file << ch;
if(ch!='`')
characters++;
if(ch==' ')
spaces++;
if(ch=='\n')
lines++;
}
while(ch!='`');
cout << "\n---------------------File writing terminated!-------------------------------"
<< "\n\n[DETAILS: Total number of characters entered: "<< characters
<< "\nTotal number of spaces entered: "<< spaces
<< "\nTotal number of lines entered: " << lines
<< "\nTotal size of the current document: "<< file.tellp() << " Byte(s)";
getch();
file.close();
return;
}
void copy()
{
char filename[80];
CHECK:;
cout << "\n\nEnter source file name:\t";
cin >> filename;
ifstream ifile(filename);
if(ifile.bad()!=0)
{
ifile.close();
cout << "\n\nError: No such file found!\nPlease either enter the correct name of the file or goto menu and select\na proper option.";
ASK:;
cout << "\n\nDo you want to enter the name of the file? [y/n]\nPlease enter a choice:\t";
switch(getche())
{
case 'y': { goto CHECK; break; }
case 'n': { return; }
default: { cout << "\n\nError: Wrong choice entered! Please enter a valid input!"; sleep(1); goto ASK; }
}
}
ifile.close();
cout << "\nEnter destination file name:\t";
char fdest[80];
cin >> fdest;
ifstream f(filename);
ofstream of(fdest);
cout << "Do you want to view the contents of the file " << filename << "?"
<< " [y = Yes, n = No]\nEnter your choice:\t";
int flag=0;
switch(getche())
{
case 'y': {
cout << "\n\n------------- Contents of file: " << filename << " : ----------------\n";
flag=1; break; }
case 'n': { flag = 0; break;}
default: { cout << "\nWrong choice entered! Taking response as negative!\n"; break; }
}
f.seekg(0, ios::beg);
of.seekp(0, ios::beg);
char ch;
int count=0, space=0, lines=0, count_lines=1;
while(f)
{
f.get(ch);
if(flag==1)
cout << ch;
of << ch;
count++;
if(ch==' ')
space++;
if(ch=='\n')
{ count_lines++; lines++; }
if(flag==1)
{
if(count_lines%20==0)
{
count_lines++;
gotoxy(1, 25);
textcolor(BLUE);
cout << "\n\n";
//textbackground(WHITE);
cprintf("\t----------Press any key to continue---------------\t");
textcolor(WHITE);
cout << "\n\n";
getch();
}
}
}
of.seekp(0, ios::end);
if(flag==1)
cout << "\n";
textcolor(YELLOW);
cprintf("\t------------------------- END OF FILE ---------------------------------\t");
textcolor(WHITE);
cout << "\n\n[FILE DETAILS:\n\nNumber of characters:\t" << count
<< "\nNumber of spaces in the file:\t" << space
<< "Number of lines in the file:\t" << lines
<< "\nTotal size of the fle:\t" << of.tellp() <<" Byte(s)]\n\n";
of.close();
f.close();
getch();
return;
}
void word_processor()
{
clrscr();
while(1)
{
clrscr();
cout << "\n\n\t\t-------------- WORD PROCESSOR --------------";
cout << "\n\n\t[1] Read from an existing file";
cout << "\n\t[2] Write to a new file";
cout << "\n\t[3] Append to an existing file";
cout << "\n\t[4] Overwrite an existing file";
cout << "\n\t[5] Copy from one file to another";
cout << "\n\t[6] About WORD PROCESSOR";
cout << "\n\t[7] Exit the program";
cout << "\n\nEnter your choice:\t";
switch(getche())
{
case '1': read(); break;
case '2': write_new(); break;
case '3': append(); break;
case '4': overwrite(); break;
case '5': copy(); break;
case '6': about_wp(); break;
case '7': return;
default: cerr << "\nWrong entry! Please try again...\n";
}
}
}