issue in double linklist

what is the problm in this code,,,

gives me error at Modify function,

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
 #include<iostream>
#include<conio.h>
#include<cstdlib>
#include<windows.h>
#include<iomanip>
using namespace std;
struct node
{
	 int roll_no;
   string name;
   char grade;
 int  p_m ,c_m,m_m,cs_m,e_m;
 int num;
   float per;
   
	node* next;
	node* pre;
}*first,*last;

class linklist
{
  public:
  	
  	linklist()
  	{
  		first=NULL;
  		last=NULL;
  	}
  	
	  void insert(int Roll_no,string Name,char grade,int P_m,int C_m,int M_m,int CS_m,int E_m);
  	void Delete(int D);
  	void search(int S);
  	void Modify(string na);
  	void show();
  	


};
char calculate( int p_m ,int c_m ,int m_m ,int  e_m ,int cs_m)
{	

	int per=(p_m +c_m +m_m + e_m + cs_m)/5;
	if(per>=60)
		return 'A';
	else if(per>=50)
		return 'B';
	else if(per>=33)
		return 'C';
	else
		return 'F';
}



void linklist::insert(int Roll_no,string Name,char grade,int P_m,int C_m,int M_m,int CS_m,int E_m)
{
	node* ptr=new node;
	ptr->roll_no=Roll_no;
	ptr->name=Name;
	ptr->p_m=P_m;
	ptr->c_m=C_m;
	ptr->m_m=M_m;
	ptr->cs_m=CS_m;
	ptr->e_m=E_m;
	ptr->grade=grade;
	
	if(first==NULL)
	{
		ptr->next=NULL;
		ptr->pre=NULL;
	   first=last=ptr;
	}
	else
	{
		ptr->pre=last;
		ptr->next=NULL;
		last=ptr;
		(ptr->pre)->next=last;
	}
}
/////////////////////////////////

void linklist::Delete(int r_no)
 {
	node* ptr=first;
  while(ptr !=NULL)
	{
      if(ptr->roll_no == r_no)
      {
      	if(ptr->next == NULL && ptr->pre == NULL)
      	{
      		first=NULL;
      		last=NULL;
      	//	delete ptr;
      		free(ptr);
      		 cout<<"\nRecord Deleted ";
			  break;
      	}
      	else if(ptr->next == NULL)
      	{
      		last=ptr->pre;
      	    (ptr->pre)->next=NULL; 
		//	 delete ptr;
			free(ptr);
			 cout<<"\nRecord Deleted ";	
			break;
      	}
      	else if(ptr->pre == NULL)
      	{
      		first=ptr->next;
      		(ptr->next)->pre=NULL;
			delete ptr;
			 cout<<"\nRecord Deleted ";
		//	free(ptr);
      	    break;
		  }
      	else
      	{
      		(ptr->next)->pre=ptr->pre;
      		(ptr->pre)->next=ptr->next;
      		delete ptr;
      		 cout<<"\nRecord Deleted ";
      		//free(ptr);
      	    break;
		  }
      	
      }
    ptr=ptr->next;
 }
 

    cout<<"Rocord "<<r_no<<" not found in the list"<<endl;
}

///////////////////////////


void linklist::search(int D)
{
	node *s=first;
	while(s != NULL)
	{
		if(s->roll_no ==D)
		{
		
			cout<<"\nRoll number of student : "<<s->roll_no;
	cout<<"\nName of student : "<<s->name;
	cout<<"\nMarks in Physics : "<<s->p_m;
	cout<<"\nMarks in Chemistry : "<<s->c_m;
	cout<<"\nMarks in Maths : "<<s->m_m;
	cout<<"\nMarks in English : "<<s->e_m;
	cout<<"\nMarks in Computer Science :"<<s->cs_m;
	cout<<"\nPercentage of student is  :"<<s->per;
	cout<<"\nGrade of student is :"<<s->grade;

		}
		s=s->next;
	}
	cout<<"\n\t\t NOT FOUND \n";
}

void linklist::show()
{
	system("cls");
	 int counter=0;
	node* s=first;
	  cout<<"\n\n\t\tSTUDENT RECORD : \n"<<endl;
	while(s !=NULL)
	{
		
		counter ++;
		cout<<"====  STUDENT NUMBER  ==== "<<counter;
		cout<<"\n____________________________\n"
		 ; cout<<"\nRoll number of student : "<<s->roll_no;
	cout<<"\nName of student : "<<s->name;
	cout<<"\nMarks in Physics : "<<s->p_m;
	cout<<"\nMarks in Chemistry : "<<s->c_m;
	cout<<"\nMarks in Maths : "<<s->m_m;
	cout<<"\nMarks in English : "<<s->e_m;
	cout<<"\nMarks in Computer Science :"<<s->cs_m;
	cout<<"\nPercentage of student is  :";
	cout<<"\nGrade of student is :"<<s->grade;
	
    cout<<"\n===================================================\n";
		s=s->next;
	}
}

