#include<iomanip.h>
#include<fstream.h>
#include<stdlib.h>
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
class student
{
public:
int roll;
char name[20],course[20];
float per;
}s;
//================================================================================================
// Function for Geting Student Details
//================================================================================================
void getdata()
{
system("cls");
cout<<"\n\n\t\t====Enter Student Details====";
cout<<"\nRoll: ";
cin>>s.roll;
cout<<"\nName: ";
cin>>s.name;
cout<<"\nCourse: ";
cin>>s.course;
cout<<"\nPercentage: ";
cin>>s.per;
fstream f1;
f1.open("file.dat",ios::app|ios::binary);
f1.write((char *)&s,sizeof(s));
f1.close();
}
//================================================================================================
// Function for Showing Student Details
//================================================================================================
void putdata()
{
system("cls");
cout<<"\n\n\t========Student Details========";
cout<<"\n\t=========================================================\n";
cout<<"\t"<<"Roll"<<setw(10)<<"Name"<<setw(15)<<"Course"<<setw(8)<<"%";
cout<<"\n\t=========================================================\n";
fstream f1;
f1.open("file.dat",ios::in|ios::binary);
f1.read((char *)&s,sizeof(s));
while(f1.eof()==0)
{
cout<<"\t"<<s.roll<<setw(15)<<s.name<<setw(10)<<s.course<<setw(12)<<s.per<<"\n";
f1.read((char *)&s,sizeof(s));
}
f1.close();
getch();
}
//================================================================================================
// Function for Searching Student Details
//================================================================================================
void searchdata()
{
system("cls");
int a;
cout<<"\n\tSearching Student Details";
cout<<"\n\n\tEnter Roll Number: ";
cin>>a;
fstream f1;
f1.open("file.dat",ios::in|ios::binary);
f1.read((char *)&s,sizeof(s));
while(f1.eof()==0)
{
if(a==s.roll)
{
cout<<"\nRoll: "<<s.roll<<"\n";
cout<<"Name: "<<s.name<<"\n";
cout<<"Course: "<<s.course<<"\n";
cout<<"Percentage: "<<s.per<<"\n";
}
f1.read((char *)&s,sizeof(s));
}
f1.close();
getch();
}
//================================================================================================
// Function for Updating Student Details
//================================================================================================
void editdata()
{
system("cls");
int a;
cout<<"\n\n\t\t======Updating A Student Record==========";
cout<<"\n\tEnter Roll Number: ";
cin>>a;
fstream f1;
f1.open("file.dat",ios::in|ios::out|ios::ate|ios::binary);
f1.seekg(0);
f1.read((char *)&s,sizeof(s));
while(!f1.eof())
{
if((a==s.roll)==1)
{
cout<<"\n\t\t==========Edit The Details==========";
cout<<"\n\n\t\t*****Please Enter New Data*****";
cout<<"\n\nRoll: ";
cin>>s.roll;
cout<<"\nName: ";
cin>>s.name;
cout<<"\nCourse: ";
cin>>s.course;
cout<<"\nPercentage: ";
cin>>s.per;
f1.seekp(f1.tellp()-sizeof(s));
f1.write((char *)&s,sizeof(s));
cout<<"\n\n\tRecord Updated";
getch();
break;
}
f1.read((char *)&s,sizeof(s));
}
f1.close();
}
//================================================================================================
// Function for Deleting Student Details
//================================================================================================
void deletedata()
{
system("cls");
int a;
cout<<"\n\n\t\t==========Deleting A Record===========";
cout<<"\nEnter Roll Number: ";
cin>>a;
fstream f1,f2;
f1.open("file.dat",ios::in|ios::binary);
if(!f1)
{
cout<<"\n\tFile Not Found";
}
else
{
f2.open("tempfile.dat",ios::out|ios::binary);
f1.read((char *)&s,sizeof(s));
while(!f1.eof())
{
if((a==s.roll)==0)
f2.write((char *)&s,sizeof(s));
f1.read((char *)&s,sizeof(s));
}
f1.close();
f2.close();
remove("file.dat");
rename("tempfile.dat","file.dat");
}
}
int main()
{
system("cls");
char ch;
while(1)
{
cout<<"\n\t========Student Information System=========";
cout<<"\n\n\t1.Insert student record";
cout<<"\n\t2.View student record";
cout<<"\n\t3.Search student record";
cout<<"\n\t4.Update student record";
cout<<"\n\t5.Delete student record";
cout<<"\n\t6.Exit";
cout<<"\n\n\tEnter your choice==> ";
ch= getchar();
if(ch=='1')
{
system("cls");
getdata();
}
else if(ch=='2')
{
system("cls");
putdata();
}
else if(ch=='3')
{
system("cls");
searchdata();
}
else if(ch=='4')
{
system("cls");
editdata();
}
else if(ch=='5')
{
system("cls");
deletedata();
}
else if(ch=='6')
{
exit(0);
}
}
}
#include<fstream.h>
#include<stdlib.h>
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
class student
{
public:
int roll;
char name[20],course[20];
float per;
}s;
//================================================================================================
// Function for Geting Student Details
//================================================================================================
void getdata()
{
system("cls");
cout<<"\n\n\t\t====Enter Student Details====";
cout<<"\nRoll: ";
cin>>s.roll;
cout<<"\nName: ";
cin>>s.name;
cout<<"\nCourse: ";
cin>>s.course;
cout<<"\nPercentage: ";
cin>>s.per;
fstream f1;
f1.open("file.dat",ios::app|ios::binary);
f1.write((char *)&s,sizeof(s));
f1.close();
}
//================================================================================================
// Function for Showing Student Details
//================================================================================================
void putdata()
{
system("cls");
cout<<"\n\n\t========Student Details========";
cout<<"\n\t=========================================================\n";
cout<<"\t"<<"Roll"<<setw(10)<<"Name"<<setw(15)<<"Course"<<setw(8)<<"%";
cout<<"\n\t=========================================================\n";
fstream f1;
f1.open("file.dat",ios::in|ios::binary);
f1.read((char *)&s,sizeof(s));
while(f1.eof()==0)
{
cout<<"\t"<<s.roll<<setw(15)<<s.name<<setw(10)<<s.course<<setw(12)<<s.per<<"\n";
f1.read((char *)&s,sizeof(s));
}
f1.close();
getch();
}
//================================================================================================
// Function for Searching Student Details
//================================================================================================
void searchdata()
{
system("cls");
int a;
cout<<"\n\tSearching Student Details";
cout<<"\n\n\tEnter Roll Number: ";
cin>>a;
fstream f1;
f1.open("file.dat",ios::in|ios::binary);
f1.read((char *)&s,sizeof(s));
while(f1.eof()==0)
{
if(a==s.roll)
{
cout<<"\nRoll: "<<s.roll<<"\n";
cout<<"Name: "<<s.name<<"\n";
cout<<"Course: "<<s.course<<"\n";
cout<<"Percentage: "<<s.per<<"\n";
}
f1.read((char *)&s,sizeof(s));
}
f1.close();
getch();
}
//================================================================================================
// Function for Updating Student Details
//================================================================================================
void editdata()
{
system("cls");
int a;
cout<<"\n\n\t\t======Updating A Student Record==========";
cout<<"\n\tEnter Roll Number: ";
cin>>a;
fstream f1;
f1.open("file.dat",ios::in|ios::out|ios::ate|ios::binary);
f1.seekg(0);
f1.read((char *)&s,sizeof(s));
while(!f1.eof())
{
if((a==s.roll)==1)
{
cout<<"\n\t\t==========Edit The Details==========";
cout<<"\n\n\t\t*****Please Enter New Data*****";
cout<<"\n\nRoll: ";
cin>>s.roll;
cout<<"\nName: ";
cin>>s.name;
cout<<"\nCourse: ";
cin>>s.course;
cout<<"\nPercentage: ";
cin>>s.per;
f1.seekp(f1.tellp()-sizeof(s));
f1.write((char *)&s,sizeof(s));
cout<<"\n\n\tRecord Updated";
getch();
break;
}
f1.read((char *)&s,sizeof(s));
}
f1.close();
}
//================================================================================================
// Function for Deleting Student Details
//================================================================================================
void deletedata()
{
system("cls");
int a;
cout<<"\n\n\t\t==========Deleting A Record===========";
cout<<"\nEnter Roll Number: ";
cin>>a;
fstream f1,f2;
f1.open("file.dat",ios::in|ios::binary);
if(!f1)
{
cout<<"\n\tFile Not Found";
}
else
{
f2.open("tempfile.dat",ios::out|ios::binary);
f1.read((char *)&s,sizeof(s));
while(!f1.eof())
{
if((a==s.roll)==0)
f2.write((char *)&s,sizeof(s));
f1.read((char *)&s,sizeof(s));
}
f1.close();
f2.close();
remove("file.dat");
rename("tempfile.dat","file.dat");
}
}
int main()
{
system("cls");
char ch;
while(1)
{
cout<<"\n\t========Student Information System=========";
cout<<"\n\n\t1.Insert student record";
cout<<"\n\t2.View student record";
cout<<"\n\t3.Search student record";
cout<<"\n\t4.Update student record";
cout<<"\n\t5.Delete student record";
cout<<"\n\t6.Exit";
cout<<"\n\n\tEnter your choice==> ";
ch= getchar();
if(ch=='1')
{
system("cls");
getdata();
}
else if(ch=='2')
{
system("cls");
putdata();
}
else if(ch=='3')
{
system("cls");
searchdata();
}
else if(ch=='4')
{
system("cls");
editdata();
}
else if(ch=='5')
{
system("cls");
deletedata();
}
else if(ch=='6')
{
exit(0);
}
}
}
No comments:
Post a Comment