here is my program. now i want to add file handling in it.
Code:
// Programmed By Mohsan Hassan
// 219-FAS/BSSE/F05
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<string.h>
#include<dos.h>
#include<process.h>
#include<iostream.h>
#define SIZE 3
struct student{
char no[10];
char name[30];
char f_name[30];
char dob[20];
char prg[30];
int mks[6];
};
student std_db[SIZE];
// User Defined Functions
void menu();
void create();
void add();
void search();
void update();
void deletee();
void report();
void report_ind();
void report_full();
int i=0,cdb=0;
void main()
{
clrscr();
menu();
getch();
}
// To Display Main Menu
void menu()
{
clrscr();
int x=5,y=1;
int ch;
gotoxy(25,y);
cout <<"Student Information System";
gotoxy(x,y+=3);
cout << "1 - Create Data Base";
gotoxy(x,y+=3);
cout << "2 - Add New Record";
gotoxy(x,y+=3);
cout << "3 - Search Record";
gotoxy(x,y+=3);
cout << "4 - Update Record";
gotoxy(x,y+=3);
cout << "5 - Delete Record";
gotoxy(x,y+=3);
cout << "6 - Report";
gotoxy(x,y+=3);
cout << "7 - Exit";
cout <<"\n\nChoose Your Choice:";
cin >> ch;
switch(ch)
{
case 1:
{
create();
break;
}
case 2:
{
add();
break;
}
case 3:
{
search();
break;
}
case 4:
{
update();
break;
}
case 5:
{
deletee();
break;
}
case 6:
{
report();
break;
}
case 7:
{
// char *aut="Programmed By Mohsan Hassan 219-FAS/BSSE/F05";
// for(int t=0;t<(strlen(aut));t++)
// {
// cout << aut[t];
// delay(100);
// }
getch();
exit(0);
break;
}
default:
{
menu();
break;
}
}
}
// To Create New Data Base
void create()
{
if(cdb==1)
{
clrscr();
cout << "\n\nData Base is already created";
getch();
menu();
}
int n=1;
char em='y';
clrscr();
while(em=='y' || em=='\r')
{
if(i>=SIZE) // to check array max length
{
clrscr();
cout << "\n\nMemory Full";
getch();
menu();
}
clrscr();
cout << "\nEnter Student Number:";
cin >> std_db[i].no;
cout << "Enter Student Name:";
gets(std_db[i].name);
cout << "Enter Father Name:";
gets(std_db[i].f_name);
cout << "Enter Date of Birth(ddmmyy):";
gets(std_db[i].dob);
cout << "Enter Programme:";
gets(std_db[i].prg);
for(n=0;n<6;n++)
{
cout << "\nEnter Marks in Subject " << n+1<<":";
cin >> std_db[i].mks[n];
}
i++;
cout <<"\nAdd More(y/n):";
em=getche();
}
cdb=1;
getch();
menu();
}
// To Add new record
void add()
{
if(i>=SIZE) // to check array max length
{
clrscr();
cout << "\n\nMemory Full";
getch();
menu();
}
clrscr();
cout << "\nEnter Student Number:";
cin >> std_db[i].no;
cout << "Enter Student Name:";
gets(std_db[i].name);
cout << "Enter Father Name:";
gets(std_db[i].f_name);
cout << "Enter Date of Birth(ddmmyy):";
gets(std_db[i].dob);
cout << "Enter Programme:";
gets(std_db[i].prg);
for(int n=0;n<6;n++)
{
cout << "\nEnter Marks in Subject " << n+1<<": ";
cin >> std_db[i].mks[n];
}
i++;
cout << "\n\nRecord Added Successfully";
getch();
menu();
}
// To search any record
void search()
{
clrscr();
char no[10];
int tmp=0;
cout << "Enter Student Number:";
cin >> no;
clrscr();
for(int j=0;j<=i;j++)
{
tmp=strcmp(no,std_db[j].no);
if(tmp==0)
break;
}
if(tmp==0)
{
cout << "\nStudent Number:\t\t"<<std_db[j].no<<endl<<endl;
cout << "Student Name:\t\t"<<std_db[j].name<<endl<<endl;
cout << "Father Number:\t\t"<<std_db[j].f_name<<endl<<endl;
cout << "Date of Birth:\t\t"<<std_db[j].dob<<endl<<endl;
cout << "Program:\t\t"<<std_db[j].prg<<endl<<endl;
for(int k=0;k<6;k++)
cout << "Marks in Subject:"<<k+1<<"\t\t"<<std_db[j].mks[k]<<endl<<endl;
getch();
}
else
{
cout << "\n\nRecord Not Found";
getch();
}
menu();
}
// To update any record
void update()
{
char no[10];
int tmp=0;
clrscr();
cout << "Enter Student Number:";
cin >> no;
clrscr();
for(int j=0;j<=i;j++)
{
tmp=strcmp(no,std_db[j].no);
if(tmp==0)
break;
}
if(tmp==0)
{
cout << "\nPlease Update record\n\n";
cout << "Enter Student Name:";
gets(std_db[j].name);
cout << "Enter Father Name:";
gets(std_db[j].f_name);
cout << "Enter Date of Birth:";
gets(std_db[j].dob);
cout << "Enter Programme:";
gets(std_db[j].prg);
for(int n=0;n<6;n++)
{
cout << "\nEnter Marks in Subject "<<n+1<<": ";
cin >> std_db[j].mks[n];
}
cout << "\n\nRecord Updated Successfully";
getch();
}
else
{
cout << "\n\nRecord Not Found";
getch();
}
menu();
}
// To delete any record
void deletee()
{
char no[10];
int tmp=0;
clrscr();
cout << "Enter Student Number:";
cin >> no;
clrscr();
for(int j=0;j<=i;j++)
{
tmp=strcmp(no,std_db[j].no);
if(tmp==0)
break;
}
if(tmp==0)
{
for(int z=j;z<i;z++)
{
std_db[z]=std_db[z+1]; // to copy next element of arrayed structure to previous one
}
i-=1;
cout << "\n\nRecord Deleted";
getch();
}
else
{
cout << "\n\nRecord Not Found";
getch();
}
menu();
}
// to display report of any record
void report()
{
int ch;
clrscr();
cout << "\t\t1 - Individual Report\n\n\n";
cout << "\t\t2 - Full Report\n\n";
cout << "Enter Your Choice:";
cin >> ch;
switch(ch)
{
case 1:
{
report_ind();
break;
}
case 2:
{
report_full();
break;
}
}
menu();
}
// to display individual record
void report_ind()
{
clrscr();
for(int j=0;j<i;j++)
{
clrscr();
cout << "\nStudent Number:\t\t"<<std_db[j].no<<endl<<endl;
cout << "Student Name:\t\t"<<std_db[j].name<<endl<<endl;
cout << "Father Number:\t\t"<<std_db[j].f_name<<endl<<endl;
cout << "Date of Birth:\t\t"<<std_db[j].dob<<endl<<endl;
cout << "Program:\t\t"<<std_db[j].prg<<endl<<endl;
for(int k=0;k<6;k++)
cout << "Marks in Subject:"<<k+1<<"\t\t"<<std_db[j].mks[k]<<endl<<endl;
cout << "\nPress Any Key To View Next Record";
getch();
}
}
// to display report of full record
void report_full()
{
int y=4;
int x=40;
clrscr();
for(int j=0;j<80;j++)
cout << "-";
cout << "No Name Father DOB Program Sub 1 Sub 2 Sub 3 Sub 4 Sub 5 Sub 6\n";
for(j=0;j<80;j++)
cout << "-";
for(j=0;j<i;j++)
{
x=40;
gotoxy(1,y);
cout << std_db[j].no;
gotoxy(5,y);
cout << std_db[j].name;
gotoxy(12,y);
cout << std_db[j].f_name;
gotoxy(21,y);
cout << std_db[j].dob;
gotoxy(31,y);
cout << std_db[j].prg;
for(int k=0;k<6;k++)
{
gotoxy(x,y);
cout <<std_db[j].mks[k];
x+=7;
}
y++;
// To control Screen Limit
if(y==10)
{
cout << "\nPress Any Key to Continue";
getch();
y=4;
clrscr();
for(int j=0;j<80;j++)
cout << "-";
cout << "No Name Father DOB Program Sub 1 Sub 2 Sub 3 Sub 4 Sub 5 Sub 6\n";
for(j=0;j<80;j++)
cout << "-";
}
}
getch();
}