Вы находитесь на странице: 1из 6

#include<iostream.

h>
#include<conio.h>
#include<fstream.h>
#include<process.h>
#include<stdio.h>
#include<iomanip.h>
class student
{
int rolno;
char name[50];
int phy, chem, maths, eng, csc;
float percent;
char grade;
void calculate();
public:
void getdata();
void showdata();
void show_tabular();
int rollno();
};
void student::calculate()
{
percent=(phy+chem+maths+eng+csc)/5.0;
if(percent>=80)
grade='A';
else if(percent>=65)
grade='B';
else if(percent>=50)
grade='C';
else if(percent>=40)
grade='D';
else
grade='F';
}
void student::getdata()
{
cout<<"\nEnter The roll number of student ";
cin>>rolno;
cout<<"\n\nEnter The Name of student ";
gets(name);
cout<<"\nEnter The marks in physics out of 100 : ";
cin>>phy;
cout<<"\nEnter The marks in chemistry out of 100 : ";
cin>>chem;
cout<<"\nEnter The marks in maths out of 100 : ";
cin>>maths;
cout<<"\nEnter The marks in english out of 100 : ";
cin>>eng;
cout<<"\nEnter The marks in computer science out of 100 : ";
cin>>csc;
calculate();
}
void student::showdata()

{
cout<<"\nRoll number of student : "<<rollno();
cout<<"\nName of student : "<<name;
cout<<"\nMarks in Physics : "<<phy;
cout<<"\nMarks in Chemistry : "<<chem;
cout<<"\nMarks in Maths : "<<maths;
cout<<"\nMarks in English : "<<eng;
cout<<"\nMarks in Computer Science :"<<csc;
cout<<"\nPercentage of student is :"<<percent;
cout<<"\nGrade of student is :"<<grade;
}
void student::show_tabular()
{
cout<<rollno()<<setw(6)<<" "<<name<<setw(10)<<phy<<setw(4)<<chem<<setw(4
)<<maths<<setw(4)
<<eng<<setw(4)<<csc<<setw(6)<<percent<<setw(6)<<" "<<grade<<endl
;
}
int student::rollno()
{
return rolno;
}
//==================================================================
void insert();
void display();
void search(int);
void modify(int);
void delte(int);
void classresult();
void resultmenu();
void fstpage();
void addedit();
//==================================================================
void insert()
{
student s;
fstream f1;
f1.open("students.dat",ios::binary|ios::app);
s.getdata();
f1.write((char *) &s, sizeof(student));
f1.close();
cout<<"\n\nStudent record Has Been Inserted ";
cin.ignore();
getch();
}
//==================================================================
void display()
{
student s;
fstream f1;
f1.open("students.dat",ios::in|ios::binary);
if(!f1)
{
cout<<"Error in opening file!! Press any key to return";

getch();
return;
}
cout<<"\n\n\n\t\tDISPLAYING ALL RECORDS \n\n";
while(f1.read((char *) &s, sizeof(student)))
{
s.showdata();
cout<<"\n\n====================================\n";
}
f1.close();
getch();
}
//==================================================================
void search(int n)
{
student s;
fstream f1;
f1.open("students.dat",ios::binary|ios::out|ios::in);
if(!f1)
{
cout<<"Error in opening file!! Press any key to return";
getch();
return;
}
int flag=0;
while(f1.read((char *) &s, sizeof(student)))
{
if(s.rollno()==n)
{
s.showdata();
flag=1;
}
}
f1.close();
if(flag==0)
cout<<"\n\nRecord does not exist";
getch();
}
//==================================================================
void modify(int n)
{
int found=0;
student s;
fstream f1;
f1.open("students.dat",ios::binary|ios::in|ios::out);
if(!f1)
{
cout<<"Error in opening file!! Press any key to return";
getch();
return;
}
while(f1.read((char *) &s, sizeof(student)) && found==0)
{
if(s.rollno()==n)
{
s.showdata();
cout<<"\n\nPlease Enter The New Details of Student"<<endl;
s.getdata();

int pos=(-1)*sizeof(s);
f1.seekp(pos,ios::cur);
f1.write((char *) &s, sizeof(student));
cout<<"\n\n\t Record Updated";
found=1;
}
}
f1.close();
if(found==0)
cout<<"\n\n Record does not exist ";
getch();
}
//==================================================================
void delte(int n)
{
student s;
fstream f5;
f5.open("students.dat",ios::binary|ios::in|ios::out);
if(!f5)
{
cout<<"Error in opening file!! Press any key to return";
getch();
return;
}
fstream f6;
f6.open("Temp.dat",ios::out);
f5.seekg(0,ios::beg);
while(f5.read((char *) &s, sizeof(student)))
{
if(s.rollno()!=n)
{
f6.write((char *) &s, sizeof(student));
}
}
f6.close();
f5.close();
remove("students.dat");
rename("Temp.dat","student.dat");
cout<<"\n\n\tRecord Deleted!";
getch();
}
//==================================================================
void classresult()
{
student s;
fstream f1;
f1.open("students.dat",ios::binary|ios::in|ios::out);
if(!f1)
{
cout<<"Cannot open file ";
getch();
return;
}
cout<<"\n\n\t\tComplete Class Results \n\n";
cout<<"================================================\n";
cout<<"R.No
Name
P C M E CSC Overall% Grade"<<end
l;
cout<<"================================================\n";

while(f1.read((char *) &s, sizeof(student)))


{
s.show_tabular();
}
getch();
f1.close();
}
//==================================================================
void fstpage()
{
cout<<"\n\n\n\t\t STUDENT REPORT CARD SYSTEM ";
getch();
}
//==================================================================
void resultmenu()
{
char ch;
int rno;
double pass;
cout<<"\n\n\n\tRESULT MENU";
cout<<"\n\n\n\t1. Class Result";
cout<<"\n\n\t2. Student Report Card";
cout<<"\n\n\t3. Back to Main Menu";
cout<<"\n\n\n\tEnter Choice (1/2/3)? ";
cin>>ch;
clrscr();
switch(ch)
{
case '1' :cout<<"\n Only senior school authorities are allowed to view t
he complete class results ";
cout<<"Enter the 5-digit passwor
d to view the class results";
cin>>pass;
classresult(); break;
case '2' :cout<<"\n\n\tEnter Roll Number Of Student : ";
cin>>rno;
search(rno); break;
case '3' :break;
default :cout<<"\a";
}
}

