You are on page 1of 34

ABOUT C++

The C++ programming language was developed at


AT&T Bell laboratories in the early 1980s by Bjarne
Stroustrup. He found out C lacking for stimulating
and decide to extend the language by adding
features. Bjarne Stroustrup called it C with classes
originally. The name C++ was coined by Rick
Mascitti where ++ is the C increment operator.
Ever since its birth, C++ evolved to cope with
problems encountered by users, and through
discussions at AT&T. The major reason for its success
is the support for Object Oriented Programming
(OOP), which is most near to real world situations.
ABOUT THE PROJECT
This is a program based on student reports. This
program helps us to do the basic operations done in
binary files i.e.
Create
Append
Search
Modify, and
Delete

student details. This also uses OOP features like data


abstraction and encapsulation which is implemented
by the creation of object, based on a class (here
student). In this program, student records mainly
constitute the following data:Roll no: of the student
Name
Marks (out of 100) scored by the student in
Physics, Chemistry, Maths, English, and
Computer Science.
Percentage
Grade
This program mainly works under three menus:Main menu: This menu helps us to go to result
menu or entry menu as per the entered choice.
Result menu: This menu displays the class result,
student result according to the choice given by
the user.
Entry menu: This menu helps us to create,
display, search, modify and delete student
records according to the choice entered by the
user.
This program also facilitate us to get back to the
main menu whenever required and also helps us to
exit the program. These functions are controlled by
the different menus.

HARDWARE SPECIFICATIONS OF THE


MACHINE USED
1.Keyboard-101 buttons
2.Monitor
3.CPU
4.Printer-Inkjet
5.Mouse-three button mouse

MINIMUM REQUIREMENT
1.Personal Computer(PC)
2.128 MB RAM
3.Windows 7 Operating System
4.Microsoft Disk Operating System(MS DOS)
5.Turbo C++3.0
6.CD
7.CD Drive

