File Operations In File Handling

  • Uploaded by: yetendra singh chauhan
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View File Operations In File Handling as PDF for free.

More details

  • Words: 189
  • Pages: 3
#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); } }

}

Related Documents

File Handling In Detail.pdf
November 2019 9
File Handling
November 2019 13
File Handling
June 2020 11
File Handling In C
November 2019 20
File Handling Notes
August 2019 29

More Documents from "P.Palanisamy"