-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPROJECTS(tushar).CPP
170 lines (160 loc) · 3.36 KB
/
PROJECTS(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
160
161
162
163
164
165
166
167
168
169
170
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
class PROJECTS
{
char Sector[20];
int ProjectNo;
char ProjectName[20];
int Cost;
char HeadOfOperation[20];
int Deadline;
public:
void GetData4();
void PutData4();
int getProjectNo();
};
void PROJECTS::GetData4()
{
cout<<"\n\tEnter the type of work which is to be done\n\t";
gets(Sector);
cout<<"\n\tEnter the Project Number\n\t";
cin>>ProjectNo;
cout<<"\n\tEnter the name of the Project\n\t";
gets(ProjectName);
cout<<"\n\tEnter the average cost of the Project (in Crores)\n\t";
cin>>Cost;
cout<<"\n\tEnter the name of the person in charge of this project\n\t";
gets(HeadOfOperation);
cout<<"\n\tEnter the deadline for submitting the project\n\t";
cin>>Deadline;
}
void PROJECTS::PutData4()
{
cout<<"\n\tType of Work :\n\t"<<Sector<<"\n\tProject Number :\n\t"<<ProjectNo<<"\n\tName of the project :\n\t"<<ProjectName<<"\n\tCost of making :\n\t"<<Cost<<"\n\tPerson in Charge :\n\t"<<HeadOfOperation<<"\n\tDeadline :\n\t"<<Deadline;
}
int PROJECTS::getProjectNo()
{
return(ProjectNo);
}
PROJECTS P;
void main()
{
clrscr();
void Enter_File();
void Display_File();
void Search();
void Modify();
void Delete();
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_File();
break;
case 2: Display_File();
break;
case 3: Search();
break;
case 4: Modify();
break;
case 5: Delete();
break;
}
}while(choice!=6);
getche();
}
void Enter_File()
{
ofstream afile("pro.dat",ios::binary|ios::app);
P.GetData4();
afile.write((char*)& P,sizeof(P));
afile.close();
cout<<"\n\t";
getche();
}
void Display_File()
{
ifstream bfile("pro.dat",ios::binary);
while(bfile.read((char*)& P,sizeof(P)))
{
P.PutData4();
}
bfile.close();
cout<<"\n\t";
getche();
}
void Search()
{
int p=-1;
int z;
ifstream cfile("pro.dat",ios::binary);
cout<<"\n\tPlease enter the Project number which is to be searched\n\t";
cin>>z;
while(cfile.read((char*)& P,sizeof(P)))
{
if(P.getProjectNo()==z)
{
p++;
}
}
if(p==-1)
cout<<"\n\tSorry!Record not found\n\t";
cfile.close();
getche();
}
void Modify()
{
int q=-1;
int a=0;
int t;
cout<<"\n\tPlease enter the project number which is to modified\n\t";
cin>>t;
fstream dfile("pro.dat",ios::in|ios::out|ios::binary);
while(dfile.read((char*)& P,sizeof(P)))
{
a++;
if(P.getProjectNo()==t)
{
P.GetData4();
dfile.seekp((a-1)*sizeof(P),ios::beg);
dfile.write((char*)& P,sizeof(P));
q++;
}
}
if(q==-1)
cout<<"Sorry Record not found";
dfile.close();
getche();
}
void Delete()
{
int b;
ifstream efile("pro.dat",ios::binary);
ofstream ffile("temp.dat",ios::binary);
cout<<"\n\tPlease enter the Project number to be deleted\n\t";
cin>>b;
while(efile.read((char*)& P,sizeof(P)))
{
if(P.getProjectNo()!=b)
{
ffile.write((char*)& P,sizeof(P));
}
}
remove("pro.dat");
rename("temp.dat","pro.dat");
efile.close();
ffile.close();
cout<<"\n\t";
getche();
}