-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrac11-F23.cpp
125 lines (114 loc) · 2.48 KB
/
Prac11-F23.cpp
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
#include <iostream>
#include <fstream>
using namespace std;
void writef()
{
int roll;
string name, div, address;
fstream write;
cout << "Enter the roll no : ";
cin >> roll;
cout << "Enter the Name : ";
cin >> name;
cout << "Enter the div : ";
cin >> div;
cout << "Enter the address : ";
cin >> address;
// writing to file
write.open("students.txt", ios::app);
write << roll << "\n";
write << name << "\n";
write << div << "\n";
write << address << "\n";
write << "\n";
write.close();
}
void readf()
{
int roll;
string name, div, address;
fstream read;
read.open("students.txt", ios::in);
while (read >> roll >> name >> div >> address)
{
cout << endl;
cout << roll << endl;
cout << name << endl;
cout << div << endl;
cout << address << endl;
cout << endl;
}
read.close();
}
void searchf()
{
int roll, froll;
bool flag = false;
string name, div, address;
fstream read;
cout << "Enter Roll no to search" << endl;
cin >> froll;
read.open("students.txt", ios::in);
while (read >> roll >> name >> div >> address)
{
if (roll == froll)
{
flag = true;
cout << "Record Found" << endl;
}
}
if (!flag)
cout << "Record Not Found" << endl;
read.close();
}
void deletef()
{
int roll, froll;
bool flag = false;
string name, div, address;
fstream read, write;
cout << "Enter Roll no to Delete" << endl;
cin >> froll;
read.open("students.txt", ios::in);
while (read >> roll >> name >> div >> address)
{
if (roll == froll)
{
flag = true;
}
else
{
write.open("stud_updated.txt", ios::app);
write << roll << "\n";
write << name << "\n";
write << div << "\n";
write << address << "\n";
write << "\n";
write.close();
}
}
read.close();
remove("students.txt");
rename("stud_updated.txt", "students.txt");
}
int main()
{
int ch;
while (1)
{
cout << endl;
cout << "1.Write, 2.Read, 3.Delete, 4.Search" << endl;
cin >> ch;
if (ch == 1)
writef();
else if (ch == 2)
readf();
else if (ch == 3)
deletef();
else if (ch == 4)
searchf();
else
exit(0);
}
return 0;
}