hi....

can someone please correct the errors of the below given program... i've marked the errors that my compiler showed...

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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#include<fstream.h>
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
#include<iomanip.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

class directory
     {
       public:
	       int record;
	       long pn1;
	       char pn2[10];
	       int age;         //ERROR 1-error: conio.h: No such file or directory

	       char address1[50];
	       char address2[50]; //ERROR 2-error: process.h: No such file or directory


	       char occupation[20];
	       char name[20];
	       char emailadd[25];
	       char internetadd[25];
	       void modification();
	       void addition();
	       void deleate();
	       void menu();
	       void search();
	       void view1();
	       void init();
	       void display();
	       void view();
	       char check(char *);
	       int test();
	    }obj;
void directory::addition()  
    {
      ofstream fout;
      fout.open("heera",ios::out|ios::app);
      init();
      fout.write((char*)&obj,sizeof(obj));
      fout.close();
    }
int directory::test()    
    {
      ifstream fin;
      fin.open("heera");
      fin.seekg(0,ios::end);
      int n;
      n=fin.tellg()/sizeof(obj);
      cout<<" \n NUMBER OF RECORDS = "<<n ;
      return n ;
    }
void directory::search()  
    {
      ifstream fin;
      fin.open("heera");
      if(fin.fail())
	{
	  cout<<" \n FILE NOT FOUND ";
	  getch();  //error: 'getch' was not declared in this scope

	  return;
	}
      clrscr();
      textcolor(BLACK+BLINK);
      gotoxy(30,1);
      cprintf(" [SEARCHING] ");
      cout<<" \n ENTER PHONE NUMBER TO BE SEARCHED : ";
      long pn;
      cin>>pn;
      int n;
      n=test();
      for(int i=0;i<n;i++)
	{
	  fin.read((char*)&obj,sizeof(obj));
	  if(pn==pn1)
	    {
	      view1();
	      return;
	    }
	}
      if(fin.eof())
	{
	  cout<<" \n RECORD NOT FOUND ";
	}
    }
void directory::init() 
    {

      clrscr();
      char ch;
      textcolor(BLACK+BLINK);
      gotoxy(30,1);
      cprintf(" [ADDITION] ");
      textcolor(BLACK);
      cout<<" \n ENTER HOUSE PHONE NUMBER : ";
      cin>>pn1;
      cout<<" \n ENTER OFFICE PHONE NUMBER : ";
      cin>>pn2;
      // ch=cin.get();
      cin.get(ch);
      cout<<" \n ENTER NAME : ";
      cin.getline(name,20,'\n');
      cout<<" \n ENTER THE OCCUPATION : ";
      cin.getline(occupation,20,'\n');
      cout<<" \n ENTER HOUSE ADDRESS : ";
      cin.getline(address1,50,'\n');
      cout<<" \n ENTER OFFICE ADDRESS : ";
      cin.getline(address2,50,'\n');
      cout<<" \n ENTER EMAIL ADDRESS : ";
      cin.getline(emailadd,25,'\n');
      cout<<" \n ENTER INTERNET ADDRESS : ";
      cin.getline(internetadd,25,'\n');
    }

void directory::view1() 
    {
      cout<<"\n";
      cout<<" PHONE NUMBER1 : "<<obj.pn1<<"\n";
      cout<<" PHONE NUMBER2 : "<<obj.pn2<<"\n";
      cout<<" NAME : "<<obj.name<<"\n";
      cout<<" HOUSE ADDRESS : "<<obj.address1<<"\n";
      cout<<" OCCUPATION : "<<obj.occupation<<"\n";
      cout<<" OFFICE ADDRESS : "<<obj.address2<<"\n";
      cout<<" EMAIL ADDRESS : "<<obj.emailadd<<"\n";
      cout<<" INTERNET ADDRESS : "<<obj.internetadd<<"\n";
      getch();
    }
void directory::modification()
     clrscr();
     textcolor(BLACK+BLINK);
     gotoxy(30,1);
     cprintf(" [ MODIFICATION ] ");
     textcolor(BLACK);
     long pn;
     int n,i;
     ifstream fin;
     ofstream fout;
     fin.open("heera");
     if(fin.fail())
       {
	 cout<<"\n FILE NOT FOUND !";
	 fout.close();
	 exit(-1);
       }
    fout.open("new");
    n=test();
    if(n==0)
      {
	cout<<"\n FILE IS EMPTY ! ";
	getch();
	return;
      }
   while(fin.good())
      {
	fin.read((char*)&obj,sizeof(obj));
	fout.write((char*)&obj,sizeof(obj));
      }
   fin.close();
   fout.close();
   fout.open("heera",ios::trunc);
   fin.open("new");
   if(fin.fail())
     {
      cout<<"\n FILE NOT FOUND !";
      exit(-1);
     }
   char ch;
   cout<<"\n ENTER PHONE NUMBER :";
   cin>>pn;
   ch=cin.get();
