//==========================================================
==================
// Name : [Link]
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//==========================================================
==================
#include <iostream>
#include<fstream>
#include<cstring>
#include<iomanip>
using namespace std;
const int MAX=20;
class Student
{
int rollno;
char name[20],city[20];
char div;
int year;
public:
Student()
{
strcpy(name,"");
strcpy(city,"");
rollno=year=div=0;
}
Student(int rollno,char name[MAX],int year,char div,char
city[MAX])
{
strcpy(this->name,name);
strcpy(this->city,city);
this->rollno=rollno;
this->year=year;
this->div=div;
}
int getRollNo()
{
return rollno;
}
void displayRecord()
{
cout<<endl<<setw(5)<<rollno<<setw(20)<<name<<setw(5)<<year<<
setw(5)<<div<<setw(10)<<city;
}
};
//==========File Operations ===========
class FileOperations
{
fstream file;
public:
FileOperations(char* filename)
{
[Link](filename,ios::in|ios::out|ios::ate|ios::binary);
}
void insertRecord(int rollno, char name[MAX],int year, char
div,char city[MAX])
{
Student s1(rollno,name,year,div,city);
[Link](0,ios::end);
[Link]((char *)&s1,sizeof(Student));
[Link]();
}
void displayAll()
{
Student s1;
[Link](0,ios::beg);
while([Link]((char *)&s1, sizeof(Student)))
{
[Link]();
}
[Link]();
}
void displayRecord(int rollNo)
{
Student s1;
[Link](0,ios::beg);
bool flag=false;
while([Link]((char*)&s1,sizeof(Student)))
{
if([Link]()==rollNo)
{
[Link]();
flag=true;
break;
}
}
if(flag==false)
{
cout<<"\nRecord of "<<rollNo<<"is not present.";
}
[Link]();
}
void deleteRecord(int rollno)
{
ofstream outFile("[Link]",ios::binary);
[Link](0,ios::beg);
bool flag=false;
Student s1;
while([Link]((char *)&s1, sizeof(Student)))
{
if([Link]()==rollno)
{
flag=true;
continue;
}
[Link]((char *)&s1, sizeof(Student));
}
if(!flag)
{
cout<<"\nRecord of "<<rollno<<" is not present.";
}
[Link]();
[Link]();
remove("[Link]");
rename("[Link]","[Link]");
[Link]("[Link]",ios::in|ios::out|ios::ate|
ios::binary);
}
~FileOperations()
{
[Link]();
cout<<"\nFile Closed.";
}
};
int main() {
ofstream newFile("[Link]",ios::app|ios::binary);
[Link]();
FileOperations file((char*)"[Link]");
int rollNo,year,choice=0;
char div;
char name[MAX],address[MAX];
while(choice!=5)
{
//clrscr();
cout<<"\n*****Student Database*****\n";
cout<<"1) Add New Record\n";
cout<<"2) Display All Records\n";
cout<<"3) Display by RollNo\n";
cout<<"4) Deleting a Record\n";
cout<<"5) Exit\n";
cout<<"Choose your choice : ";
cin>>choice;
switch(choice)
{
case 1 : //New Record
cout<<endl<<"Enter RollNo and name : \n";
cin>>rollNo>>name;
cout<<"Enter Year and Division : \n";
cin>>year>>div;
cout<<"Enter address : \n";
cin>>address;
[Link](rollNo,name,year,div,address);
cout<<"\nRecord Inserted.";
break;
case 2 :
cout<<endl<<setw(5)<<"ROLL"<<setw(20)<<"NAME"<<setw(5)<<"YEA
R"<<setw(5)<<"DIV"<<setw(10)<<"CITY";
[Link]();
break;
case 3 :
cout<<"Enter Roll Number";
cin>>rollNo;
[Link](rollNo);
break;
case 4:
cout<<"Enter rollNo";
cin>>rollNo;
[Link](rollNo);
break;
case 5 :break;
}
return 0;
}