-
Notifications
You must be signed in to change notification settings - Fork 1
/
File_Organization.cpp
132 lines (131 loc) · 2.95 KB
/
File_Organization.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
126
127
128
129
130
131
132
/*
Title : Program in C++ to implement file organizations.
*/
#include <iostream>
#include <fstream>
using namespace std;
struct student
{
int rollno;
char name[50];
float per;
} s;
int main()
{
int ch, c, rno, flag;
ofstream outf, outf1;
outf.open("stud.txt");
ifstream inf;
do
{
cout << "\n1.ADD RECORD\n2.DISPLAY\n3.DELETE RECORD\n4.MODIFY RECORD\n";
cout << "\nEnter your choice:";
cin >> ch;
switch (ch)
{
case 1:
do
{
cout << "\n";
cout << "\nEnter the RollNo,:";
cin >> s.rollno;
cout << "\nEnter theName";
cin >> s.name;
cout << "\nEnter the Percentage:";
cin >> s.per;
outf << "\t" << s.rollno;
outf << "\t" << s.name;
outf << "\t" << s.per;
cout << "\nDo you want to continue :";
cin >> c;
} while (c == 1);
cout << "\nRecord added sucessfully:";
outf.close();
break;
case 2:
inf.open("stud.txt");
while (!inf.eof())
{
inf >> s.rollno;
inf >> s.name;
inf >> s.per;
cout << "\nRoll NO is:" << s.rollno;
cout << "\nName: is:" << s.name;
cout << "\nPercentage is:" << s.per;
}
inf.close();
break;
case 3:
outf1.open("student.txt");
inf.open("stud.txt");
cout << "\nEnter the roll no which you want to delete:";
cin >> rno;
flag = 0;
while (!inf.eof())
{
inf >> s.rollno;
inf >> s.name;
inf >> s.per;
if (rno == s.rollno)
{
flag = 1;
cout << "\nRecord deleted:";
}
else if (rno != s.rollno)
{
outf1 << "\t" << s.rollno;
outf1 << "\t" << s.name;
outf1 << "\t" << s.per;
}
}
if (flag == 0)
{
cout << "Record is not present";
}
inf.close();
outf1.close();
remove("stud.txt");
rename("student.txt", "stud.txt");
break;
case 4:
outf1.open("student.txt");
inf.open("stud.txt");
cout << "\nEnter the roll no which you want to modify:";
cin >> rno;
flag = 0;
while (!inf.eof())
{
inf >> s.rollno;
inf >> s.name;
inf >> s.per;
if (rno == s.rollno)
{
cout << "\nEnter the RollNo,Name,and Percentage:";
cin >> s.rollno >> s.name >> s.per;
outf1 << "\t" << s.rollno;
outf1 << "\t" << s.name;
outf1 << "\t" << s.per;
flag = 1;
}
else if (rno != s.rollno)
{
outf1 << "\t" << s.rollno;
outf1 << "\t" << s.name;
outf1 << "\t" << s.per;
}
}
inf.close();
outf1.close();
if (flag == 0)
{
cout << "Record is not present";
}
remove("stud.txt");
rename("student.txt", "stud.txt");
break;
}
cout << "\nwant to continue:";
cin >> c;
} while (c == 1);
return 0;
}