//   cin.get(ch);
   for(i=0;i<n;i++)
	{
	   fin.read((char*)&obj,sizeof(obj));
	   char d;
	   if(pn==pn1)
	      {
		view1();
		d=check("HOUSE PHONE NUMBER ");
		if((d=='y') || (d=='Y'))
		  {
		    cout<<"\n ENTER NEW PHONE NUMBER :";
		    cin>>pn1;
		    ch=cin.get();
		  //  cin.get(ch);
		  }
		if(check("OFFICE PHONE NUMBER ")=='Y')
		  {
		    cout<<"\n ENTER NEW PHONE NUMBER :";
		    cin>>pn2;
		   ch=cin.get();
		 // cin.get(ch);
		  }
		if(check("NAME")=='y')
		  {
		    cout<<"\n ENTER NEW NAME : ";
		    cin.getline(name,20,'\n');
		  }
		if(check("HOME ADDRESS")=='y')
		  {
		    cout<<"\n ENTER NEW ADDRESS :";
		    cin.getline(address1,50,'\n');
		  }
		if(check("OFFICE ADDRESS")=='y')
		  {
		    cout<<"\n ENTER NEW ADDRESS :";
		    cin.getline(address2,50,'\n');
		  }
		if(check("EMAIL ADDRESS:")=='y')
		  {
		    cout<<"\n ENTER NEW MAIL ADDRESS :";
		    cin.getline(emailadd,25,'\n');
		  }
		if(check("INTERNET ADDRESS")=='y')
		  {
		    cout<<"\n ENTER NEW INTERNET ADDRESS :";
		    cin.getline(internetadd,25,'\n');
		  }
	      }
	   fout.write((char*)&obj,sizeof(obj));
	}
   fout.close();
   fin.close();
    }
char  directory::check(char *s)
    {
       cout<<"\n MODIFY \t "<<s<<"\t"<<"Y/N";
       char ch;
      ch =getch();
      //cin.get(ch);
      if((ch=='y')||(ch=='Y'))
	return 'y';
       else
	return 'n';
    }
void  directory::deleate()
    {
       clrscr();
       window(1,1,80,25);
       textcolor(BLACK+BLINK);
       gotoxy(30,1);
       cprintf("[DELETION]");
       long pn;
       int n,i;
       ifstream fin;
       ofstream fout;
       fin.open("heera");
       if(fin.fail())
	{
	  cout<<"\n FILE NOT FOUND ! ";
	  getch();
	  return;
	}
       fout.open("new");
       n=test();
       if(n==0)
	{
	  cout<<"\n FILE IS EMPTY ! ";
	  getch();
	  return;
	}
      for(i=0;i<n;i++)
	{
	  fin.read((char*)&obj,sizeof(obj));
	  fout.write((char*)&obj,sizeof(obj));
	}
      fin.close();
      fout.close();
      fout.open("meera",ios::trunc);
      fin.open("new");
      if(fin.fail())
	{
	  cout<<"\n FILE NOT FOUND ! ";
	  getch();
	  return;
	}
     cout<<"\n ENTER PHONE NUMBER :";
     cin>>pn;
     for(i=0;i<n;i++)
       {
	 fin.read((char*)&obj,sizeof(obj));
	 if(pn!=pn1)
	    fout.write((char*)&obj,sizeof(obj));
       }
     fout.close();
     fin.close();

    }
 void directory::view()
   {
     ifstream fin;
     int n,j;
     fin.open("heera");
     if(fin.fail()||fin.bad())
       {
	  cout<<"\n FILE NOT FOUND ! ";
	  getch();
	  return;
       }
     clrscr();
     int i=0;
     n=test();
     for(j=0;j<n;j++)
       {
	 cout<<"\n RECORD "<<i+1<<"\n";
	 fin.read((char*)&obj,sizeof(obj));
	 cout<<"\n PHONE NUMBER1 :"<<obj.pn1<<"\n";
	 cout<<"\n PHONE NUMBER2 :"<<obj.pn2<<"\n";
	 cout<<"\n NAME :"<<obj.name<<"\n";
	 cout<<"\n HOUSE ADDRESS :"<<obj.address1<<"\n";
	 cout<<"\n OCCUPATION :"<<obj.occupation<<"\n";
	 cout<<"\n OFFICE ADDRESS :"<<obj.address2<<"\n";
	 cout<<"\n INTERNET ADDRESS :"<<obj.internetadd<<"\n";
	 cout<<"\n EMAIL ADDRESS : "<<obj.emailadd<<"\n";
	 i+=1;
       }
      fin.close();
      getch();

   }

