Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

//functions on files

#include<iostream.h> #include<conio.h> #include<fstream.h> #include<stdio.h> #include<stdlib.h> class student { intstudentid; char name[20]; charfname[20]; public: voidgetdata ! { cout<<"#n$nter %he admission no.:#t "; cin>>studentid; cout<<"#n#n$nter %he &ame of %he 'tudent:#t "; gets name!; cout<<"#n#n$nter(athe)s &ame of the 'tudent:#t"; gets fname!; * voidsho+data ! { cout<<"#n,dmission no. :#t"<<studentid; cout<<"#n'tudent &ame :#t "; puts name!; cout<<"#n(ather)s &ame :#t"; puts fname!; * intsearch-e. ! { returnstudentid; * *; void+ritedata ! { studentob/; ofstream+ritefile; cout<<"0000 ,11 2$3421 00000#n#n"; +ritefile.open "student.dat"5ios::binar.6ios::app!; ob/.getdata !; +ritefile.+rite char7!8ob/5si9eof ob/!!;

+ritefile.close !; * voiddispla.data ! { studentob/; ifstreamdisp; cout<<"00000000 1:';<,= 2$3421 000000#n#n"; disp.open "student.dat"5ios::binar.!; +hile disp.read char7!8ob/5si9eof ob/!!! { ob/.sho+data !; * disp.close !; * void search int n! { studentob/; ifstream sear; cout<<"0000000000 '$,23> 2$3421 0000000#n#n"; sear.open "student.dat"5ios::binar.!; +hile sear.read char7!8ob/5si9eof ob/!!! { if ob/.search-e. !00n! ob/.sho+data !; * sear.close !; * voiddelrecord int n! { studentob/; ifstreamdelr; cout<<"0000000000 1$<$%$$ 2$3421 0000000#n#n"; delr.open "student.dat"5ios::binar.!; ofstreamne+file; ne+file.open "%emp.dat"5ios::out6ios::binar.!; +hile delr.read char7!8ob/5si9eof ob/!!! { if ob/. search-e. !?0n! ne+file.+rite char7!8ob/5si9eof ob/!!; * delr.close !; ne+file.close !; remove "student.dat"!; rename "%emp.dat"5"student.dat"!;

* voidmodirecord int n! { fstreammodif; studentob/; cout<<"0000000000 @41:(= 2$3421 0000000#n#n"; int found00; modif.open "student.dat"5ios::in6ios::out!; +hile modif.read char7!8ob/5si9eof ob/!! 88 found000! { if ob/. search-e. !00n! { ob/.sho+data !; cout<<"#n$nter %he &e+ 1etails of student"; ob/.getdata !; intpos0AB7si9eof ob/!; modif.see-p pos5ios::cur!; modif.+rite char7!8ob/5si9eof ob/!!; found0B; * * modif.close !; * int main ! { int t; studentob/; gt: CCgoto destination declaration clrscr !; cout<<"00000 %,'D 00000"; cout<<"#n#nB. ,dd student 1etails "; cout<<"#n#n2. Eie+ 'tudent 1etails"; cout<<"#n#nF. 'earch 2ecord"; cout<<"#n#nG. @odif. 2ecord"; cout<<"#n#nH. 1elete 2ecord"; cout<<"#n#nI. $Jit"; cout<<"#n#n3hoose .our tas-...#t"; cin>>t; if t00B! { clrscr !; +ritedata !; cout<<"#n#npress an. -e. to goto tas- +indo+..."; getch !;

gotogt; * else if t002! { clrscr !; displa.data !; cout<<"#n#npress an. -e. to goto tas- +indo+..."; getch !; gotogt; * else if t00F! { clrscr !; int id; cout<<"#n$nter 'tudent id:#t"; cin>>id; search id!; cout<<"#n#npress an. -e. to gotota-s menu...."; getch !; gotogt; * else if t00G! { clrscr !; intmr; cout<<"#n$nter 'tudent id:#t"; cin>>mr; modirecord mr!; cout<<"#n#npress an. -e. to gotota-s menu...."; getch !; gotogt; * else if t00H! {intdr; cout<<"#n$nter 'tudent id:#t"; cin>>dr; delrecord dr!; cout<<"#n#npress an. -e. to gotota-s menu...."; getch !; gotogt;* else if t00I! { eJit 0!; *

else { cout<<"#n#ninvalid choice? please t.pe carefull...."; gotogt; * return 0; *

OUTPUT

You might also like