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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
class employee
{
private:
int empno,age;
char sex,name[25],desig[10],addr[30],city[15];
int msal;
public:
void indata();
void outdata();
void modify();
int retempno();
};
void employee::indata()
{
cout<<"enter employee number:";
cin>>empno;
cout<<"enter employee name:";
gets(name);
cout<<"enter age:";
cin>>age;
cout<<"enter sex:";
cin>>sex;
cout<<"enter city:";
gets(city);
cout<<"enter address:";
gets(addr);
cout<<"enter designation:";
gets(desig);
cout<<"enter monthly salary:";
cin>>msal;
}
void employee::outdata()
{
cout<<"\n+------------------------------------------------------+";
cout<<"\nemployee number:"<<empno;
cout<<"\nemployee name:"<<name;
cout<<"\nage:"<<age;
cout<<"\nsex:"<<sex;
cout<<"\ncity:"<<city;
cout<<"\naddress:"<<addr;
cout<<"\ndesignation:"<<desig;
cout<<"\nmonthly salary:"<<msal;
cout<<"\n+------------------------------------------------------+";
}
int employee::retempno()
{
return empno;
}
void employee::modify()
{
cout<<"\n+------------------------------------------------------+";
cout<<"\nemployee number:"<<empno;
cout<<"\nemployee name:"<<name;
cout<<"\nage:"<<age;
cout<<"\nsex:"<<sex;
cout<<"\ncity:"<<city;
cout<<"\naddress:"<<addr;
cout<<"\ndesignation:"<<desig;
cout<<"\nmonthly salary:"<<msal;
cout<<"\n+------------------------------------------------------+";
int mempno,mage;
char msex,mname[25],mdesig[10],maddr[30],mcity[15];
int mmsal;
cout<<"\n+----------------------------------------------------+";
cout<<"\n| MODYFING MENU |";
cout<<"\n+----------------------------------------------------+";
cout<<"\nenter new employee number(enter '-1' to retain old one):";
cin>>mempno;
cout<<"enter new employee name:(enter . to retain old one):";
gets(mname);
cout<<"enter new age(enter '-1' to retain old one):";
cin>>mage;
cout<<"enter new sex(enter '.' to retain old one):";
cin>>msex;
cout<<"enter new city(enter '.' to retain old one):";
gets(mcity);
cout<<"enter new address(enter '.' to retain old one):";
gets(maddr);
cout<<"enter new designation(enter '.' to retain old one):";
gets(mdesig);
cout<<"enter new monthly salary(enter '-1' to retain old one):";
cin>>mmsal;
cout<<"\n+------------------------------------------------------+";
if(strcmp(mname,".")!=0)
strcpy(name,mname);
if(strcmp(mdesig,".")!=0)
strcpy(desig,mdesig);
if(strcmp(mcity,".")!=0)
strcpy(city,mcity);
if(strcmp(maddr,".")!=0)
strcpy(addr,maddr);
if(msex!='.')
sex=msex;
if(mempno!=-1)
empno=mempno;
if(mmsal!=-1)
mmsal=msal;
}
void showall()
{
employee sa;
ifstream fsa;
fsa.open("employee.dat");
while(!fsa.eof())
{
fsa.read((char*)&sa,sizeof(sa));
sa.outdata();
cout<<"\n";
getch();
}
getch();
fsa.close();
}
void credits()
{
cout<<"\nunder construction :P";
getch();
}
void add()
{
ofstream fa; employee ea;
fa.open("employee.dat",ios::app);
char ch;
do{
ea.indata();
fa.write((char*)&ea,sizeof(ea));
cout<<"do you want to add more records(y/n):";
cin>>ch;
}while(ch=='y'||ch=='Y'); fa.close();
}
void searchr()
{
int flags=0;
employee es;
int empnoms;
cout<<"enter employee no to search for:";
cin>>empnoms;
ifstream fs;
fs.open("employee.dat");
while(!fs.eof())
{
fs.read((char*)&es,sizeof(es));
if(es.retempno()==empnoms)
{
flags=1;
cout<<"record found";
es.outdata();
getch();
break;
}
}
if(flags==0)
cout<<"specified record not found"; getch(); fs.close();
}
void deleter()
{
ifstream fd;
ofstream ft;
fd.open("employee.dat");
ft.open("temperory.dat");
int flagd=0;
char conf='y';
employee ed;
cout<<"enter employee number to delete:";
int enodel; cin>>enodel;
while(!fd.eof())
{
fd.read((char*)&ed,sizeof(ed));
if(ed.retempno()==enodel)
{
flagd=1;
cout<<"\nRecord preparing for delete";
ed.outdata();
cout<<"\ndo you want do delete this record(y/n):";
cin>>conf;
if(conf=='n')
ft.write((char*)&ed,sizeof(ed));
}
else
ft.write((char*)&ed,sizeof(ed));
}
if(flagd==0)
cout<<"specified employee not found ";
remove("employee.dat");
rename("temperory.dat","employee.dat");
cout<<"process complete";
fd.close();
ft.close();
}
void main()
{
label:
employee e;
clrscr();
int ch, flag=0;
long pos;
cout<<"+----------------------------------------------------+";
cout<<"\n| MENU |";
cout<<"\n+----------------------------------------------------+";
cout<<"\n1.Add record\n2.Delete a record\n3.Search for a record\n4.Modify a record\n5.Show all records\n6.Credits\n7.exit\nEnter your choice[1-7]";
cin>>ch;
if(ch==1)
{
add();
goto label;
}
else if(ch==2)
{
deleter();
getch();
goto label;
}
else if(ch==3)
{
searchr();
goto label;
}
else if(ch==4)
{
cout<<"enter employee no to modify:";
int empnom; cin>>empnom;
fstream f;
f.open("employee.dat",ios::in|ios::app);
while(!f.eof())
{
f.read((char*)&e,sizeof(e));
if(e.retempno()==empnom)
{
flag=1;
cout<<"\nrecord found";
e.modify();
pos=f.tellg();
f.seekg(pos-(sizeof(e)));
f.write((char*)&e,sizeof(e));
getch();
}
}
if(flag==0)
cout<<"record not found"; getch();
goto label;
f.close();
}
else if(ch==5)
{
showall();
goto label;
}
else if(ch==6)
{
credits();
goto label;
}
else if(ch==7)
exit(0);
else
{
cout<<"\nwrong choice";
goto label;
}
getch();
}
|