#include<stdio.h> #include #include #include<process.h> class student { private: char name[10]; char branch[10]; int id; char semester[10]; public:
void void void void void void
}; void student:: getdata() { cout<<"enter the name"; cin>>name; cout<<"enter the branch"; cin>>branch; cout<<"enter the semester"; cin>>semester; cout<<"enter id"; cin>>id; this->saveinfile();
getdata(); saveinfile(); readfromfile(); display(); search(); deleted();
} void student::saveinfile() { fstream obj; obj.open("record.txt",ios::app); obj.write((char*)this,sizeof(student)); obj.close(); } void student::readfromfile() { fstream obj; obj.open("record.txt",ios::in|ios::nocreate); if(!obj.fail()) { obj.read((char*)this,sizeof(student)); while(!obj.eof()) { this->display(); obj.read((char*)this,sizeof(student)); } } obj.close();
} void student::display() { cout<
cout<>id2; obj.open("record.txt",ios::in|ios::nocreate); obj1.open("new.txt",ios::app); obj.read((char*)this,sizeof(student)); while(!obj.eof()) { if(this->id!=id2) { obj1.write((char*)this,sizeof(student)); } obj.read((char*)this,sizeof(student)); } remove("record.txt"); rename("new.txt","record.txt"); } void student::search() { int id1; fstream obj; obj.open("record.txt",ios::in); obj.read((char*)this,sizeof(student)); cout<<"enter the id to search"; cin>>id1; while(!obj.eof()) { if(this->id==id1) { cout<<endl<<"record is found"<<endl; int l=obj.tellg(); obj.seekg(l- sizeof(student)); obj.read((char *)this,sizeof(student)); this->display(); break; } obj.read((char *)this,sizeof(student)); } obj.close(); } void main() { student s1; clrscr(); int x; while(1) {
cout<<" MENU"<<endl; cout<<"1..add,2..display,3..search,4..remove,5..exit"<<endl; cout<<"enter your choice"<<endl; cin>>x; switch(x) { case 1: s1.getdata(); break; case 2: s1.readfromfile(); break; case 3: s1.search(); break; case 4: s1.deleted(); break; case 5: exit(0); } }
}