Skip to content

Commit

Permalink
file handling
Browse files Browse the repository at this point in the history
  • Loading branch information
linrakesh committed Oct 15, 2019
1 parent 028eb45 commit 81d4ad2
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
34 changes: 34 additions & 0 deletions File_handling/sarthak/delete_record.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include<fstream>
#include<iostream>
using namespace std;
struct student{
int admno;
char name[30];
char add[80];
float fees;
};

int main(){

ifstream fin("student.dat");
ofstream fout("temp.dat");

student s;
int tadmno;

cout<<"\n Enter Admno no that you want to delete ";
cin>>tadmno;

while(fin.read((char *)&s,sizeof(student))){
if(s.admno!=tadmno){
fout.write((char *)&s,sizeof(student));
}
}
fin.close();
fout.close();

remove("student.dat");
rename("temp.dat","student.dat");

return 0;
}
14 changes: 14 additions & 0 deletions File_handling/sarthak/duplicater.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<fstream>
#include<iostream>
using namespace std;
int main(){
ifstream fin("sarthak.txt");
ofstream fout("dup.txt");
char ch;
while(fin.get(ch)){
fout<<ch;
}
fin.close();
fout.close();
return 0;
}
26 changes: 26 additions & 0 deletions File_handling/sarthak/file_read_student.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<fstream>
#include<iostream>
using namespace std;
struct student{
int admno;
char name[30];
char add[80];
float fees;
};

int main(){

ifstream fin("student.dat");
student s;
cout<<"\n Data from file \n";

while(fin.read((char *)&s,sizeof(student))){
cout<<"\n Admno :"<<s.admno;
cout<<"\n Name :"<<s.name;
cout<<"\n Address :"<<s.add;
cout<<"\n Fees :"<<s.fees;
}
fin.close();

return 0;
}
32 changes: 32 additions & 0 deletions File_handling/sarthak/student_record_file.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include<fstream>
#include<iostream>
using namespace std;
struct student{
int admno;
char name[30];
char add[80];
float fees;
};

int main(){
ofstream fout("student.dat",ios::app);
student s;
char choice;
do{
cout<<"\n Enter admno :";
cin>>s.admno;
cout<<"\n Enter name : ";
cin>>s.name;
cout<<"\n Enter address :";
cin>>s.add;
cout<<"\n Enter fees : ";
cin>>s.fees;
fout.write((char *)&s, sizeof(student));
cout<<"\n Want to add more records(y/n) :";
cin>>choice;
}while(choice!='n');

fout.close();

return 0;
}
38 changes: 38 additions & 0 deletions File_handling/sarthak/update_record.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include<fstream>
#include<iostream>
using namespace std;
struct student{
int admno;
char name[30];
char add[80];
float fees;
};

int main(){

ifstream fin("student.dat");
ofstream fout("temp.dat");

student s;
int tadmno;

cout<<"\n Enter Admno no that you want to update ";
cin>>tadmno;

while(fin.read((char *)&s,sizeof(student))){
if(s.admno==tadmno){
cout<<"\n Enter new address :";
cin>>s.add;
cout<<"\n Enter new fees :";
cin>>s.fees;
}
fout.write((char *)&s,sizeof(student));
}
fin.close();
fout.close();

remove("student.dat");
rename("temp.dat","student.dat");

return 0;
}

0 comments on commit 81d4ad2

Please sign in to comment.