void  directory::menu()
    {
       char ch;
       clrscr();
       textbackground(WHITE);
       textcolor(BLACK);
       gotoxy(30,8);
       cprintf(" A:ADDITION ");
       gotoxy(30,9);
       cprintf(" D: DELETION \n  \r ");
       gotoxy(30,10);
       cprintf(" M:MODIFICATION \n \r ");
       gotoxy(30,11);
       cprintf(" V:VIEW \n \r ");
       gotoxy(30,12);
       cprintf(" S:SEARCH \n \r ");
       gotoxy(30,13);
       cprintf(" E:EXIT \n \r ");
       ch=getch();

      switch(ch)
	   {
	     case 'a':
	     case 'A':
		addition();
		break;
	     case 'd' :
	     case 'D' :
		deleate();
		break;
	     case 'm':
	     case 'M':
		modification();
		break;
	     case 'v':
	     case 'V':
		view();
		break;
	     case 's':
	     case 'S':
		search();
		break;
	     case 'e':
	     case 'E':
		system("cls");
		exit(0);
	 }
}
int main()
    {
      welcome_screen();
      for(;;)
      obj.menu();
      return 0;
   }

Last edited on
Could you please edit your post and use the forum [code] tags? It will help us be able to read it, thanks.

What is the t.cpp file that is referenced on line 21?
Last edited on
1. Read http://www.cplusplus.com/articles/how_to_ask/
2. Use [code][/code] tags
3. that looks pre-standard C++
4.
ERROR 1-error: conio.h: No such file or directory
conio.h isn't a standard header
ERROR 2-error: process.h: No such file or directory
nor is process.h
error: 'getch' was not declared in this scope
getch is from conio which isn't standard
so ... wat changes do i make in da program....? i'm in a situation here.got very little time left.can someone please make the required corrections and post it again.please. :(
iomanip.h is not standard either...
I suggest using standard libraries and getting rid of nonstandard commands like getch as Bazzy suggested.
Last edited on
iomanip.h is not standard either...

iomanip is standard: http://www.cplusplus.com/reference/iostream/manipulators/
( except for that old-style .h )
wat changes do i make in da program....?


If you want to take the advice, then simply remove the conio.h, What methods are you using in it? prehaps we can tell you what you can use instead if you can describe what they do ?

Because I can garuntee that pretty much nobody here will be familar with conio.h, or process.h.

So you need to tell us what methods they use, and what the method does.
No way in hell should anybody be
make the required corrections and post it again
. The point is to give you help, not the answer. Bazzy already directed you to how to ask.
Anyway, I second gcampton; conio and process are both deprecated (heck, I don't even recognize process). Take them both out, get rid of getch and any crap from process, and that should solve most of the problems.
Also, istream.get() does not return a character. You pass the object you want your input to go into; get returns a reference to the istream against which it was called (this).
Besides that I don't see any errors. So that's probably it, unless there are things you didn't mark out on that code.
k... i'm sorry about the "corrections" part of my previous statement...
and thanks for the help.
I assume clrscr();
clears the screen ? 1 example you could do instead of this is simply print 10-20 blank lines. However it's usually bad form to mess with consoles in this way. They are not really necessary, it's fine to be able to scroll up and see what the program has done, it also helps debug errors.

Oh...

Just saw this:
clrscr();
window(1,1,80,25);
textcolor(BLACK+BLINK);
gotoxy(30,1);
cprintf("[DELETION]");

I didn't realize this was a window application, I assumed it was console. your going to need to read up on Windows API if you prefer MS windows, or something x-compatible QT, wxWidgets. etc.
You could read through some posts on the windows forum to find the references you need.
============================================
The other way you could go is trying to get those 2 header files into your project, your going to have to search your computer for them, or download them and put them into your library path.
Last edited on
You are right Bazzy I should have been more specific he probably does not know that the .h ones are old.
Man I hope if he does learn some Windows API, he will at least follow everyone's advice and not use the older unknown/ non-standard functions like getch.
It looks like some old code you got somewhere around the internet or some book after searching.

I don't think you wrote that otherwise you wouldn't be asking for the errors you encountered.

The code you posted compiled just fine on my old BCC compiler. I just had to remove the welcome_screen function which wasn't defined anywhere. It's a console application with a dull but acceptable GUI. This is definitely a very old application you got form a book or internet.

cprintf and textcolor functions are really old ones, I remember using them. You should instead use the SetConsoleTextAttribute function, google it and you'll find what it does. It should work with cout but if it doesn't you'll have to use WriteConsole function.

No function works exactly like the beautiful getch, but you'll have to find other ways. getchar is one. I suggest you go through the msdn website because it's the best place to start.

Last edited on
Topic archived. No new replies allowed.