problem in search

Pages: 12
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
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<process.h>

	class car
	{
		public:
		int carno;
		char model[20],mf[20],chno[10],col[15],des[100];
		int mil,price;
	void accept()
		{
		clrscr();
		cout<<"\tEnter The Special Car Number";cin>>carno;
		cout<<"\tEnter The Manufacturer\n";cout<<"\t";gets(mf);
		cout<<"\tEnter The  Model Of Car";cout<<"\t";gets(model);
		cout<<"\tEnter The Color";cout<<"\t";gets(col);
		cout<<"\tEnter The Price";cout<<"\t";cin>>price;
		cout<<"\tEnter The Mileage";cout<<"\t";cin>>mil;
		cout<<"\tEnter The Chasis Number";cout<<"\t";gets(chno);
		cout<<"\tEnter Description";cout<<"\t";gets(des);
		getch();
		}
	void print()
		{
		clrscr();
		cout<<"Special Car Number";
		cout<<carno;
		cout<<"\nManufacturer\n";
		puts(mf);
		cout<<"\nModel";
		puts(model);
		cout<<"\nColor";
		puts(col);
		cout<<"\nPrice";
		cout<<price;
		cout<<"\nMileage";
		cout<<mil;
		cout<<"\nChasis Number";
		puts(chno);
		cout<<"\nDescription";
		puts(des);
		getch();
		}
		friend void intro();
		friend void write();
		friend void read();
		friend void search_carno();
		friend void search_model();
		friend void search_manu();
		friend void search_chno();
		friend void delete_inf();
		friend void modify();
		friend void search_main();
	};
		void intro()
			{
			clrscr();
			gotoxy(11,11);
			cout<<"\tTHIS PROJECT IS MADE BY NARENDRA SINGH";
			gotoxy(13,15);
			cout<<"\t\tTHIS PROJECT IS MADE FOR CAR SHOWROOM";
			getch();
			}
		void write()
			{
				car c;
				clrscr();
				ofstream file("car.rms",ios::binary|ios::app);
				c.accept();
				file.write((char*)&c,sizeof(c));
				file.close();
			}
		void read()
			{
				car c;
				ifstream file("car.rms",ios::binary);
				while(file.read((char*)&c,sizeof(c)))
				c.print();
				file.close();
			}
		void search_carno()
			{
				car c;
				ifstream file("car.rms",ios::binary);
				int x,found=-1;
				cout<<" Enter Car Number To Be Searched\n ";
				cin>>x;
				while(file.read((char*)&c,sizeof(c)))
					{
					if(c.carno==x)
						{
						found=1;
						c.print();
						}
					}
					file.close();
					if(found==-1)
					{
					cout<<"No Result Found";
					       getch();
					}
				}

		void search_model()
			{
				car c;
				ifstream file("car.rms",ios::binary);
				char y[20];
				clrscr();
				cout<<"Enter Model To Be Searched\n";
				gets(y);
				int l=(strlen(y));
				int found=-1;
				while (file.read((char*)&c,sizeof(c)))
					{
					if(strncmp(c.model,y,l==0))
						{
						c.print();
						found=1;
						}
					}
				if(found==-1)
				       {
					cout<<"No Result Found";
			}               getch();
			}
		void search_chno()
			{
				car c;
				ifstream file("car.rms",ios::binary);
				char y[10];
				clrscr();
				cout<<"Enter Chasis Number To Be Searched\n";
				gets(y);
				int l=(strlen(y));
				int found=-1;
				while (file.read((char*)&c,sizeof(c)))
					{
					if(strncmp(c.chno,y,l==0))
						{
						c.print();
						found=1;
						}
					}
				if(found==-1)
				      {
					cout<<"No Result Found";
					getch();
				      }
			   }

		void search_manu()
			{
				car c;
				ifstream file("car.rms",ios::binary);
				char m[20];
				clrscr();
				cout<<"\t\tEnter Manufacturer To Be Searched\n";
				gets(m);
				int l=(strlen(m));
				int found=0;
				while (file.read((char*)&c,sizeof(c)))
					{
					if(strncmp(c.mf,m,l==0))
						{
						c.print();
						found=1;
						}
					}
				if(found==0)
					cout<<"No Result Found";
			}
		void delete_record()
			{
				car c;
				clrscr();
				ifstream file1("car.rms",ios::binary);
				ofstream file2("temp.rms",ios::binary);
				int d;
				cout<<"\t\tEnter The Car Number\n";
				cin>>d;
				while(file1.read((char*)&c,sizeof(c)));
				{
				if(c.carno!=d)
					{
					file2.write((char*)&c,sizeof(c));
					}
				}
			file1.close();
			file2.close();
			remove("car.rms");
			rename("temp.rms","car.rms");
			}
		void modify()
			{
				car c1,c2;
				clrscr();
				ifstream file1("car.rms",ios::binary);
				ofstream file2("temp.rms",ios::binary);
				int o;
				cout<<"\t\tEnter Car Number To Be Modified ";
				cin>>o;
				while(file1.read((char*)&c1,sizeof(c1)));
					{
					if(c1.carno==o)
						{
						c2.accept();
						file2.write((char*)&c2,sizeof(c2));
						}
					else
					file2.write((char*)&c1,sizeof(c1));
					}
					file1.close();
					file2.close();
					remove("car.rms");
					rename("temp.rms","car.rms");
			}
		void search_main()
			{
					int ch;

				do{
					clrscr();
					gotoxy(9,0);
					cout<<"\t\t\tTHE CAR SHOWROOM PROGRAM\n ";
					cout<<"\t\tSearch Menu\n";
					cout<<"\n\n\t\t1.By Carno\n \t\t2.By Model\n \t\t3.By Manufacturer\n \t\t4.By Chasis No.\n \t\t5.Return To Main Menu\n";
					cout<<"\t\t";cin>>ch;
					switch(ch)
					{
						case 1:search_carno();break;
						case 2:search_model();break;
						case 3:search_manu();break;
						case 4:search_chno();break;
						default:exit(0);break;
					}
				}while(ch!=5);

			}
		void main()
			{
				clrscr();
				intro();
				int ch;
			do{     clrscr();
				gotoxy(9,0);
				cout<<"\t\t\tTHE CAR SHOWROOM PROGRAM\n";
				cout<<"\t\t\tMAIN MENU\n\n \t\t\t1.ADD\n \t\t\t2.READ\n \t\t\t3.Search\n \t\t\t4.Delete\n \t\t\t5.Modify\n \t\t\t6.Close Program\n";
				cout<<"\tENTER YOUR CHOICE";cin>>ch;
				switch(ch)
				{
				case 1:write();break;
				case 2:read();break;
				case 3:search_main();break;
				case 4:delete_record();break;
				case 5:modify();break;
				default:exit(0);
				}
			}while(ch!=6);
			getch();
			}
