You are on page 1of 20

1

2 #include <iostream>
3 #include <string>
4 #include <fstream>
5
6 using namespace std;
7
8 struct Node
9 {
10 Node* nextptr;
11 Node* prevptr;
12 string student_name;
13 string father_name;
14 int registration;
15 string section;
16 string major;
17 string area;
18 float gpa;
19 };
20
21 class LAB_PROJECT
22 { private:
23 Node* startptr;
24 Node* lastptr;
25
26
27 public:
28 LAB_PROJECT();
29 ~LAB_PROJECT();
30 void add_node();
31 void display_nodes();
32 Node* return_pointer(int index);
33 Node* pointer_by_registration(int reg_key);
34 Node* pointer_by_name(string getin);
35 void edit_student();
36 void edit_father();
37 void edit_registration();
38 void edit_section();
39 void edit_major();
40 void edit_area();
41 int return_size();
42 void edit_info();
43 void get_info();
44 void edit_gpa();
45 void remove_selected();
46 void delete_all_nodes();
47 void print_selected();
48 void print_to_file();
49 };
50
51
52
53 LAB_PROJECT::LAB_PROJECT()
54 {
55 //ctor
56
57
58 startptr=lastptr=NULL;
59 }
60 LAB_PROJECT::~LAB_PROJECT()
61 {
62
63 }
64
65 void LAB_PROJECT::add_node()
66 {
67 Node*temp1ptr;
68 temp1ptr = new Node;
69 string s_name;
70 string f_name;
71 int reg;
72 string sect;
73 string maj;
74 string area_int;
75 float new_gpa;
76 int confirmation = 0;
77
78
79
80 // string the tedious process of repetition
81 cin.ignore(1,'\n');
82 cout << "\n \n Please Enter STudents Name: ";
83 getline(cin,s_name,'\n');
84 temp1ptr->student_name = s_name;
85
86
87 cout << "\n \nAre you sure, 1 = Yes, 2 = No >> ";
88 cin >> confirmation;
89 cin.ignore(1,'\n');
90
91 if(confirmation==2)
92 {
93
94
95 do
96 {
97 cout <<"\n \n Please Re-Enter >> ";
98 getline(cin,s_name,'\n');
99 cout << "\n \n Are you sure, 1 = Yes, 2 = No >> ";
100 cin >> confirmation;
101 cin.ignore(1,'\n');
102 }while(confirmation!=1);
103 temp1ptr->student_name = s_name;
104 confirmation = 0;
105 }
106
107
108
109
110
111 // for fathers name now
112 cout << "\n \n Please Enter Father's Name: ";
113 getline(cin,f_name,'\n');
114 temp1ptr->father_name = f_name;
115
116 cout << "\n \n Are you sure, 1 = Yes, 2 = No >> ";
117 cin >> confirmation;
118 cin.ignore(1,'\n');
119
120 if(confirmation==2)
121 {
122
123
124 do
125 {
126 cout <<"\n \n Please Re-Enter >> ";
127 getline(cin,f_name,'\n');
128 cout << "\n \n Are you sure, 1 = Yes, 2 = No >> ";
129 cin >> confirmation;
130 cin.ignore(1,'\n');
131 }while(confirmation!=1);
132 temp1ptr->father_name = f_name;
133 confirmation = 0;
134
135 }
136
137
138
139
140
141 // for Registration no. now
142 cout << "\n \n Please Enter Registration No: ";
143 cin >> reg;
144 temp1ptr->registration = reg;
145 cin.ignore(1,'\n');
146
147 cout << "\n \n Are you sure, 1 = Yes, 2 = No >> ";
148 cin >> confirmation;
149 cin.ignore(1,'\n');
150
151
152 if(confirmation==2)
153 {
154
155
156 do
157 {
158 cout <<"\n \n Please Re-Enter >> ";
159 cin>>reg;
160 cout << "\n \n Are you sure, 1 = Yes, 2 = No >> ";
161 cin >> confirmation;
162 cin.ignore(1,'\n');
163 }while(confirmation!=1);
164 temp1ptr->registration = reg;
165 confirmation = 0;
166
167 }
168
169
170
171
172
173
174
175
176 cout << "\n \n Please Enter Section: ";
177 getline(cin,sect,'\n');
178 temp1ptr->section = sect;
179
180 cout << "\n \n Are you sure, 1 = Yes, 2 = No >> ";
181 cin >> confirmation;
182 cin.ignore(1,'\n');
183
184
185
186 if(confirmation==2)
187 {
188
189
190 do
191 {
192 cout <<"\n \n Please Re-Enter >> ";
193 getline(cin,sect,'\n');
194 cout << "\n \n Are you sure, 1 = Yes, 2 = No >> ";
195 cin >> confirmation;
196 cin.ignore(1,'\n');
197 }while(confirmation!=1);
198 temp1ptr->section = sect;
199 confirmation = 0;
200
201 }
202
203
204
205 cout << "\n \n Please Enter Major Area of Interest: ";
206 getline(cin,maj,'\n');
207 temp1ptr->major = maj;
208
209 cout << "\n \n Are you sure, 1 = Yes, 2 = No >> ";
210 cin >> confirmation;
211 cin.ignore(1,'\n');
212
213
214
215 if(confirmation==2)
216 {
217
218
219 do
220 {
221 cout <<"\n \n Please Re-Enter >> ";
222 getline(cin,maj,'\n');
223 cout << "\n \n Are you sure, 1 = Yes, 2 = No >> ";
224 cin >> confirmation;
225 cin.ignore(1,'\n');
226 }while(confirmation!=1);
227 temp1ptr->major = maj;
228 confirmation = 0;
229
230 }
231
232
233
234
235
236 cout << "\n \n Please Enter Current Area: ";
237 getline(cin,area_int,'\n');
238 temp1ptr->area = area_int;
239
240 cout << "\n \n Are you sure, 1 = Yes, 2 = No >> ";
241 cin >> confirmation;
242 cin.ignore(1,'\n');
243
244
245
246
247 if(confirmation==2)
248 {
249
250
251 do
252 {
253 cout <<"\n \n Please Re-Enter >> ";
254 getline(cin,area_int,'\n');
255 cout << "\n \n Are you sure, 1 = Yes, 2 = No >> ";
256 cin >> confirmation;
257 cin.ignore(1,'\n');
258 }while(confirmation!=1);
259 temp1ptr->area = area_int;
260 confirmation = 0;
261
262 }
263
264
265
266
267
268 cout << "\n \n Please Enter The GPA : ";
269 cin >> new_gpa;
270 temp1ptr->gpa = new_gpa;
271 cin.ignore(1,'\n');
272
273 cout << "\n \n Are you sure, 1 = Yes, 2 = No >> ";
274 cin >> confirmation;
275 cin.ignore(1,'\n');
276
277
278 if(confirmation==2)
279 {
280
281
282 do
283 {
284 cout <<"\n \n Please Re-Enter >> ";
285 cin>>new_gpa;
286 cout << "\n \n Are you sure, 1 = Yes, 2 = No >> ";
287 cin >> confirmation;
288 cin.ignore(1,'\n');
289 }while(confirmation!=1);
290 temp1ptr->gpa = new_gpa;
291 confirmation = 0;
292
293 }
294
295
296 cout << endl;
297 cout << endl;
298 cout << endl;
299
300
301
302 // 4 cases
303
304 // 1- list is empty , simply add
305
306 if (startptr==NULL)
307 {
308 startptr=temp1ptr;
309 lastptr=startptr;
310 lastptr->nextptr=NULL;
311 lastptr->prevptr=NULL;
312 }
313 // 2- Before the 1st node
314 else if (reg<startptr->registration)
315 {
316 temp1ptr->nextptr=startptr;
317 startptr->prevptr=temp1ptr;
318 startptr=temp1ptr;
319 startptr->prevptr=NULL;
320 }
321 // 3- greater than the last one
322 else if (reg > lastptr->registration)
323 {
324 lastptr->nextptr = temp1ptr;
325 temp1ptr->prevptr=lastptr;
326 lastptr=temp1ptr;
327 lastptr->nextptr = NULL;
328 }
329 // 4 - somewhere in the middle
330 else
331 {
332 Node*current;
333 Node*hold3ptr;
334 current = startptr;
335
336 while (current!=NULL)
337 {
338 if (reg < current->nextptr->registration)
339 {
340 hold3ptr = current->nextptr;
341 current->nextptr=temp1ptr;
342 hold3ptr->prevptr = temp1ptr;
343 temp1ptr->nextptr = hold3ptr;
344 hold3ptr->prevptr = current;
345 return; //
346 }
347 current=current->nextptr;
348 }
349 }
350 }
351
352
353 // writinf fucntion to diplay all the nodes
354
355
356 void LAB_PROJECT::display_nodes()
357 {
358 Node*temptr;
359 temptr = startptr;
360
361 do
362 { cout << " -- Student Name: ";
363 cout << temptr->student_name << " "<<endl;
364 cout << " -- Fahter Name: ";
365 cout << temptr->father_name << " "<<endl;
366 cout << " -- Registration No: ";
367 cout << temptr->registration << " "<<endl;
368 cout << " -- Section : ";
369 cout << temptr->section << " "<<endl;
370 cout << " -- Major Area : ";
371 cout << temptr->major << " "<<endl;
372 cout << " -- Current Area: ";
373 cout << temptr->area << " "<<endl;
374 cout << " -- Student GPA: ";
375 cout << temptr->gpa << " "<<endl;
376 cout << endl;
377 cout << endl;
378
379 // now incrementing the pointer to next one
380 temptr=temptr->nextptr;
381
382 }while(temptr!=NULL);
383 }
384
385 // adding delete the ndoes function now
386
387 void LAB_PROJECT::delete_all_nodes()
388 {
389 Node*temp1;
390 Node*temp2;
391
392 temp1=startptr;
393 temp2=temp1;
394
395 while (temp1!=NULL)
396 {
397 temp1 = temp1->nextptr;
398 delete (temp2);
399 temp2 = temp1;
400 }
401
402 delete (temp1);
403 }
404 // adding size of list function now
405
406 // reutnr size of the list
407 int LAB_PROJECT::return_size(){
408 Node* temp;
409 temp = startptr;
410 int count = 0;
411 if (startptr==NULL)
412 {
413 return (count);
414 }
415 else if(temp->nextptr==NULL)
416 {
417 count++;
418 return(count);
419 }
420 else
421 {
422 while(temp->nextptr!=NULL)
423 {
424 count++;
425 temp=temp->nextptr;
426 }
427 return(count+1);
428 }
429 }
430
431 Node* LAB_PROJECT::return_pointer(int index){
432 if(index == 0) // user trying to trick me, he he i am smart too
433 {
434 return(0);
435 }
436 else if(index == 1) // 1st node pointer requested
437 {
438 return(startptr);
439 }
440 else{
441 Node* temp;
442 temp = startptr;
443 for(int i=1; (i<index); i++)
444 {
445 temp=temp->nextptr;
446 }
447 return(temp);}
448 }
449 // reutnr size
450
451 // writing fucntio write to file
452
453 void LAB_PROJECT::print_to_file()
454 {
455 Node*temptr;
456 temptr = startptr;
457
458
459 ofstream outfile("student's_data.txt");
460
461 while(temptr!=NULL)
462 {
463 outfile << " -- Student Name: ";
464 outfile << temptr->student_name << " "<<endl;
465 outfile << " -- Fahter Name: ";
466 outfile << temptr->father_name << " "<<endl;
467 outfile << " -- Registration No: ";
468 outfile << temptr->registration << " "<<endl;
469 outfile << " -- Section : ";
470 outfile << temptr->section << " "<<endl;
471 outfile << " -- Major Area : ";
472 outfile << temptr->major << " "<<endl;
473 outfile << " -- Current Area: ";
474 outfile << temptr->area << " "<<endl;
475 outfile << " -- Student GPA: ";
476 outfile << temptr->gpa << " "<<endl;
477 outfile << endl;
478 outfile << endl;
479
480 temptr=temptr->nextptr;
481 }
482
483 cout << "\n \n Written Successfully Where Your Programe is Running!";
484 }
485
486 // get_info function
487
488 void LAB_PROJECT::get_info()
489 {
490 int key = 0;
491
492 cout << " \n \n Please Enter the Registration No. of the Student :";
493 cin >> key;
494
495 Node*temptr;
496 temptr = startptr;
497
498 while (temptr!= NULL)
499 {
500 if(key == temptr->registration)
501 {
502 cout << " -- Student Name: ";
503 cout << temptr->student_name << " "<<endl;
504 cout << " -- Fahter Name: ";
505 cout << temptr->father_name << " "<<endl;
506 cout << " -- Registration No: ";
507 cout << temptr->registration << " "<<endl;
508 cout << " -- Section : ";
509 cout << temptr->section << " "<<endl;
510 cout << " -- Major Area : ";
511 cout << temptr->major << " "<<endl;
512 cout << " -- Current Area: ";
513 cout << temptr->area << " "<<endl;
514 cout << " -- Student GPA: ";
515 cout << temptr->gpa << " "<<endl;
516 cout << endl;
517 cout << endl;
518 return;
519 }
520
521 temptr=temptr->nextptr;
522 }
523
524
525 }
526
527
528 // writing function pointer by registration
529
530 Node* LAB_PROJECT::pointer_by_registration(int reg_key)
531 {
532 int key = 0;
533 key = reg_key;
534
535 Node* temp1;
536 temp1 = startptr;
537
538 while(temp1 !=NULL)
539 {
540 if(key == temp1->registration)
541 {
542 return(temp1);
543 }
544 temp1=temp1->nextptr;
545 }
546 return(NULL);
547 }
548
549 // pointer by registration
550
551 Node* LAB_PROJECT::pointer_by_name(string getin)
552 {
553 string checker;
554 checker = getin;
555
556 Node*temp1;
557 temp1 = startptr;
558
559 while(temp1 != NULL)
560 {
561 if (checker == temp1->student_name)
562 {
563 return (temp1);
564 }
565 temp1=temp1->nextptr;
566 }
567 return(NULL);
568 }
569
570 void LAB_PROJECT::edit_student()
571 {
572 int response = 0;
573 string search_name;
574 int search_reg = 0;
575
576 cout << "\n \n -- Select Search Option 1 or 2 Accordingly" << endl;
577 cout << "\n 1--Registration ";
578 cout << "\n 2--Student's Name" << " >> " ;
579 cin >> response;
580 cin.ignore(1,'\n');
581
582 if (response==1)
583 {
584 cout << "\n \n Enter Registration No: ";
585 cin >> search_reg;
586
587 Node*temp1;
588
589 temp1 = pointer_by_registration(search_reg);
590
591 cin.ignore(1,'\n');
592 string new_name;
593
594 cout << "\n \n Enter New Name ";
595 getline(cin,new_name,'\n');
596 temp1->student_name = new_name;
597 return;
598
599 }
600 else if(response==2)
601 {
602 cout << "\n \n Enter Student's Name , that you want to search " << endl
;
603 getline(cin,search_name,'\n');
604
605 Node*temp2;
606
607 temp2 = pointer_by_name(search_name);
608 string new_name;
609
610 cout << "\n \n Enter New Name";
611 getline(cin,new_name,'\n');
612
613 temp2->student_name=new_name;
614 return;
615 }
616 }
617
618 void LAB_PROJECT::edit_father()
619 {
620 int response = 0;
621 string search_name;
622 int search_reg = 0;
623
624 cout << "\n \n -- Select Search Option 1 or 2 Accordingly" << endl;
625 cout << "\n 1--Registration ";
626 cout << "\n 2--Student's Name" << " >> " ;
627 cin >> response;
628
629 if (response==1)
630 {
631 cout << "\n \n Enter Registration No: ";
632 cin >> search_reg;
633
634 Node*temp1;
635
636 temp1 = pointer_by_registration(search_reg);
637
638 cin.ignore(1,'\n');
639 string new_name;
640
641 cout << "\n \n Enter New Name ";
642 getline(cin,new_name,'\n');
643 temp1->father_name = new_name;
644 return;
645
646 }
647 else if(response==2)
648 {
649 cout << "\n \n Enter Student's Name , that you want to search " << endl
;
650 getline(cin,search_name,'\n');
651 cin.ignore(1,'\n');
652 Node*temp2;
653
654 temp2 = pointer_by_name(search_name);
655 string new_name;
656
657 cout << "\n \n Enter New Name";
658 getline(cin,new_name,'\n');
659 cin.ignore(1,'\n');
660 temp2->father_name=new_name;
661 return;
662 }
663 }
664
665 void LAB_PROJECT::edit_registration()
666 {
667 int response = 0;
668 string search_name;
669 int search_reg = 0;
670
671 cout << "\n \n -- Select Search Option 1 or 2 Accordingly" << endl;
672 cout << "\n 1--Registration ";
673 cout << "\n 2--Student's Name" << " >> " ;
674 cin >> response;
675
676 if (response==1)
677 {
678 cout << "\n \n Enter Registration No: ";
679 cin >> search_reg;
680
681 Node*temp1;
682
683 temp1 = pointer_by_registration(search_reg);
684
685 cin.ignore(1,'\n');
686 int new_reg_new = 0;
687
688 cout << "\n \n Enter New Registration No: ";
689 cin >> new_reg_new;
690 temp1->registration = new_reg_new;
691 return;
692
693 }
694 else if(response==2)
695 {
696 cout << "\n \n Enter Student's Name , that you want to search " << endl
;
697 getline(cin,search_name,'\n');
698 cin.ignore(1,'\n');
699 Node*temp2;
700
701 temp2 = pointer_by_name(search_name);
702 int new_reg_new = 0;
703
704 cout << "\n \n Enter New Registration No: ";
705 cin >> new_reg_new;
706 temp2->registration = new_reg_new;
707 return;
708 }
709 }
710
711 void LAB_PROJECT::edit_section()
712 {
713 int response = 0;
714 string search_name;
715 int search_reg = 0;
716
717 cout << "\n \n -- Select Search Option 1 or 2 Accordingly" << endl;
718 cout << "\n 1--Registration ";
719 cout << "\n 2--Student's Name" << " >> " ;
720 cin >> response;
721
722 if (response==1)
723 {
724 cout << "\n \n Enter Registration No: ";
725 cin >> search_reg;
726
727 Node*temp1;
728
729 temp1 = pointer_by_registration(search_reg);
730
731 cin.ignore(1,'\n');
732 string new_name;
733
734 cout << "\n \n Enter New Section ";
735 getline(cin,new_name,'\n');
736 temp1->section= new_name;
737 return;
738
739 }
740 else if(response==2)
741 {
742 cout << "\n \n Enter Student's Name , that you want to search " << endl
;
743 getline(cin,search_name,'\n');
744 cin.ignore(1,'\n');
745 Node*temp2;
746
747 temp2 = pointer_by_name(search_name);
748 string new_name;
749
750 cout << "\n \n Enter New Section";
751 getline(cin,new_name,'\n');
752 cin.ignore(1,'\n');
753 temp2->section=new_name;
754 return;
755 }
756 }
757
758 void LAB_PROJECT::edit_major()
759 {
760 int response = 0;
761 string search_name;
762 int search_reg = 0;
763
764 cout << "\n \n -- Select Search Option 1 or 2 Accordingly" << endl;
765 cout << "\n 1--Registration ";
766 cout << "\n 2--Student's Name" << " >> " ;
767 cin >> response;
768
769 if (response==1)
770 {
771 cout << "\n \n Enter Registration No: ";
772 cin >> search_reg;
773
774 Node*temp1;
775
776 temp1 = pointer_by_registration(search_reg);
777
778 cin.ignore(1,'\n');
779 string new_name;
780
781 cout << "\n \n Enter New Major Area of Interest: ";
782 getline(cin,new_name,'\n');
783 temp1->major = new_name;
784 return;
785
786 }
787 else if(response==2)
788 {
789 cout << "\n \n Enter Student's Name , that you want to search " << endl
;
790 getline(cin,search_name,'\n');
791 cin.ignore(1,'\n');
792 Node*temp2;
793
794 temp2 = pointer_by_name(search_name);
795 string new_name;
796
797 cout << "\n \n Enter New Major Area of Interest: ";
798 getline(cin,new_name,'\n');
799 cin.ignore(1,'\n');
800 temp2->major=new_name;
801 return;
802 }
803 }
804
805 void LAB_PROJECT::edit_area()
806 {
807 int response = 0;
808 string search_name;
809 int search_reg = 0;
810
811 cout << "\n \n -- Select Search Option 1 or 2 Accordingly" << endl;
812 cout << "\n 1--Registration ";
813 cout << "\n 2--Student's Name" << " >> " ;
814 cin >> response;
815
816 if (response==1)
817 {
818 cout << "\n \n Enter Registration No: ";
819 cin >> search_reg;
820
821 Node*temp1;
822
823 temp1 = pointer_by_registration(search_reg);
824
825 cin.ignore(1,'\n');
826 string new_name;
827
828 cout << "\n \n Enter New Area: ";
829 getline(cin,new_name,'\n');
830 temp1->area = new_name;
831 return;
832
833 }
834 else if(response==2)
835 {
836 cout << "\n \n Enter Student's Name , that you want to search " << endl
;
837 getline(cin,search_name,'\n');
838 cin.ignore(1,'\n');
839 Node*temp2;
840
841 temp2 = pointer_by_name(search_name);
842 string new_name;
843
844 cout << "\n \n Enter New Area: ";
845 getline(cin,new_name,'\n');
846 cin.ignore(1,'\n');
847 temp2->area=new_name;
848 return;
849 }
850 }
851
852 void LAB_PROJECT::edit_gpa()
853 {
854 int response = 0;
855 string search_name;
856 int search_reg = 0;
857
858 cout << "\n \n -- Select Search Option 1 or 2 Accordingly" << endl;
859 cout << "\n 1--Registration ";
860 cout << "\n 2--Student's Name" << " >> " ;
861 cin >> response;
862
863 if (response==1)
864 {
865 cout << "\n \n Enter Registration No: ";
866 cin >> search_reg;
867
868 Node*temp1;
869
870 temp1 = pointer_by_registration(search_reg);
871
872 cin.ignore(1,'\n');
873 int new_reg_new = 0;
874
875 cout << "\n \n Enter New GPA: ";
876 cin >> new_reg_new;
877 temp1->gpa = new_reg_new;
878 return;
879
880 }
881 else if(response==2)
882 {
883 cout << "\n \n Enter Student's Name , that you want to search " << endl
;
884 getline(cin,search_name,'\n');
885 cin.ignore(1,'\n');
886 Node*temp2;
887
888 temp2 = pointer_by_name(search_name);
889 int new_reg_new = 0;
890
891 cout << "\n \n Enter New GPA: ";
892 cin >> new_reg_new;
893 temp2->gpa = new_reg_new;
894 return;
895 }
896 }
897
898 void LAB_PROJECT::remove_selected()
899 {
900 int response = 0;
901 string search_name;
902 int search_reg = 0;
903
904 cout << "\n \n -- Select Search Option 1 or 2 Accordingly" << endl;
905 cout << "\n 1--Registration ";
906 cout << "\n 2--Student's Name" << " >> " ;
907 cin >> response;
908 cin.ignore(1,'\n');
909
910 if(response==1)
911 {
912 cout << "\n \n Enter Registration No: ";
913 cin >> search_reg;
914
915 Node*temp1;
916
917 temp1 = pointer_by_registration(search_reg);
918 cin.ignore(1,'\n');
919
920 if(temp1==startptr)//means start ptr
921 {
922 startptr=startptr->nextptr;
923 startptr->prevptr=NULL;
924 delete(temp1);
925 return;
926 }
927 else if(temp1==lastptr) // means last ptr to be deleted
928 {
929 lastptr=lastptr->prevptr;
930 lastptr->nextptr=NULL;
931 delete(temp1);
932 return;
933 }
934 else
935 {
936 Node*temp2;
937 Node*temp3;
938
939 temp2=temp1->prevptr;
940 temp3=temp1->nextptr;
941 temp2->nextptr=temp3;
942 temp3->prevptr=temp2;
943 delete(temp1);
944 return;
945 }
946
947
948 }
949 else if (response==2)
950 {
951 cout << "\n \n Enter Student's Name , that you want to search " << endl
;
952 getline(cin,search_name,'\n');
953 cin.ignore(1,'\n');
954 Node*temp1;
955
956 temp1 = pointer_by_name(search_name);
957
958 if(temp1==startptr)//means start ptr
959 {
960 startptr=startptr->nextptr;
961 startptr->prevptr=NULL;
962 delete(temp1);
963 return;
964 }
965 else if(temp1==lastptr) // means last ptr to be deleted
966 {
967 lastptr=lastptr->prevptr;
968 lastptr->nextptr=NULL;
969 delete(temp1);
970 return;
971 }
972 else
973 {
974 Node*temp2;
975 Node*temp3;
976
977 temp2=temp1->prevptr;
978 temp3=temp1->nextptr;
979 temp2->nextptr=temp3;
980 temp3->prevptr=temp2;
981 delete(temp1);
982 return;
983 }
984 }
985
986
987 }
988
989 void LAB_PROJECT::print_selected()
990 {
991 int response = 0;
992 string search_name;
993 int search_reg = 0;
994
995 cout << "\n \n -- Select Search Option 1 or 2 Accordingly" << endl;
996 cout << "\n 1--Registration ";
997 cout << "\n 2--Student's Name" << " >> " ;
998 cout << "\n 3--Print All" << " >> " ;
999 cin >> response;
1000 cin.ignore(1,'\n');
1001
1002 if(response == 1)
1003 {
1004 cout << "\n \n Enter Registration No: ";
1005 cin >> search_reg;
1006
1007 Node*temptr;
1008
1009 temptr = pointer_by_registration(search_reg);
1010 cin.ignore(1,'\n');
1011
1012 ofstream outfile("student's_data.txt");
1013
1014 outfile << " -- Student Name: ";
1015 outfile << temptr->student_name << " "<<endl;
1016 outfile << " -- Fahter Name: ";
1017 outfile << temptr->father_name << " "<<endl;
1018 outfile << " -- Registration No: ";
1019 outfile << temptr->registration << " "<<endl;
1020 outfile << " -- Section : ";
1021 outfile << temptr->section << " "<<endl;
1022 outfile << " -- Major Area : ";
1023 outfile << temptr->major << " "<<endl;
1024 outfile << " -- Current Area: ";
1025 outfile << temptr->area << " "<<endl;
1026 outfile << " -- Student GPA: ";
1027 outfile << temptr->gpa << " "<<endl;
1028 outfile << endl;
1029 outfile << endl;
1030
1031 cout << "\n \n Written Successfully Where Your Programe is Running!";
1032
1033 }
1034 else if(response==2)
1035 {
1036 cout << "\n \n Enter Student's Name , that you want to search " << endl
;
1037 getline(cin,search_name,'\n');
1038 cin.ignore(1,'\n');
1039 Node*temptr;
1040
1041 temptr = pointer_by_name(search_name);
1042 ofstream outfile("student's_data.txt");
1043
1044 while(temptr!=NULL)
1045 {
1046 outfile << " -- Student Name: ";
1047 outfile << temptr->student_name << " "<<endl;
1048 outfile << " -- Fahter Name: ";
1049 outfile << temptr->father_name << " "<<endl;
1050 outfile << " -- Registration No: ";
1051 outfile << temptr->registration << " "<<endl;
1052 outfile << " -- Section : ";
1053 outfile << temptr->section << " "<<endl;
1054 outfile << " -- Major Area : ";
1055 outfile << temptr->major << " "<<endl;
1056 outfile << " -- Current Area: ";
1057 outfile << temptr->area << " "<<endl;
1058 outfile << " -- Student GPA: ";
1059 outfile << temptr->gpa << " "<<endl;
1060 outfile << endl;
1061 outfile << endl;
1062
1063 temptr=temptr->nextptr;
1064 }
1065
1066 cout << "\n \n Written Successfully Where Your Programe is Running!";
1067 }
1068 else if (response==3)
1069 {
1070 Node*temptr;
1071 temptr = startptr;
1072
1073
1074 ofstream outfile("student's_data.txt");
1075
1076 while(temptr!=NULL)
1077 {
1078 outfile << " -- Student Name: ";
1079 outfile << temptr->student_name << " "<<endl;
1080 outfile << " -- Fahter Name: ";
1081 outfile << temptr->father_name << " "<<endl;
1082 outfile << " -- Registration No: ";
1083 outfile << temptr->registration << " "<<endl;
1084 outfile << " -- Section : ";
1085 outfile << temptr->section << " "<<endl;
1086 outfile << " -- Major Area : ";
1087 outfile << temptr->major << " "<<endl;
1088 outfile << " -- Current Area: ";
1089 outfile << temptr->area << " "<<endl;
1090 outfile << " -- Student GPA: ";
1091 outfile << temptr->gpa << " "<<endl;
1092 outfile << endl;
1093 outfile << endl;
1094
1095 temptr=temptr->nextptr;
1096 }
1097
1098 cout << "\n \n Written Successfully Where Your Programe is Running!";
1099 }
1100
1101
1102
1103
1104
1105 }
1106
1107 int main()
1108 {
1109 LAB_PROJECT obj;
1110 int your_response = 0;
1111 while(1)
1112 {
1113 cout << endl;
1114 cout << endl;
1115 cout << endl;
1116 cout << "Please choose one of the following options: ";
1117 cout << endl;
1118 cout << endl;
1119 cout << endl;
1120 cout << " 1 -- Add a new student's info ";
1121 cout << endl;
1122 cout << " 2 -- Edit a student's info ";
1123 cout << endl;
1124 cout << " 3 -- Get a student's info ";
1125 cout << endl;
1126 cout << " 4 -- Print info to a text file ";
1127 cout << endl;
1128 cout << " 5 - Exit Program ";
1129 cout << endl;
1130 cout << ">> ";
1131
1132 cin >> your_response;
1133
1134 switch (your_response)
1135 {
1136 case(1):
1137 {
1138 obj.add_node();
1139 break;
1140 }
1141 case(2):
1142 {
1143 int new_case = 0;
1144
1145 cout << endl;
1146 cout << endl;
1147 cout << endl;
1148 cout << "Please choose one of the following options: ";
1149 cout << endl;
1150 cout << endl;
1151 cout << endl;
1152 cout << " -- 1 - Student Name ";
1153 cout << endl;
1154 cout << " -- 2 - Father Name ";
1155 cout << endl;
1156 cout << " -- 3 - Registration Number ";
1157 cout << endl;
1158 cout << " -- 4 - Section ";
1159 cout << endl;
1160 cout << " -- 5 - Major Area of Interest ";
1161 cout << endl;
1162 cout << " -- 6 - Current CGPA ";
1163 cout << endl;
1164 cout << " -- 7 - Remove a Student's Entry ";
1165 cout << endl;
1166 cout << " -- 8 - Remove all Data ";
1167 cout << endl;
1168 cout << ">> ";
1169 cin >> new_case;
1170
1171 switch(new_case)
1172 {
1173 case(1):
1174 {
1175 obj.edit_student();
1176 break;
1177 }
1178 case(2):
1179 {
1180 obj.edit_father();
1181 break;
1182 }
1183 case(3):
1184 {
1185 obj.edit_registration();
1186 break;
1187 }
1188 case(4):
1189 {
1190 obj.edit_section();
1191 break;
1192 }
1193 case(5):
1194 {
1195 obj.edit_area();
1196 break;
1197 }
1198 case(6):
1199 {
1200 obj.edit_gpa();
1201 break;
1202 }
1203 case(7):
1204 {
1205 obj.remove_selected();
1206 break;
1207 }
1208 case(8):
1209 {
1210 obj.delete_all_nodes();
1211 break;
1212 }
1213 }
1214
1215
1216 break;
1217 }
1218 case(3):
1219 {
1220 int reaction = 0;
1221 cout <<" \n \n 1-- Get a Particular Student Info "<<endl;
1222 cout <<" \n \n 2-- Get All Student's Info "<<endl;
1223 cout << ">> ";
1224 cin >> reaction ;
1225 cin.ignore(1,'\n');
1226 if (reaction==1)
1227 {
1228 obj.get_info();
1229 }
1230 else if (reaction==2)
1231 {
1232 obj.display_nodes();
1233 }
1234 break;
1235 }
1236 case(4):
1237 {
1238 obj.print_selected();
1239 break;
1240 }
1241 case(5):
1242 {
1243 obj.delete_all_nodes();
1244 return 0;
1245 break;
1246 }
1247 }
1248
1249 }
1250
1251
1252
1253 return 0;
1254 }

You might also like