Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

PROJECT WORK ON COMPUTER SCIENCE

Programme for Telephone Directory


#include<iostream.h> #include<conio.h> #include<fstream.h> #include<stdio.h> #include<process.h> class fileop { public: char name[50]; char fname[50]; char pn[20]; int rolls; void readdata() { cout<<"Enter your name:"; cin>>name; cout<<"Enter your father name:"<<endl; cin>>fname; cout<<"Enter your roll:"; cin>>rolls; cout<<"Enter phone no.:"; cin>>pn; }

ST. XAVIERS COLLEGE, RANCHI-834001

PROJECT WORK ON COMPUTER SCIENCE


void display() { cout<<"Name:"<<name<<"\n"; cout<<"Father name:"<<fname<<"\n"; cout<<"Roll:"<<rolls<<"\n"; cout<<"Phone no.::"<<pn<<"\n"; } int roll() { return rolls; } }; void main() { clrscr(); ifstream file; ofstream fout; fileop obj; int o; int n,i; char ch; char check; char s='n'; while(s=='n') { clrscr();

ST. XAVIERS COLLEGE, RANCHI-834001

PROJECT WORK ON COMPUTER SCIENCE


cout<<"Menu\n"; cout<<"press 1 for searching\n"; cout<<"press 2 for insertion\n"; cout<<"press 3 for deletion\n"; cout<<"press 4 for updation\n"; cout<<"press 5 for all the records\n"; cout<<"Enter your choice:"; cin>>o; switch(o) { case 1: cout<<"\nEnter the roll of student:"; cin>>n; i=0; file.open("welcome.txt"); while(file.read((char*)&obj,sizeof (fileop))) { if(obj.roll()==n) { i++; cout<<"Roll "<<n<<" is present\n"; cout<<"\nyou want to see detail:"; char op; cin>>op; if(op=='y') obj.display(); }

ST. XAVIERS COLLEGE, RANCHI-834001

PROJECT WORK ON COMPUTER SCIENCE


}

file.close(); break; case 2: char ch; i=0; cout<<"\nyou want to insert(y or n):"; cin>>ch; file.open("welcome.txt"); fout.open("temp.txt"); while(file.read((char*)&obj,sizeof (fileop))) { fout.write((char*)&obj,sizeof (fileop)); } while(ch=='y') { obj.readdata(); fout.write((char*)&obj,sizeof (fileop)); cout<<"\nYou want to continue inserting(y or n):"; cin>>ch; } remove("welcome.txt"); rename("temp.txt","welcome.txt"); fout.close(); file.close();

ST. XAVIERS COLLEGE, RANCHI-834001

PROJECT WORK ON COMPUTER SCIENCE


break; case 3: i=0; cout<<"\nEnter Roll of Student you want to delete:"; cin>>n; file.open("welcome.txt"); fout.open("temp.txt"); while(file.read((char*)&obj,sizeof (fileop))) { if(obj.roll()!=n) { fout.write((char*)&obj,sizeof (fileop)); } else i++; } fout.close(); file.close(); remove("welcome.txt"); rename("temp.txt","welcome.txt"); if(i==0) cout<<"\nRecord not found"; else cout<<"\nRecord deleted"; break; case 4: cout<<"\nyou want to modify(y or n):";

ST. XAVIERS COLLEGE, RANCHI-834001

PROJECT WORK ON COMPUTER SCIENCE


cin>>ch; cout<<" roll: "; cin>>n; file.open("welcome.txt"); fout.open("temp.txt"); while(file.read((char*)&obj,sizeof (fileop))) { if(obj.roll()==n) { obj.display(); cout<<"\nEnter the records:"; obj.readdata(); } fout.write((char*)&obj,sizeof (fileop)); } remove("welcome.txt"); rename("temp.txt","welcome.txt"); fout.close(); file.close(); break; case 5: i=1; file.open("welcome.txt"); while(file.read((char*)&obj,sizeof (fileop))) { cout<<"\nDetails of student "<<i; obj.display(); i++;

ST. XAVIERS COLLEGE, RANCHI-834001

PROJECT WORK ON COMPUTER SCIENCE


} } cout<<"\nDo you want to exit:"; cin>>s; } getch(); }

ST. XAVIERS COLLEGE, RANCHI-834001

You might also like