Last edited on
Are your program:
1) Not compiles
    * Is other code compiles correctly, i. e. is your compiler configured properly
    * If so, give us error message and corresponding code part.
2) Not running
    * Are you sure that it is not a problem with automatically closing console?
    * How do you run it?
    * Is there any error messages?
3) Gives an error when run
    * Is it system error message or error reported in console?
    * Give us error message and input which leads to error.
4) Not giving correct results
    * Tell what you entered, what you expected, and what you got.
    * Are you sure that results you expected are correct?
not giving correct result in search menu.
What did you enter, what did you got, what did you expect?

Also explait what does tid do:
strncmp( c.model, y, l==0 )
when i search by car no.
it does no show not found if there is no match found.
Your problem is in strncmp function. What do you want to do with it?
i us this for search by modal function
Explain how exactly are you using it, what is the meaning and value of each parameter. You have a serious problem with it and you need to find what is wrong.
Actually i have to prepare a project on car show room.i have to submit it in my school so please check it if any other error is their..according to u..plze.help me in this..
As I said, your comparison does not make sense. Right now it does following:
if(/*First letter of search string and car are not same*/)
Hint: you misplaced = sign (or closigng brace).
void search_carno()
{
car c;
ifstream file("car.rms",ios::binary);
int x,found=-1;
cout<<" Enter Car Number To Be Searched\n ";
cin>>x;
while(file.read((char*)&c,sizeof(c)))
{
if(c.carno==x)
{
found=1;
c.print();
}
}
file.close();
if(found==-1)
{
cout<<"No Result Found";
getch();
}
}
i have prob only in this function
Give example of "car.rms". You function should work (it is only one which should work correctly).
i cant under stand. what you are telling?
pleas solve the error in the cpp code i had given you if u can..
Last edited on
there is no error in void search_carno(), provided your file car.rms is correct and there is no bugs in whichever ancient nonstandard compiler you are using. So I want to see file you are opening to reproduce your problem.
i have delete that file.
but same prob is their.
i am using C++ compiler...
i have delete that file.
So how do you test your code? Why do you think it is not correct if you did not even run it?

i am using C++ compiler...
..which one? There are many.
Turbo C++ IDE
by re entering all data which the program stored in the file "car.rms".
by re entering all data which the program stored in the file "car.rms".
So after reebtering the data, program shoul generate new car.rms file. post it.
21 Search
11 4.Delete
5ddas fy
6.C s – j ’ÿ qFddd  ”ŠF2¤ÿ\* – q j j j ¸ÿ6j – –
T’  1 Âÿò:j T Üÿ;?T1 ôÿT ìÿ]<Tèÿ
ú   &
Err, you should post it as a file. You cannot post binary data as text
Pages: 12