-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkList.cpp
More file actions
147 lines (144 loc) · 2.92 KB
/
LinkList.cpp
File metadata and controls
147 lines (144 loc) · 2.92 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
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
#include <stdlib.h>
using namespace std;
struct student
{
string Name;
int RollNumber;
float cgpa;
student *next;
};
student *Head = NULL;
void addRecord();
void AddToList(string n, int roll, float grades);
student *Get_Last_Record(student *temp);
void Print_Record();
void Print_Single_Record(student *temp);
void Load_To_File();
void File_Handling(student *temp);
student *Search_Name(string n);
void Print_Search_Record(student *temp);
int main()
{
string name;
int i = 0;
while (i < 3)
{
addRecord();
i++;
}
Print_Record();
Load_To_File();
cout<<"\n\n Enter The Name To Search: ";
cin>>name;
Search_Name(name);
getch();
}
void addRecord()
{
string name;
int roll;
float grades;
cout << "Name: ";
cin >> name;
cout << "Roll Number: ";
cin >> roll;
cout << "Grades: ";
cin >> grades;
AddToList(name, roll, grades);
}
void AddToList(string n, int roll, float grades)
{
student *Record = new student;
Record->Name = n;
Record->RollNumber = roll;
Record->cgpa = grades;
Record->next = NULL;
if (Head == NULL)
{
Head = Record;
}
else
{
student *temp = Get_Last_Record(Head);
temp->next = Record;
}
}
student *Get_Last_Record(student *temp)
{
while (temp->next != NULL)
{
temp = temp->next;
}
return temp;
}
void Print_Record()
{
cout << "\n\n Results: \n";
student *temp = Head;
while (temp != NULL)
{
Print_Single_Record(temp);
temp = temp->next;
}
}
void Print_Single_Record(student *temp)
{
cout << "Name :";
cout << temp->Name << endl;
cout << "Roll-Number :";
cout << temp->RollNumber << endl;
cout << "CGPA :";
cout << temp->cgpa << endl;
}
void Load_To_File()
{
student *temp = Head;
while (temp != NULL)
{
File_Handling(temp);
temp = temp->next;
}
}
void File_Handling(student *temp)
{
fstream file;
file.open("data.txt", ios::app);
file << temp->Name << "," << temp->RollNumber << "," << temp->cgpa << endl;
file.close();
}
student *Search_Name(string n)
{
bool IsFound=false;
student *temp=Head;
while (temp != NULL)
{
if(temp->Name == n)
{
cout<<"Record Found.";
IsFound=true;
break;
}
temp=temp->next;
}
if (IsFound == false)
{
cout<<"Record Doesn't Found.";
}
else{
Print_Search_Record(temp);
}
}
void Print_Search_Record(student *temp)
{
cout<<"\n\n\n Search Result : ";
cout<<"\nName :";
cout<<temp->Name;
cout<<"\nRollNumber :";
cout<<temp->RollNumber;
cout<<"\nCGPA :";
cout<<temp->cgpa;
}