C++ Project
C++ Project
Computer Science
Project Report
CERTIFICATE
ACKNOWLEDGEMENT
KUSH BHAGAT
3
Computer Science
Project Report
CONTENTS
Page No.
• INTRODUCTION 4
• DISCUSSION 5
• SOURCE CODE 8
• OUTPUT SCREENS 32
• BIBLOGRAPHY 39
4
Computer Science
Project Report
INTRODUCTION
• Name
• Course
• Stream
• Roll number
• Father’s name
• Mother’s name
• Address
• Bus number
• Enrolment number (Auto Generated)
DISSCUSION
S CHOOL S TUDENT’S
D ATABASE
8
Computer Science
Project Report
SOURCE CODE
# include <string.h>
# include <conio.h>
# include <stdlib.h>
# include <stdio.h>
# include <dos.h>
# include <time.h>
# include <math.h>
# include <fstream.h>
# include <ctype.h>
void check();
void backup();
void del_db();
void pass();
void enter_data();
void view_personal();
void match_name();
void match_enrol();
void edit_data();
void del();
void help();
void time_norm();
void time_main();
void desktop();
void main();
struct student_inf
{
char stu_name[30],
clas[5] ,
course[5],stream[5],
9
Computer Science
Project Report
batch[5],
fat_name[30] , mot_name[30],
roll_no[8],
add[50] , pho_no[20];
int enrol_no;
} struc_info;
class student_info
{
public:
void getdata()
{
textcolor(15);
cprintf("Student's Name: "); gets (struc_info.stu_name);
cprintf("Class: "); gets (struc_info.clas);
cprintf("Course: "); gets (struc_info.course);
cprintf("Stream: "); gets (struc_info.stream);
cprintf("Father's Name: "); gets (struc_info.fat_name);
cprintf("Mother's Name: "); gets (struc_info.mot_name);
cprintf("Roll No.: "); gets (struc_info.roll_no);
cprintf("Address: "); gets (struc_info.add);
cprintf("Ph.No.: "); gets (struc_info.pho_no);
struc_info.enrol_no=::enrol;
}
void display()
{
textcolor(15);
cprintf("Student's Name: "); puts (struc_info.stu_name);
cprintf("Class: "); puts (struc_info.clas);
cprintf("Course: "); puts (struc_info.course);
cprintf("Stream.: "); puts (struc_info.stream);
cprintf("Enrol.No.: "); cout<<(struc_info.enrol_no);
cprintf("Father's Name: "); puts (struc_info.fat_name);
cprintf("Mother's Name: "); puts (struc_info.mot_name);
cprintf("Roll No.: "); puts (struc_info.roll_no);
cprintf("Address: "); puts (struc_info.add);
cprintf("Ph.No.: "); puts (struc_info.pho_no);
}
void displayg()
{
textcolor(15);
cprintf("Student's Name: "); puts (struc_info.stu_name);
10
Computer Science
Project Report
void edit_data()
{
textcolor(15);
cprintf("Student's Name: "); puts (struc_info.stu_name);
cprintf("Class: "); gets (struc_info.clas);
cprintf("Course: "); gets (struc_info.course);
struc_info.enrol_no=::enrol;
}
} io_data;
class student_ginfo
{
int enrol_no;
char choice;
public:
void getdata()
{
textcolor(15);
char nam_enrol;
gotoxy(4,22);
cprintf("Search according to (n)ame or Enr(o)llment No.: ");
nam_enrol=getche();nam_enrol=tolower(nam_enrol);
11
Computer Science
Project Report
if(nam_enrol=='n')
{
cout<<"."; delay(400); cout<<"."; delay(400); cout<<"."; delay(400);
match_name();
}
else if(nam_enrol=='o')
{
cout<<"."; delay(400); cout<<"."; delay(400); cout<<"."; delay(400);
match_enrol();
}
else
{
gotoxy(64,25);
cout<<"INVALID INPUT"<<"."; delay(400); cout<<"."; delay(400);
cout<<".";
delay(400);
main();
}
cout<<"Press 'y' to view the students personal information: "<<endl
<<"WARNING: THIS INFO IS OLNY FOR THE STAFF: ";
choice=getche();
if((choice=='y')||(choice=='Y'))
{
cout<<"."; delay(400); cout<<"."; delay(400); cout<<"."; delay(400);
cout<<endl;
pass();
if(::ctr_pas>0)
{ view_personal(); }
}
else
{
gotoxy(44,12);
cout<<"."; delay(400); cout<<"."; delay(400); cout<<"."; delay(400);
main();
}
}
} view_info;
void check()
{
ifstream check;
check.open("database.vbps",ios::beg|ios::binary);
if(check==NULL)
{
clrscr();
12
Computer Science
Project Report
time_norm();
textcolor(15);
gotoxy(1,4);
cprintf("Database does not exist. Press any key to go back to main.");getch();
check.close();
main();
}
check.close();
}
void backup()
{
fstream file("database.vbps",ios::in|ios::binary);
if(file!=NULL)
{
fstream file2("newbackup.vbps",ios::out|ios::binary);
while(file.read((char*)& struc_info,sizeof(student_inf)))
{ file2.write((char*)& struc_info,sizeof(student_inf)); }
file.close();
file2.close();
remove("backup.vbps");
rename("newbackup.vbps","backup.vbps");
}
remove("database.vbps");
cout<<"DO YOU WANT TO DELETE BACK UP FILE ALSO. PRESS
ENTER TO DO SO.\n";
ch=getch();
if(int(ch)==13)
{
remove("backup.vbps");
}
}
else
{
cout<<"INVALID INPUT! PLEASE TRY AGAIN!"<<endl;
}
}
void pass()
{
textcolor(15);
::ctr_pas=0;
int c_pas=0;
char stringo[4] , stringg[4];
stringo[0]='V'; stringo[1]='B'; stringo[2]='P'; stringo[3]='S';
for (int i=1;i<=3;i++)
{
c_pas=0;
cout<<"Enter Pin: ";
for(int y=0;y<=3;y++)
{ stringg[y]=getch(); cout<<"*"; }
cout<<endl;
for(int s=0;s<=3;s++)
{
if(stringg[s]==stringo[s])
{ c_pas++; }
}
if (c_pas==4)
{ ::ctr_pas++; break; }
else
{ cout<<"INVALID PIN! Make sure caps lock is ON.\n "<<endl; }
}
if (::ctr_pas<1)
{ delay(1000); main(); }
clrscr();
time_norm();
gotoxy(1,5);
}
14
Computer Science
Project Report
void enter_data()
{
::ctr_pas=0;
textcolor(15);
char ans;
int a=0;
fstream count;
count.open("database.vbps",ios::in|ios::binary|ios::beg);
while(count.read((char*)& struc_info,sizeof(student_inf)))
{ a=(struc_info.enrol_no); }
count.close();
gotoxy(1,5);
cout<<"Enter Data(y/n): "; ans=getche();
cout<<endl<<endl;
if((ans=='y')||(ans=='Y'))
{
fstream file;
file.open("database.vbps",ios::binary|ios::app);
file.seekg(0,ios::end);
if (a==0)
{
cout<<"FIRST RECORD!\n"; ::enrol=1;
cout<<"ENROLLMENT GRANTED! YOUR ENROLLMENT NO. IS:
"<<::enrol<<"\n";
io_data.getdata();
file.write((char*)& struc_info,sizeof(student_inf));
file.close();
}
else
{
::enrol=a+1;
cout<<"ENROLLMENT GRANTED! YOUR ENROLLMENT NO. IS:
"<<::enrol<<"\n";
io_data.getdata();
file.write((char*)& struc_info,sizeof(student_inf));
file.close();
}
}
else
{
cout<<"LOADING"<<"."; delay(400); cout<<"."; delay(400); cout<<".";
delay(400);
15
Computer Science
Project Report
main();
}
}
void view_personal()
{
textcolor(15);
::ctr_pas=0;
ifstream file;
file.open("database.vbps",ios::beg||ios::binary);
file.read((char*)& struc_info,sizeof(student_inf));
int enrol;
cout<<"Enter Enrollment No.: "; cin>>enrol;
cout<<endl;
int ptr , ctr_match=0;
while(!file.eof())
{
ptr=(struc_info.enrol_no/enrol);
if (ptr==1)
{
ctr_match++;
io_data.display();
cout<<endl;
break;
}
file.read((char*)& struc_info,sizeof(student_inf));
}
file.close();
if (ctr_match==0)
{
cout<<"No match"
<<"."; delay(400); cout<<"."; delay(400); cout<<"."; delay(400); main();
}
else
{
cout<<"Press any key to go back to main menu. ";int ch;
do{ ch=getch(); } while(ch!=13);
main();
}
}
void match_name()
{
clrscr();
textcolor(15);
16
Computer Science
Project Report
time_norm();
ifstream file;
file.open("database.vbps",ios::beg||ios::binary);
file.read((char*)& struc_info,sizeof(student_inf));
char name[30];
gotoxy(1,4); cout<<"Enter Name: "; cin>>name;
int ptr , ctr=0;
while(!file.eof())
{
ptr=strcmpi(name,struc_info.stu_name);
if (ptr==0)
{
ctr++;
cout<<ctr<<". ";
io_data.displayg();
cout<<endl;
getch();
}
file.read((char*)& struc_info,sizeof(student_inf));
}
if (ctr==0)
{
cout<<"No Match"
<<"."; delay(400); cout<<"."; delay(400); cout<<"."; delay(400); main();
}
file.close();
}
void match_enrol()
{
textcolor(15);
clrscr();
time_norm();
ifstream file;
file.open("database.vbps",ios::beg||ios::binary);
file.read((char*)& struc_info,sizeof(student_inf));
int enrol , ctr=0;
gotoxy(1,4); cout<<"Enter Enrollment No.: "; cin>>enrol;
file.seekg(0,ios::beg);
while(!file.eof())
{
if (struc_info.enrol_no==enrol)
{
ctr++;
17
Computer Science
Project Report
cout<<ctr<<". ";
io_data.displayg();
cout<<endl;
break;
}
file.read((char*)& struc_info,sizeof(student_inf));
}
if (ctr==0)
{
cout<<"No Match"<<"."; delay(400); cout<<"."; delay(400); cout<<".";
delay(400);
main();
}
file.close();
}
void edit_data()
{
textcolor(15);
fstream file;
file.open("database.vbps",ios::in|ios::out|ios::beg|ios::binary|ios::ate);
file.seekg(0,ios::beg);
file.read((char*)& struc_info,sizeof(student_inf));
int enrol , ctr=0 , x;
cout<<"Enrollment No.:: ";cin>>enrol;cout<<endl;
while(!file.eof())
{
if (struc_info.enrol_no==enrol)
{ ctr++; x=file.tellg()-sizeof(student_inf); break; }
file.read((char*)& struc_info,sizeof(student_inf));
}
if (ctr==0)
{
cout<<"No Match"<<"."; delay(400); cout<<"."; delay(400); cout<<".";
delay(400);
main();
}
puts("Current details are: ");cout<<endl;
io_data.display();cout<<endl;
puts("Do you want to continue(y/n): ");cout<<endl;
char choice=getch(); choice=tolower(choice);
if(choice=='y')
{
::enrol=enrol;
io_data.edit_data();
file.seekg(x,ios::beg);
18
Computer Science
Project Report
file.write((char*)& struc_info,sizeof(student_inf));
file.close();
}
else
{ file.close(); }
}
void del()
{
textcolor(15);
clrscr();
time_norm();
int enrol;
gotoxy(1,5);
cout<<"Enter Enrollment No.:";cin>>enrol;
int check=0;
fstream file("database.vbps",ios::in|ios::binary);
if(file==NULL)
{
cout<<"File does not exist. Press any key to go back to main.";getch();
main();
}
fstream file2("temp.vbps",ios::out|ios::binary);
char ch;
cout<<"Are you sure you want to delete Enrollment No. "<<enrol<<" (y/n): ";
ch=getche();ch=tolower(ch);cout<<endl;
if(ch=='y')
{
while(file.read((char*)& struc_info,sizeof(student_inf)))
{
if (enrol!=struc_info.enrol_no)
{ file2.write((char*)& struc_info,sizeof(student_inf)); }
else
{
io_data.display();
char che;
do
{
cout<<endl;
cout<<"Are you sure you want to delete Enrollment No. "<<enrol<<"
(y/n): ";
che=getche();che=tolower(che);cout<<endl;
if (che=='y')
{ check=1; break; }
else
19
Computer Science
Project Report
{
file2.write((char*)& struc_info,sizeof(student_inf));
file.close();
file2.close();
main();
break;
}
}while(che!='y');
}
}
if (check==0)
{
cout<<"Enrollment No. does not exist. Press any key to go back to main.";
getch();
main();
}
else
{
cout<<endl<<"\nDeleted. Press any key to go back to main.";getch();
file.close();
file2.close();
remove("database.vbps");
rename("temp.vbps","database.vbps");
main();
}
getch();
}
else
{
file.close();
file2.close();
main();
}
}
void help()
{
for (int s=1;s<=3;s++)
{
start:
_setcursortype(_NOCURSOR);
textcolor(15);
clrscr();
gotoxy(19,1); textcolor(5); cprintf("|");
{ textcolor(4); cprintf("-"); }
textcolor(5); cprintf("|");
gotoxy(33,2); textcolor(14); cprintf("STUDENT DATABASE\n");
gotoxy(28,3); cprintf("VISHWA BHARTI PUBLIC
SCHOOL\n");
gotoxy(32,4); cprintf("SECTOR-28 NOIDA\n");
gotoxy(33,5); cprintf("UTTAR PRADESH\n");
gotoxy(19,6); textcolor(5); cprintf("|");
for (x=1;x<46;x++)
{ textcolor(4); cprintf("-"); }
if(s==2)
{
gotoxy(60,23);
cout<<"PAGE "<<s<<" OF 3";
21
Computer Science
Project Report
if(s==3)
{
gotoxy(60,23);
cout<<"PAGE "<<s<<" OF 3";
gotoxy(3,12); cout<<"¯ This Program has been built completely in TURBO
C++ VER. 3.0";
gotoxy(3,14); cout<<" Author: KUSH BHAGAT";
gotoxy(3,15); cout<<" Dated : 23rd November 2009";
gotoxy(3,29); cout<<"Press any key to go back to Main..............";
getch();
}
}
cout<<endl<<endl<<" THANKS for using this program"<<"."; delay(400);
cout<<".";
delay(400); cout<<"!"; delay(800);
}
void time_norm()
{
textcolor(15);
int x;
gotoxy(1,2);
for (x=1;x<81;x++)
{ textcolor(6); cprintf("-"); }
time_t timer;
struct tm *tblock; //gets time of day
timer = time(NULL); //converts date/time to a structure
tblock = localtime(&timer);
gotoxy(22,1);
22
Computer Science
Project Report
textcolor(9);
cprintf("--------------------------------------\n");
gotoxy(23,2);
textcolor(15+128);
cprintf("Local time: %s",asctime(tblock));
gotoxy(22,3);
textcolor(9);
cprintf("--------------------------------------\n");
}
void time_main()
{
textcolor(15);
int x;
gotoxy(1,8);
for (x=1;x<81;x++)
{ textcolor(6); cprintf("-"); }
time_t timer;
struct tm *tblock; //gets time of day
timer = time(NULL); //converts date/time to a structure
tblock = localtime(&timer);
gotoxy(22,7);
textcolor(9);
cprintf("--------------------------------------\n");
gotoxy(23,8);
textcolor(15+128);
cprintf("Local time: %s",asctime(tblock));
gotoxy(22,9);
textcolor(9);
cprintf("--------------------------------------\n");
}
void desktop()
{
textcolor(15);
::desk++;
char starto[3],startg[3],ext[3];
textcolor(5); cprintf("|");
textcolor(14);
gotoxy(28,11); cprintf("VISHWA BHARATI PUBLIC SCHOOL\n");
gotoxy(33,12); cprintf("SECTOR-28 NOIDA \n");
gotoxy(34,13); cprintf("UTTAR PRADESH\n");
gotoxy(18,14); textcolor(5); cprintf("|");
for (x=1;x<46;x++)
{ textcolor(4); cprintf("-"); }
textcolor(5); cprintf("|");
time_norm();
gotoxy(33,7);
startg[0]=tolower(getch());
while ((startg[0]!='v')&&(startg[0]!='e'))
{ startg[0]=tolower(getch()); }
cout<<"WELCOME";
startg[1]=tolower(getch());
while ((startg[1]!='p')&&(startg[1]!='x'))
{ startg[1]=tolower(getch()); }
cout<<" TO ";
startg[2]=tolower(getch());
while ((startg[2]!='s')&&(startg[2]!='c'))
{ startg[2]=tolower(getch()); }
cout<<"VBPS!";
void main()
{
textcolor(15);
24
Computer Science
Project Report
backup();
if (::desk==0)
{ desktop(); }
clrscr();
start:
_setcursortype(_NOCURSOR);
textcolor(15);
clrscr();
gotoxy(19,1); textcolor(5); cprintf("|");
textcolor(5); cprintf("|");
gotoxy(33,2); textcolor(14); cprintf("STUDENT DATABASE\n");
gotoxy(28,3); cprintf("VISHWA BHARTI PUBLIC
SCHOOL\n");
gotoxy(33,4); cprintf("SECTOR-28, NOIDA\n");
gotoxy(34,5); cprintf("UTTAR PRADESH\n");
gotoxy(19,6); textcolor(5); cprintf("|");
for (x=1;x<46;x++)
{ textcolor(4); cprintf("-"); }
textcolor(15);
gotoxy(4,11); cprintf("Students Information");
gotoxy(4,12); cprintf("Add a new Student's Information");
gotoxy(4,13); cprintf("Edit existing Information");
gotoxy(4,14); cprintf("Delete Information");
gotoxy(4,15); cprintf("Delete Complete Information");
gotoxy(4,16); cprintf("Use Backup");
gotoxy(4,17); cprintf("Help");
gotoxy(4,18); cprintf("Desktop");
gotoxy(1,20); textcolor(5); cprintf("|");
for (x=1;x<79;x++)
{ textcolor(4); cprintf("-"); }
textcolor(5); cprintf("|");
int v , p=1 , y=11;
textcolor(3);
25
Computer Science
Project Report
for(int t=y;t<=y+7;t++)
{ gotoxy(1,t); cprintf("Ì"); }
textcolor(10+128);
gotoxy(2,y); cprintf("> "); //272
v=getch();
do
{
textcolor(10+128);
if ((y==18)&&(v==80)&&(p==8))
{
gotoxy(2,y); cout<<char(255);
p=1;
y=11;
gotoxy(2,y); cprintf("> ");
v=getch();
}
else if((y==11)&&(v==72)&&(p==1))
{
gotoxy(2,y); cout<<char(255);
p=8;
y=18;
gotoxy(2,y); cprintf("> ");
v=getch();
}
switch (v)
{
case 80:
{
gotoxy(2,y); cout<<char(255);
y++;
gotoxy(2,y); cprintf("> ");
p++;
break;
}
case 72:
{
gotoxy(2,y); cout<<char(255);
y--;
gotoxy(2,y); cprintf("> ");
p--;
break;
}
}
if(v!=13)
{ v=getch(); }
26
Computer Science
Project Report
}while(v!=13);
gotoxy(2,y); cout<<char(255);
switch(p)
{
case 1:
{
check();
textcolor(15);
view_info.getdata();
break;
}
case 2:
{
textcolor(15);
clrscr();
time_norm();
gotoxy(1,5);
pass();
if(::ctr_pas>0)
{ enter_data(); break; }
else
{
gotoxy(64,25);
cout<<"LOADING"<<"."; delay(400); cout<<"."; delay(400); cout<<".";
delay(400);
main();
}
break;
}
case 3:
{
check();
textcolor(15);
clrscr();
time_norm();
gotoxy(1,5);
pass();
if(::ctr_pas>0)
{ edit_data(); break; }
else
{
gotoxy(64,25);
27
Computer Science
Project Report
case 4:
{
textcolor(15);
clrscr();
time_norm();
gotoxy(1,5);
check();
pass();
if(::ctr_pas>0)
{
del();
break;
}
else
{
gotoxy(64,25);
cout<<"LOADING"<<"."; delay(400); cout<<"."; delay(400); cout<<".";
delay(400);
main();
}
break;
}
case 5:
{
char in;
textcolor(15);
clrscr();
time_norm();
gotoxy(1,5);
check();
cout<<"Are you sure you want to Delete Complete DB. Press enter if
yes.\n";
in=getch();
if (int(in)==13)
{
pass();
del_db();
28
Computer Science
Project Report
}
break;
}
case 6:
{
textcolor(15);
char q;
gotoxy(4,22);
cprintf("ARE YOU SURE YOU WANT TO UPDATE THE CURRENT DB
FROM BACKUP FILE (y/n)? ");
q=tolower(getche());
cout<<endl;
if (q=='y')
{
backup();
cprintf(" UPDATED! PRESS ANY KEY TO GET BACK TO MENU.");
getch();
}
else
{
cprintf(" PRESS ANY KEY TO GET BACK TO MENU. ");
getch();
}
break;
}
case 7:
{
textcolor(15);
help();
break;
}
case 8:
{
textcolor(15);
gotoxy(64,25);
cout<<"LOADING"<<"."; delay(400); cout<<"."; delay(400); cout<<".";
delay(400);
::desk=0;
main();
break;
}
}
backup();
goto start; }
29
Computer Science
Project Report
OUTPUT SCREENS
SCREEN 1: DESKTOP
------------------------------------------------
--------------------------------Local time: Mon Nov 23 11:10:35 2009--------------------------------
------------------------------------------------
WELCOME TO VBPS!
|-----------------------------------------------------------------------------------|
VISHWA BHARATI PUBLIC SCHOOL
SEC-28 NOIDA
UTTAR PRADESH
|-----------------------------------------------------------------------------------|
SCREEN 2: MENU
|-----------------------------------------------------------------------------------|
STUDENT DATABASE
VISHWA BHARATI PUBLIC SCHOOL
SEC-28 NOIDA
UTTAR PRADESH
|-----------------------------------------------------------------------------------|
-------------------------------------------------
----------------------------------Local time: Mon Nov 23 11:13:42 2009----------------------------------
-------------------------------------------------
|-------------------------------------------------------------------------------------------------------------------|
30
Computer Science
Project Report
╠ Students Information
╠ Add a new Student's Information
╠ Edit existing Information
╠ Delete Information
╠ Delete Complete Information
╠ Use Backup
╠ Help
╠ Desktop
|-------------------------------------------------------------------------------------------------------------------|
Are you sure you want to Delete Complete DB. Press enter if yes.
Enter Pin: ****
» To open an existing DB, select option SEARCH from the main menu.
You can searh the required students information either ny his/her
name or by Enrollment no. Basic information will be displayed.Personal
Information is password secured.
» You can delete the information with the DELETE option.
» Everytime you open, exit or use any option in the program,
a backup of the database is created with the updated data.
» This Program has been built completely in TURBO C++ VER. 3.0
PAGE 3 OF 3
36
Computer Science
Project Report
BIBLOGRAPHY