Documente Academic
Documente Profesional
Documente Cultură
Page | 1
ACKNOWLEDGEMENT
Page | 2
INDEX
Introduction
Header files
used Working
C++ coding
Output Screenshots
Bibliography
Page | 3
INTRODUCTION
Page | 5
HEADER FILES USED
#include<fstream.h>
#include<iomanip.h>
#include<stdio.h>
#include<conio.h>
#include<string. h>
Page | 6
WORKING
Page | 7
PROGRAM CODING
#include<fstream.h>
#include<iomanip.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
class student
{
int rollno;
char name[50],password,kvmeg;
int p_marks, c_marks, m_marks,
e_marks, cs_marks;
float per;
char grade;
void calculate();
public:
void getdata();
void showdata();
void show_tabular();
Page | 8
int retrollno();
int roll()
{
return(rollno);
}
};
void student::calculate()
{
per=(p_marks+c_marks+m_marks+e_marks+cs_m
arks)/5;
if(per>=60)
grade='A';
else if(per>=50)
grade='B';
else if(per>=33)
grade='C';
else
grade='F';
}
Page | 9
void student::getdata()
{ int r; s;
student
cout<<"\n enter the roll no. of the
student "; cin>>r;
fstream sid("student.dat",ios::binary|ios::in);
while(!sid.eof())
{
sid.read((char*)&s,sizeof(student));
if(s.roll()==r)
{
cout<<"This Roll Number Already
Exists"; goto last;
}
}
rollno=r;
sid.close();
cout<<"\n\n enter the name of
student "; gets(name);
cout<<"\n enter the marks obtained in
physics out of 100: ";
Page | 10
cin>>p_marks;
cout<<"\n enter the marks
obtained in chemistry out of 100: ";
cin>>c _marks;
cout<<"\n enter the marks obtained in
english out of 100: ";
cin>>e_marks;
cout<<"\n enter the marks obtained
in maths out of 100: ";
cin>>m_marks;
cout<<"\n enter the marks
obtained in computer science out of 100: ";
cin>>cs_marks;
calculate();
cout<<"Record Created ";
last:
}
void student::showdata()
{
cout<<"\n roll no of student: "<<rollno;
cout<<"\n name of student: "<<name;
cout<<"\n marks in physics: "<<p_marks; Page | 11
cout<<"\n marks in chemistry: "<<c_marks;
cout<<"\n marks in english: "<<e_marks;
cout<<"\n marks in maths: "<<m_marks;
cout<<"\n marks in computer science:
"<<cs_marks;
cout<<"\n percentage of student is:
"<<per; cout<<"\n grade of student
is; "<<grade; getch(); }
void student::show_tabular()
{
cout<<rollno<<"\t";
for(int sd=0;sd<strlen(name)&&sd<15;sd++)
cout<<name[sd];
if(strlen(name)<=6)
cout<<"\t";
cout<<"\t"<<p_marks<<"\t"<<c_marks<<"\t"<<e_
marks<<"\t"<<m_marks<<"\t"<<cs_marks<<"\t"<<per
<<"\t"<<grade<<endl;
}
int student::retrollno()
{
Page | 12
} return rollno;
void write_student();
void display_all();
void display_sp(int);
void modify_student(int);
void delete_student(int);
void class_result();
void result();
void intro();
void entry_menu();
int main()
{
s:
char ch;
cout.setf(ios::fixed|ios::showpoint);
cout<<setprecision(2);
clrscr();
intro();
do
{
Page | 13
clrscr(); MAIN
MENU "; cout<<"\n\n\n\t
break;
case '2': entry_menu();
break;
case '3':remove("student.dat");
Deleted"; cout<<"\n\n\tAll Records
outfile.open("student.dat",ios::binary|ios::app);
st.getdata();
outfile.write((char*)&st,
sizeof(student)); cin.ignore();
getch();
}
void display_all()
{
student st;
Page | 15
ifstream infile;
infile.open("student.dat",ios::binary);
if(!infile)
{ cout<<" file could not be open !!press
any key...";
getch();
} return;
sizeof(student));
if(infile.eof()||!infile)
break;
st.showdata();
cout<<"\n\n=================\n\n";
}
}
Page | 16
void display_sp(int n)
{ student st;
ifstream infile;
infile.open("student.dat",ios::binary);
if(!infile)
{ cout<<" file could not be open
} return;
int flag=0;
sizeof(student))) while(infile.read((char*)&st,
{
if(st.retrollno()==n)
{ st.showdata();
flag=1;
Page | 17
}
}
infile.close();
if(flag==0)
cout<<"\n\nrecord does not
exist "; getch();
}
void modify_student(int n)
{
int found=0;
student st;
fstream file;
file.open("student.dat",ios::binary|ios::in|ios::out);
if(!file)
{ cout<<" file could not be open
Page | 18
while(file.read((char*)&st,
sizeof(student))&&found==0)
{
if(st.retrollno()==n)
{
st.showdata();
cout<<"\n\nplease enter
the new details of student"<<endl;
st.getdata();
int pos=(-1)*sizeof(st);
file.seekp(pos,ios::cur);
file.write((char*)&st,
sizeof(student));
}found=-1;
}
file.close();
if(found==0)
cout<<"\n\n record not
student st;
ifstream infile;
infile.open("student.dat",ios::binary);
if(!infile)
{
cout<<"file could not be open !! press any key....";
getch();
return;
}
ofstream outfile;
outfile.open("temp.dat",ios::out|ios::binary);
infile.seekg(0,ios::beg);
while(!infile.eof())
{
Page | 20
infile.read((char*)&st,
sizeof(student)); if(infile.eof())
break;
{if(st.retrollno()!=n)
outfile.write((char*)&st,sizeof(student));
}
else if(st.retrollno()==n)
{
}flag=1;
}
outfile.close();
infile.close();
remove("student.dat");
rename("temp.dat","student.dat");
if(flag==1)
cout<<"\n\n\trecord deleted...";
else
cout<<"\n\nNo Record Found ";
Page | 21
getch();
}
void class_result()
{
student st;
ifstream infile;
infile.open("student.dat",ios::binary);
if(!infile)
{
cout<<"file could not be open !! press any
key..."; getch();
}return;
cout<<"\n\n\tall students result \n\n";
cout<<"==================================
=======================================
=======";
cout<<"|R.No\t|Name\t\t|Phy\t|Che\t|Mat\t|Eng\t|CS\t|%
age\t|Grade"<<endl;
Page | 22
cout<<"==================================
=======================================
=======";
while(infile.read((char*)&st, sizeof(student)))
{
st.show_tabular();
}
cout<<"==================================
=======================================
=======\n";
getch();
infile.close();
}
void{result()
char ch;
int rno;
Page | 23
cout<<"\n\n\tresult menu";
cout<<"\n\n\t1. class result";
cout<<"\n\n\t2. student report
card"; cout<<"\n\n\t3. back to
main menu"; cout<<"\n\n\tenter
your choice(1-3).."; cin>>ch;
switch(ch)
{
case '1': class_result();
break;
case '2': cout<<"\n\n\tenter rollno of
student: "; cin>>rno;
display_sp(rno);
break;
case '3': break;
default: cout<<"\a";
}
}
void intro()
{
Page | 24
cout<<" COMPUTER SCIENCE
INVESTIGATORY PROJECT";
getch(); }
void entry_menu()
{
char ch;
int num;
break;
case '2': display_all();
break;
case '3': cout<<"\\n\tplease enter the
roll no"; cin>>num;
display_sp(num);
break;
case '4': cout<<"\n\n\tplease enter the roll no";
cin>>num;
modify_student(num);
break;
case '5': cout<<"\n\n\tplease enter the roll no";
Page | 26
cin>>num;
delete_student(num);
break;
case '6': break;
dafault: cout<<"\a";
entry_menu();
}
}
Page | 27
SCREENSHOTS
Page | 28
Page | 29
Page | 30
Page | 31
Page | 32
Page | 33
BIBLIOGRAPHY
Getting started with C++ by Sumita Arora
www.slideshare.com
en.wikipedia.org
www.google.com
www.icbse.in
Page | 34