//==================================================================
void addedit()
{
char ch;
int num;
clrscr();
cout<<"\n\n\n\t ADD/EDIT MENU";
cout<<"\n\n\t1.CREATE STUDENT RECORD";
cout<<"\n\n\t2.DISPLAY ALL STUDENTS RECORDS";
cout<<"\n\n\t3.SEARCH STUDENT RECORD ";
cout<<"\n\n\t4.MODIFY STUDENT RECORD";
cout<<"\n\n\t5.DELETE STUDENT RECORD";
cout<<"\n\n\t6.BACK TO MAIN MENU";
cout<<"\n\n\tPlease Enter Your Choice (1-6) ";

cin>>ch;
clrscr();
switch(ch)
{
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
default:
}

insert(); break;
display(); break;
cout<<"\n\n\tPlease Enter The roll number "; cin>>num;
search(num); break;
cout<<"\n\n\tPlease Enter The roll number "; cin>>num;
modify(num);break;
cout<<"\n\n\tPlease Enter The roll number "; cin>>num;
delte(num);break;
break;
cout<<"\a"; addedit();

}
//==================================================================
int main()
{
char ch;
cout.setf(ios::fixed|ios::showpoint);
cout<<setprecision(2);
clrscr();
fstpage();
do
{
clrscr();
cout<<"\n\n\n\tMAIN MENU";
cout<<"\n\n\t01. RESULT MENU";
cout<<"\n\n\t02. ADD/EDIT MENU";
cout<<"\n\n\t03. EXIT";
cout<<"\n\n\tPlease Select Your Option (1-3) ";
cin>>ch;
clrscr();
switch(ch)
{
case '1': resultmenu();
break;
case '2': addedit();
break;
case '3': break;
default :cout<<"\a";
}
}
while(ch!='3');
return 0;
}

Вам также может понравиться