Wednesday, February 5, 2014

A project on student reportcard c++

#include<iomanip.h>
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
class reportcard
{
float sno,percentage,rollno,p_marks,c_marks,m_marks,e_marks,co_marks;
char name[20],grade;
void cal();
public :
void getdetails();
void showdetails();
void tabular();
int retroll();
};
void reportcard::getdetails()         //funtion gets details
{
cout<<endl<<endl<<endl<<"Enter S.NO         : ";
cin>>sno;
cout<<endl<<endl      <<"Enter STUDENT NAME : ";
gets(name);
cout<<endl<<endl      <<"Enter ROLL NO      : ";
cin>>rollno;
cout<<endl<<endl<<endl<<endl<<"Enter Marks in PHYSICS (out of 100)   : ";
cin>>p_marks;
cout<<endl<<endl<<"Enter Marks in CHEMISTRY (out of 100) : ";
cin>>c_marks;
cout<<endl<<endl<<"Enter Marks in MATHS (out of 100)     : ";
cin>>m_marks;
cout<<endl<<endl<<"Enter Marks in ENGLISH (out of 100)   : ";
cin>>e_marks;
cout<<endl<<endl<<"Enter Marks in COMPUTER (out of 100)  : ";
cin>>co_marks;
cal();
}
void reportcard::showdetails()  //function show details
{clrscr();
cout<<endl<<endl<<endl<<"S.NO         : "<<sno;
cout<<endl<<endl      <<"STUDENT NAME : ";
puts(name);
cout<<endl<<endl      <<"ROLL NO      : "<<rollno;
cout<<endl<<endl<<endl<<endl<<"Marks in PHYSICS (out of 100)   : "<<p_marks;
cout<<endl<<endl<<"Marks in CHEMISTRY (out of 100) : "<<c_marks;
cout<<endl<<endl<<"Marks in MATHS (out of 100)     : "<<m_marks;
cout<<endl<<endl<<"Marks in ENGLISH (out of 100)   : "<<e_marks;
cout<<endl<<endl<<"Marks in COMPUTER (out of 100)  : "<<co_marks;
cout<<endl<<endl<<endl<<"PERCENTAGE : "<<percentage<<"%";
cout<<endl<<endl      <<"Grade      : "<<grade<<endl<<endl;
}
int reportcard::retroll()  //function returns roll number
{
return rollno;
}
void reportcard::cal()    //function calculates grade and percentage
{
percentage=(p_marks+c_marks+m_marks+e_marks+c_marks)/5;
if(percentage>=90)
grade='A';
else if(percentage<90&&percentage>=80)
grade='B';
else if(percentage<80&&percentage>=70)
grade='C';
else if(percentage<70&&percentage>=60)
grade='D';
else if(percentage<60&&percentage>=33)
grade='E';
else if(percentage<33)
grade='F';
}
void reportcard::tabular()
{
cout<<endl<<sno<<'\t'<<rollno<<'\t'<<name<<'\t'<<p_marks<<'\t'<<c_marks<<'\t'<<m_marks<<'\t'<<e_marks<<'\t'<<co_marks<<setw(13)<<percentage<<endl<<endl;
}