///////////
int main()
{ 

	int roll_no,choice;
   string name
   ;char grade;
 int  p_m ,c_m,m_m,cs_m,e_m;
 int num;
 int student;
   float per;
	
	linklist obj;
	
	cout<<"\n\n\t\t";
	system("pause");
	while(1)
	{
		system("color 72");
		system("cls");
    cout<<"======================================";
    cout<<"*******  STUDENT REPORT CARD  ********";
	cout<<"======================================";
    
	cout<<"\t[1]  #  ADD Student Recprd\n";
    cout<<"\t[2]  #  DELETE STUDENT RECORD\n";
    cout<<"\t[3]  #  Search By Roll No. \n";
    cout<<"\t[4]  #  DISPLAY All Student RECORD\n";
    cout<<"\t[5]  #  Modify Student RECORD\n";
    cout<<"\t[6]  #  Exit program \n";
cin>>choice;
switch(choice)
{
	case 1:
	{
		system("cls");
		system("color 75");
		cout<<"\n\t\t\tEnter number of student Records:";
		cin>>student;
   	 	  int s1=1;
		
			  while(s1<=student)
			  {
			  	cout<<"\nRoll number of student ";
	cin>>roll_no;
	cout<<"\n\nName of student ";
	cin>>name;
	cout<<"\nmarks in physics out of 100 : ";
	cin>>p_m;
	cout<<"\nmarks in chemistry out of 100 : ";
	cin>>c_m;
	cout<<"\nmarks in maths out of 100 : ";
	cin>>m_m;
	cout<<"\nmarks in english out of 100 : ";
	cin>>e_m;
	cout<<"\nmarks in computer science out of 100 : ";
	cin>>cs_m;
				  
			grade=calculate(p_m, m_m, e_m,c_m, cs_m);	
			obj.insert(roll_no,name,grade,p_m,c_m,m_m,e_m,cs_m);
			  	s1+=1;
	          }
		break;
	}
	case 2:
	{
			system("color 73");
		if(first==NULL)
		{
		 cout<<"\nRECORD IS EMPTY ";
			cout<<"\n\n\t\t";
		   system("pause");
			break;
	    }
		cout<<"Enter roll no.: ";
		cin>>roll_no;
		obj.Delete(roll_no);
		cout<<"\n\n\t";
		system("pause");
		break;
	}
	case 3:
	{
			system("color 74");
			if(first==NULL)
		{
			char a[100]="\nRECORD IS EMPTY ";
	//	  slow(a);
			cout<<"\n\n\t\t";
		   system("pause");
		   break;
	   }
	   cout<<"\nEnter Roll No. to Search \n";
	   cin>>roll_no;
	   obj.search(roll_no);
	    cout<<"\n\n\t\t";
		system("pause");
		break;
	}
	case 4:
	{
			system("color 7C");
			if(first==NULL)
		{
	    cout<<"RECORD IS EMPTY";
	//	slow(a);
		cout<<"\n\n\t\t";
		system("pause");
		break;
	    }
		obj.show();
		cout<<endl<<endl<<"\t\t";
		system("pause");
		break;
	}
	case 5:
	{
			system("color 7D");
			if(first==NULL)
		{
	    cout<<"RECORD IS EMPTY ";
	cout<<"\n\n\t\t";
		system("pause");
		break;
	    }
	    cout<<"\nSearch By Name ( Update Record ): ";
	    cin>>name;
	    obj.Modify(name);
	    cout<<"\n\n\t\t";
		system("pause");
		break;
	}
	case 6:
	{
		exit(1);
		break;
	}
	default:
		{
				system("color 7E");
		 cout<<"\n\t\tPlease Enter Correct NUMBER \n\n";
}	
	
 } 	
getch();
return 0;	
}
 void linklist::Modify(string name)
{
	
  int roll_num;
  char grade;
  int  phy_m ,chem_m,math_m,coms_m,eng_m;
  int num;
  node* ptr=first;
while(ptr != NULL)
{
	if(ptr->name == name)
	{
		cout<<"\n\n";
			cout<<"roll num NO = ";
			  	cin>>roll_num;
				 ptr->roll_no=roll_num;
				  cout<<"\nSTUDENT NAME = ";
			  	  cin.get();
				  getline(cin,name);
				 		 ptr->name=name;
				 	cout<<"Markx in Physics";	 
				 	cin>>phy_m;
				 	ptr->p_m=phy_m;
				 	cout<<"Markx in chemistry ";
				 	cin>>chem_m;
				 	ptr->c_m=chem_m;
					 cout<<"Markx in Maths ";
					 cin>>math_m;
					 ptr->m_m=math_m;
					 cout<<"markx in english";
					 cin>>eng_m;
					 ptr->e_m=eng_m;
					 cout<<"markx in computer science";
					 cin>>coms_m;
					 ptr->cs_m=coms_m;
				
				 		 
	       	cout<<"\n\t\tRecord is updated : \n";
		break;
		}
ptr=ptr->next;
}	
cout<<"\n\t\tRECORD NOT FOUND \n";
}
Last edited on
If you bother yourself to indent your code properly, you'll see mismatched braces.
Topic archived. No new replies allowed.