//program code
//header files used
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<stdio.h>
#include<fstream.h>
#include<iomanip.h>
//class definition
class student
{
int rollno; //to store rollno:ofstudent
char name[50]; //to store name of student
int p_marks,c_marks,m_marks,e_marks,cs_marks; //to store marks
//of diff subjects

float per; //to store percentage


char grade; //to store grade

void calculate() //to calculate percentage and assign grade


{
per=(p_marks+c_marks+m_marks+e_marks+cs_marks)/5.0;
if(per>=90)
grade='A';
else
if(per<90&&per>75)
grade='B';
else
if(per<75&&per>=60)
grade='C';
else
if(per<60&&per>=40)
grade='D';
else
grade='E';
}
public:

void getdata() //to input all data members

{
cout<<"\nRoll no:";
cin>>rollno;
cout<<"Name:";
gets(name);
cout<<"Physics out of 100:";
cin>>p_marks;
cout<<"Chemistry out of 100:";
cin>>c_marks;
cout<<"Maths out of 100:";
cin>>m_marks;
cout<<"English out of 100:";
cin>>e_marks;
cout<<"Computer science out of 100:";
cin>>cs_marks;
calculate();
}
void showdata() //to display all details
{

cout<<"\nRollno:"<<rollno;
cout<<"\nName:"<<name;
cout<<"\nMarks";
cout<<"\n Physics:"<<p_marks;
cout<<"

Chemistry:"<<c_marks;

cout<<"

Maths:"<<m_marks;

cout<<"

English:"<<e_marks;

cout<<"

Computer Science:"<<cs_marks;

cout<<"\nPercentage:"<<setprecision(3)<<per;
cout<<" Grade:"<<grade;
}

void show_tabular() //to display details in tabular form


{
cout<<rollno<<"

"<<name<<"

"<<p_marks<<"

"<<m_marks;
cout<<"

"<<e_marks<<"

"<<setprecision(3)<<per<<"

"<<cs_marks<<"
"<<grade<<"\n";

int ret_rollno() //to return rollno

"<<c_marks<<"

{
return rollno;
}};
//global declaration of variables
fstream fp;
student st;

//function definition to create and append student details


void write_student()
{
fp.open("Student.dat",ios::binary|ios::app|ios::out);
char ans;
do
{
st.getdata();
fp.write((char*)&st,sizeof(st));
cout<<"Do you want to continue(Y/N):";
cin>>ans;}while(ans=='Y'||ans=='y');
fp.close();
cout<<"\nStudent record created";
}

//function definition to display details of all students


void display_all()
{
clrscr();
cout<<"

DISPLAY ALL RECORDS";

fp.open("Student.dat",ios::binary|ios::in);
while(fp.read((char*)&st,sizeof(st)))
{
st.showdata();
cout<<"\n------------------------------------------;
cout<<------------------\n";
}
fp.close();
}

//function definition to search for a particular student record


void search_student()
{
int flag=0,n;
fp.open("Student.dat",ios::binary|ios::in);
cout<<"\nEnter the roll no:to be searched for:";
cin>>n;

while(fp.read((char*)&st,sizeof(st)))
{
if(st.ret_rollno()==n)
{
clrscr();
st.showdata();
flag=1;break;
}}
fp.close();
if(flag==0)
cout<<"\nRecord not present";
}

//function definition to modify student details


void modify_student()
{
int no,found=0;
clrscr();
cout<<"\n

TO MODIFY";

cout<<"\nEnter the rollno:to be modified:";


cin>>no;
fp.open("Student.dat",ios::binary|ios::in|ios::out);

while(fp.read((char*)&st,sizeof(st))&&found==0)
{
if(st.ret_rollno()==no)

{
st.showdata();
cout<<"\nPlease enter the new details of the student";
st.getdata();
int pos=-1*sizeof(st);
fp.seekp(pos,ios::cur);
fp.write((char*)&st,sizeof(st));
cout<<"\nRecord updated";
found=1;break;
}}
fp.close();
if(found==0)
cout<<"\nRecord not found";
}

//function definition to delete student record


void delete_student()
{

clrscr();
int no;
student st;
cout<<"\n

DELETE RECORD";

cout<<"\nEnter rollno:of student to be deleted:";


cin>>no;
fp.open("Student.dat",ios::binary|ios::in);
ofstream fout("temp.dat",ios::binary);
while(fp.read((char*)&st,sizeof(st)))
{
if(st.ret_rollno()!=no)
fout.write((char*)&st,sizeof(st));
}
fp.close();
fout.close();
remove("Student.dat");
rename("temp.dat","Student.dat");
cout<<"\nRecord deleted";
}

//function definition to display class result


void class_result()

{
clrscr();
fp.open("Student.dat",ios::binary|ios::in);
if(!fp)
{
cout<<"\nERROR!!!FILE COULD NOT BE OPEN\n";
cout<<"\nGO TO ENTRY MENU TO CREATE FILE";
cout<<"\nPROGRAM CLOSING....";
exit(0);
}
cout<<"\n\n

STUDENT RESULT\n";

cout<<"-----------------------------------------------;
cout<<---------------------\n";
cout<<"Rollno

Name

Phy Chem Maths Eng Comp %age

Grade";
cout<<"\n---------------------------------------------;
cout<<----------------------\n";
while(fp.read((char*)&st,sizeof(st)))
{
st.show_tabular();
}
fp.close();

//function definition for result menu


void result()
{
clrscr();
int ans;
char ch;
cout<<"********RESULT MENU********";
cout<<"\n1.Class Result";
cout<<"\n2.Student Report card";
cout<<"\n3.Back to main menu";
cout<<"\nEnter your choice(1-3):";
cin>>ans;
switch(ans)
{
case 1:class_result();
break;
case 2:do
{clrscr();
search_student();

cout<<"\nDo you want to search for any more result(Y/N)?:";


cin>>ch;}while(ch=='Y'||ch=='y');
break;
case 3:break;
}
}

//function definition for entry/edit menu


void entry_menu()
{
clrscr();
int ch2;
cout<<"\n********ENTRY MENU********";
cout<<"\n1.Create student record";
cout<<"\n2.Display all student records";
cout<<"\n3.Search student record";
cout<<"\n4.Modify student record";
cout<<"\n5.Delete student record";
cout<<"\n6.Back to main menu";
cout<<"\nEnter your choice(1-6):";
cin>>ch2;
switch(ch2)

{
case 1:write_student();break;
case 2:display_all();break;
case 3:search_student();break;
case 4:modify_student();break;
case 5:delete_student();break;
case 6:break;
}
}

//main program
void main()
{
clrscr();
int ch;
do
{
cout<<"\n********MAIN MENU********";
cout<<"\n1.Result Menu";
cout<<"\n2.Entry/Edit Menu";
cout<<"\n3.Exit";
cout<<"\nSelect your choice(1-3):";

cin>>ch;
switch(ch)
{
case 1:result();
break;
case 2:entry_menu();break;
case 3:exit(0);
}
}while(ch!=3);
getch();
}
//program ends
//*******END OF PROJECT**********

MAIN MENU SCREEN

ENTRY MENU-CREATION AND


APPENDING OF RECORDS

DISPLAYING ALL RECORDS

RESULT MENU

CLASS RESULT

STUDENT REPORT CARD

SEARCHING A PARTICULAR
RECORD

MODIFYING A RECORD

DELETING A PARTICULAR
RECORD

ENTERING BACK TO MAIN MENU

CLASS RESULT

STUDENT REPORT CARD

*******EXIT FROM
PROGRAM*******

This program is mainly


designed so as to input details of the student such
as roll no, name and marks of 5 subjects and to
function the basic operations done in binary files:
search, append, delete, and modify. This program
also displays the student progress card and also the
class result including their percentage and grade.
But this program allows us to
input a limited number of entities like roll no, name,

and marks. This program can be made more efficient


by introducing new menus and by including more
entities so as to store complete details of the
student which will be useful in the near future.

www.google.com
Computer Science with C++ class
XII by Sumita Arora

You might also like