void appendrecords();   //appends data in binary file
void displayallrecords();  //shows all records in tabular form
void modifyrecord(int);  // modifies a record
void deleterecord(int);  //delets a record
void displayrecord(int); //displays a particular record
int main()
{
clrscr();
int num=0,a=0,b=0;
do
{
clrscr();
cout<<endl<<endl<<endl;
cout<<"================================================================================================================================================================"<<endl<<endl;
cout<<endl<<'\t'<<'\t'<<'\t'<<"Press 1 to enter input/edit record menu"<<endl<<endl;
cout<<'\t'<<'\t'<<'\t'<<"Press 2 to show class result"<<endl<<endl;
cout<<'\t'<<'\t'<<'\t'<<"Press 3 to exit"<<endl<<endl;
cout<<endl<<endl<<endl<<"================================================================================================================================================================"<<endl<<endl;
cout<<endl<<endl<<endl<<"ENTER CHOICE (1/2/3) : ";
cin>>a;
if(a==1)
{
clrscr();
cout<<endl<<endl<<endl;
cout<<"================================================================================================================================================================"<<endl<<endl;
cout<<endl<<endl<<'\t'<<'\t'<<'\t'<<"Press 1 to input a new record"<<endl<<endl;
cout<<'\t'<<'\t'<<'\t'<<"Press 2 to display a particular record"<<endl<<endl;
cout<<'\t'<<'\t'<<'\t'<<"Press 3 to modify a record"<<endl<<endl;
cout<<'\t'<<'\t'<<'\t'<<"Press 4 to delete a record"<<endl<<endl;
cout<<endl<<endl;
cout<<"================================================================================================================================================================"<<endl<<endl;
cout<<endl<<endl<<endl<<"ENTER CHOICE : ";
cin>>b;
if(b==1)
appendrecords();
else if(b==2)
{clrscr();
cout<<endl<<endl<<"ENTER ROLL NUMBER : ";
cin>>num;
displayrecord(num);
}
else if(b==3)
{clrscr();
cout<<endl<<endl<<"ENTER ROLL NUMBER : ";
cin>>num;
modifyrecord(num);
}
else if(b==4)
{
clrscr();
cout<<endl<<endl<<"ENTER ROLL NUMBER : ";
cin>>num;
deleterecord(num);
}
else
{
cout<<endl<<endl<<endl<<"WRONG CHOICE, Press any key to return back...";
getch();
}
}
else if(a==2)
displayallrecords();
else if(a==3)
exit(0);
else
{
cout<<endl<<endl<<endl<<"WRONG CHOICE, Press any key to enter again....";
getch();
}
}while(a!=3);
return 0;
}
void appendrecords()//appending record into binary file
{
clrscr();
reportcard ob;
ofstream fo;
fo.open("file.dat",ios::binary|ios::app);
ob.getdetails();
fo.write((char*)&ob,sizeof(ob));
fo.close();
cout<<endl<<endl<<"RECORD INPUTED"<<endl;
getch();
}

void displayrecord(int n) // reads a particular record from file
{
clrscr();
reportcard ob;
ifstream fin;
fin.open("file.dat",ios::binary);
while(fin.read((char*)&ob,sizeof(reportcard)))
{
if(ob.retroll()==n)
{
clrscr();
cout<<endl<<endl;
ob.showdetails();
}
}
fin.close();
getch();
}
void modifyrecord(int n)
{
clrscr();
reportcard ob;
fstream fin;
fin.open("file.dat",ios::binary|ios::in|ios::out);
if(!fin)
{
cout<<"File Doesnt Exist"<<endl;
return;
}
while(fin.read((char*)&ob,sizeof(reportcard)))
{
if(ob.retroll()==n)
{
clrscr();
ob.showdetails();
cout<<endl<<endl<<"ENTER NEW DETAILS"<<endl;
ob.getdetails();
int pos=(-1)*sizeof(ob);
fin.seekg(pos,ios::cur);
fin.write((char*)&ob,sizeof(reportcard));
cout<<endl<<endl<<"RECORD UPDATED"<<endl;
}
}
fin.close();
getch();
}
void deleterecord(int n)
{
clrscr();
reportcard ob;
ifstream fin;
fin.open("file.dat",ios::binary);
ofstream fo;
if(!fin)
{
cout<<"FILE DOESNT EXIST"<<endl;
return;
}
fo.open("temp.dat",ios::binary|ios::out);
fin.seekg(0,ios::beg);
while(fin.read((char*)&ob,sizeof(reportcard)))
{
if(ob.retroll()!=n)
{
fo.write((char*)&ob,sizeof(reportcard));
}
}
fin.close();
fo.close();
remove("file.dat");
rename("temp.dat","file.dat");
cout<<endl<<endl<<"RECORD DELETED"<<endl;
getch();
}
void displayallrecords()
{
clrscr();
reportcard ob;
ifstream fin;
fin.open("file.dat",ios::binary);
cout<<endl<<endl;
cout<<"================================================================================================================================================================"<<endl<<endl;
cout<<"S.NO"<<'\t'<<"ROLLNO"<<'\t'<<"NAME"<<setw(15)<<"PHY"<<'\t'<<"CHEM"<<'\t'<<"Maths"<<'\t'<<"Eng"<<'\t'<<"Comp"<<'\t'<<"Per"<<endl<<endl;
cout<<"================================================================================================================================================================"<<endl<<endl;
while(fin.read((char*)&ob,sizeof(ob)))
{
ob.tabular();
}
fin.close();
getch();
}




No comments:

Post a Comment