Object Oriented Programming Aman Gupta 15BEC1162
Object Oriented Programming Aman Gupta 15BEC1162
Object Oriented Programming Aman Gupta 15BEC1162
#include<fstream>
#include<iomanip>
#include<iostream>
struct student
int eno;
char name[20];
float marks;
};
void file_allread()
ifstream stud_file;
stud_file.open("student.txt");
char ch;
int i=1;
while(!stud_file.eof())
if(!stud_file.eof())
{
cout<<"Record Number:"<<i<<endl;
cout<<"identity No:"<<stud.eno<<endl;
cout<<"student Name:"<<stud.name<<endl;
cout<<"marks"<<stud.marks<<endl;
i++;
} }
stud_file.close();
cout<<"====End====="<<endl;
//Function to enter a specific record number and to view that record only
void file_spread()
ifstream stud_file;
stud_file.open("student.txt");
char ch;
int r;
cin>>r;
r--;
if(!stud_file.eof())
cout<<"student No:"<<stud.eno<<endl;
cout<<"student Name:"<<stud.name<<endl;
cout<<"marks"<<stud.marks<<endl; }
stud_file.close();
cout<<"====End===="<<endl;
void file_write()
ofstream stud_file;
stud_file.open("student.txt",ios::app);
char ch;
cout<<"====Write Record===="<<endl;
cout<<"student No:";
cin>>stud.eno;
cout<<"student Name:";
cin>>stud.name;
cout<<"marks";
cin>>stud.marks;
else
stud_file.close();
cout<<"====End===="<<endl;
void file_update()
fstream stud_file;
cout<<"====Update Record===="<<endl;
stud_file.open("student.txt");
char ch;
int r;
cin>>r;
r--;
stud_file.seekp((sizeof(struct student)*r),ios::beg);
cout<<"student No:";
cin>>stud.eno;
cout<<"student Name:";
cin>>stud.name;
cout<<"marks";
cin>>stud.marks;
else
stud_file.close();
cout<<"====End====="<<endl;
void file_copy()
ifstream stud_file;
stud_file.open("student.txt");
ofstream stud_bak_file;
stud_bak_file.open("student_backup.txt");
char ch;
int i=0;
while(!stud_file.eof())
if(!stud_file.eof())
i++;
stud_file.close();
stud_bak_file.close();
cout<<"====End===="<<endl;
int menu()
int opt;
cout<<"===Menu==="<<endl;
cout<<"3.Write a Record"<<endl;
cout<<"4.Update a Record"<<endl;
cout<<"5.Backup file"<<endl;
cout<<"6.Exit"<<endl;
cout<<"======"<<endl;
while(1)
cin>>opt;
break;
return opt; }
main()
int opt;
char ch;
while(1)
{ opt=menu();
if(opt==6)
break;
if(opt==1)
file_allread();
if(opt==2)
file_spread();
if(opt==3)
file_write();
if(opt==4)
file_update();
if(opt==5)
file_copy();
cout<<"Good Bye!!!"<<endl;