forked from HACK-IT-ROHAN/Hactoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WARDLIST(tushar).CPP
159 lines (148 loc) · 2.91 KB
/
WARDLIST(tushar).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
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
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class WARDLIST
{
char Division[20];
char Zone[20];
char Ward[20];
public:
void GetData6();
void PutData6();
};
void WARDLIST::GetData6()
{
cout<<"\n\tEnter the name of the Division of the MCD\n\t";
gets(Division);
cout<<"\n\tEnter the name of the Zone\n\t";
gets(Zone);
cout<<"\n\tEnter the name of the Ward\n\t";
gets(Ward);
}
void WARDLIST::PutData6()
{
cout<<"\n\tThe name of the division :\n\t"<<Division<<"\n\tName of the Zone :\n\t"<<Zone<<"\n\tName of the Ward :\n\t"<<Ward;
}
WARDLIST W;
void main()
{
clrscr();
void Enter_File2();
void Display_File2();
void Search2();
void Modify2();
void Delete2();
int choice;
do
{
cout<<"\n\tMain Menu\n\t";
cout<<"\n\t1.Add a record\n\t";
cout<<"\n\t2.Display the record\n\t";
cout<<"\n\t3.Search a record\n\t";
cout<<"\n\t4.Modify a record\n\t";
cout<<"\n\t5.Delete a record\n\t";
cout<<"\n\t6.Want to exit?\n\t";
cout<<"Enter your choice";
cin>>choice;
switch(choice)
{
case 1: Enter_File2();
break;
case 2: Display_File2();
break;
case 3: Search2();
break;
case 4: Modify2();
break;
case 5: Delete2();
break;
}
}while(choice!=6);
getche();
}
void Enter_File2()
{
ofstream afile("pro2.dat",ios::binary|ios::app);
W.GetData6();
afile.write((char*)& W,sizeof(W));
afile.close();
cout<<"\n\t";
getche();
}
void Display_File2()
{
ifstream bfile("pro2.dat",ios::binary);
while(bfile.read((char*)& W,sizeof(W)))
{
W.PutData6();
}
bfile.close();
cout<<"\n\t";
getche();
}
void Search2()
{
int p=-1;
char z[20];
ifstream cfile("pro2.dat",ios::binary);
cout<<"\n\tPlease enter the Ward name which is to be searched\n\t";
gets(z);
while(cfile.read((char*)& W,sizeof(W)))
{
if(strmpi(Ward,z)==0)
{
p++;
W.PutData6();
}
}
if(p==-1)
cout<<"\n\tSorry!Record not found\n\t";
cfile.close();
getche();
}
void Modify2()
{
int q=-1;
int a=0;
char t[20];
cout<<"\n\tPlease enter the Ward name which is to modified\n\t";
gets(t);
fstream dfile("pro2.dat",ios::in|ios::out|ios::binary);
while(dfile.read((char*)& W,sizeof(W)))
{
a++;
if(strmpi(Ward,t)==0)
{
W.GetData6();
dfile.seekp((a-1)*sizeof(W),ios::beg);
dfile.write((char*)& W,sizeof(W));
q++;
}
}
if(q==-1)
cout<<"Sorry Record not found";
dfile.close();
getche();
}
void Delete2()
{
char b[20];
ifstream efile("pro2.dat",ios::binary);
ofstream ffile("temp2.dat",ios::binary);
cout<<"\n\tPlease enter the Ward name to be deleted\n\t";
gets(b);
while(efile.read((char*)& W,sizeof(W)))
{
if(strmpi(Ward,b)!=0)
{
ffile.write((char*)& W,sizeof(W));
}
}
remove("pro2.dat");
rename("temp2.dat","pro2.dat");
efile.close();
ffile.close();
cout<<"\n\t";
getche();
}