i make this project what i unable to use file handling

#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<fstream.h>
#include<ctype.h>
#include<bios.h>
#include<ctype.h>

int menu(int,char a[25],char b[25],char c[25],char d[25],char e[25],char sl1[2],char sl2[2],char title[40],char under[2]);
void lbyl(char a[50]);
void main_menu();
void student_menu();
void mark_menu();
int records=0;


void lbyl(char a[50])
{
int l,i;
l=strlen(a);
for (i=0;i<l;i++)
{
cout<<a[i];
}
}



struct s_date
{
int dd,mm,yyyy;
};

//DEFINING OF Stuctures
struct student
{
char address[30];
char fname[30];
long int redgno;
s_date dob;
char clas[5];
char name[20];
int sub1,sub2,sub3,sub4,sub5,total;
float avg,pre;
char div[10];
char st_code[10];
}s[10];

/****************************Function To Add Data***************************/
void add()
 {


 int i=0;
 char ch='y';
 char fn[20];
 fstream file;
 do
  {
  records++;
  ss:

  int st;
  int t_redg,mark;

  cout<<"\n\tStudents Data Collector";

  cout<<"\n\t=======================";

  cout<<"\n\tEnter The Following";

  cout<<"\n\tRegistaration No:";
  cin>>s[i].redgno;

  cout<<"\n\tName          :";
  gets(s[i].name);

  cout<<"\n\tAddress       :";
  gets(s[i].address);

  cout<<"\n\tFather's Name :";
  gets(s[i].fname);

  cout<<"\n\tClass         :";
  gets(s[i].clas);

  cout<<"\n\tDate Of Birth :DD MM YYYY";
  cin>>s[i].dob.dd>>s[i].dob.mm>>s[i].dob.yyyy;

  sa:
  cout<<"\n\tStudent Data Entry Form";

  cout<<"\n\t=======================";

  cout<<"\n\tEnter The Stream Code:\n\t1.Science Stream\n\t2.Commerce Streame";

  cin>>st;
  switch(st)
   {
   case 1:strcpy(s[i].st_code,"Science");
   break;
   case 2:strcpy(s[i].st_code,"Commerce");
   break;
   default:cout<<"\n\t\t\tInvalid Type.\n\nDo you want to continue?(Y/N)...";
       cin>>ch;
       if (ch=='y'||ch=='Y')
       {
        goto sa;
       }
       else add();
   }


  cout<<"\n\tStudent Data Entry Form";

  cout<<"\n\t=======================";

  cout<<"\n\tEnter The Following Marks";

  cout<<"\n\tSub1(Eng/Eng):";                                           //Sub 1

  cin>>s[i].sub1;

  cout<<"\n\tSub2(Math/A/C):";                                        //Sub 2

  cin>>s[i].sub2;

  cout<<"\n\tSub3(Phy/Eco):";                         //Sub 3

  cin>>s[i].sub3;

  cout<<"\n\tSub4(Chem/B.st):";                         //Sub 4

  cin>>s[i].sub4;
                                     //Sub 5
  cout<<"\n\tSub5(Bio/Comp):";

  cin>>s[i].sub5;
  s[i].total=s[i].sub1+s[i].sub2+s[i].sub3+s[i].sub4+s[i].sub5;
  if((s[i].sub1<33)||(s[i].sub2<33)||(s[i].sub3<33)||(s[i].sub4<33)||(s[i].sub5<33))
  strcpy(s[i].div,"Fail");
  else if(s[i].total>=375)
  strcpy(s[i].div,"Distintion");
  else if((s[i].total>=300)&&(s[i].total<375))
  strcpy(s[i].div,"First Class");
  else if((s[i].total>=250)&&(s[i].total<300))
  strcpy(s[i].div,"Second Class");
  else if(s[i].total<165)
  strcpy(s[i].div,"Fail");

  strcat(fn,s[i].name);
  strcat(fn,".txt");
  file.open(fn,ios::out);
   if(!file)
    {
    cout<<".";
    }
  file<<"                            Report Card Of "<<s[i].name
      <<"\nRegistration Number:"<<s[i].redgno<<"\nClass:"<<s[i].clas
      <<"\nAddress:"<<s[i].address<<"\nFather's Name:"<<s[i].fname
      <<"\nDate Of Birth:"<<s[i].dob.dd<<"-"<<s[i].dob.mm<<"-"<<s[i].dob.yyyy
      <<"\nStream:"<<s[i].st_code<<"\n\n\
-------------------------------------------------------------------------------\
    \nSubject Marks\n-------------\nSubject 1 :"
      <<s[i].sub1<<"\nSubject 2 :"<<s[i].sub2<<"\nSubject 3 :"<<s[i].sub3
      <<"\nSubject 4 :"<<s[i].sub4<<"\nSubject 5 :"<<s[i].sub5
      <<"\nTotal     :"<<s[i].total<<"\nGrade     :"<<s[i].div;
  file.close();

  i++;

  cout<<"\n\tWant More Record To Be Written?(Y/N)......";
  cin>>ch;
  }while(ch=='y'||ch=='Y');
  if(ch=='n'||ch=='N') student_menu();
 }

/******************************Function To Modify Marks**********************/
void mod()
 {
 int regno,flag=0,i;
 char ch;
 student te;

 cout<<"\n\n\tEnter The Reg No to be modified:";
 cin>>regno;
 for(i=0;i<10;i++)
  {
  if(s[i].redgno==regno)
   {
   flag=1;
   cout<<"\n\tSubject 1    :"<<s[i].sub1;
   cout<<"\n\tDo you want to change this?[y/n]";
   ch=getch();
   if(ch=='y')
    {
    cout<<"\n\tEnter New Value:";
    cin>>te.sub1;
    s[i].sub1=te.sub1;
    }
   cout<<"\n\tSubject  2  :"<<s[i].sub2;
   cout<<"\n\tDo you want to change this?[y/n]";
   ch=getch();
   if(ch=='y')
    {
    cout<<"\n\tEnter New Value:";
    cin>>te.sub2;
    s[i].sub2=te.sub2;
    }
   cout<<"\n\tSubject 3   :"<<s[i].sub3;
   cout<<"\n\tDo you want to change this?[y/n]";
   ch=getch();
   if(ch=='y')
    {
    cout<<"\n\tEnter New Value:";
    cin>>te.sub3;
    s[i].sub3=te.sub3;
    }
   cout<<"\n\tSubject 4   :"<<s[i].sub4;
   cout<<"\n\tDo you want to change this?[y/n]";
   ch=getch();
   if(ch=='y')
    {
    cout<<"\n\tEnter New Value:";
    cin>>te.sub4;
    s[i].sub4=te.sub4;
    }
   cout<<"\n\tSubject 5   :"<<s[i].sub5;
   cout<<"\n\tDo you want to change this?[y/n]";
   ch=getch();
   if(ch=='y')
    {
    cout<<"\n\tEnter New Value:";
    cin>>te.sub5;
    s[i].sub5=te.sub5;
    }
   }
  }
  if(flag==0) cout<<"\n\tInvalid Reg No!";
 }




/****************************Function To Make Menus**************************/
int menu(int num,char a[25],char b[25],char c[25],char d[25],char e[25],char sl1[2],char sl2[2],char title[40],char under[2])
{
char ch;
int key,x=4,sl=1,l,i;

l=strlen(title);

cout<<title;
cout<<"\n";

for(i=0;i<l;i++)
cout<<under;

    cout<<"\n\t"<<sl1<<a<<sl2;

    cout<<"\n\t "<<b;

    cout<<"\n\t "<<c;

    cout<<"\n\t "<<d;

    cout<<"\n\t "<<e;

cout<<"\n\tEnter Your Choice:1";
 key=bioskey(0);
while (key!=7181)
 {
 switch(key)
  {
  case 18432:                                   //UP
  l=strlen(title);

  cout<<title;
  cout<<"\n";

  for(i=0;i<l;i++)
  cout<<under;
        switch(x)
        {
        case 4: if (num==4) goto up4;
        else if (num==3) goto up3;
        else if (num==2) goto up2;

        cout<<"\n\t "<<a;

        cout<<"\n\t "<<b;

        cout<<"\n\t "<<c;

        cout<<"\n\t "<<d;

        cout<<sl1<<e<<sl2;

        cout<<"\n\tEnter Your Choice:5";sl=5;
        if (num==5) x=2;
        else x=1;
        break;
        case 2: up4:

        cout<<"\n\t "<<a;

        cout<<"\n\t "<<b;

        cout<<"\n\t "<<c;

        cout<<"\n\t"<<sl1<<d<<sl2;

        cout<<"\n\t "<<e;

        cout<<"\n\tEnter Your Choice:4";sl=4;
        if (num==5) x=3;
        else if (num==4) x=3;
        else x=1;
        break;
        case 3: up3:

        cout<<"\n\t "<<a;

        cout<<"\n\t "<<b;

        cout<<sl1<<c<<sl2;

        cout<<"\n\t "<<d;

        cout<<"\n\t "<<e<<" ";

        cout<<"\n\tEnter Your Choice:3";sl=3;
        x=1;
        break;
        case 1: up2:

        cout<<"\n\t "<<a;

        cout<<"\n\t"<<sl1<<b<<sl2;

        cout<<"\n\t "<<c;

        cout<<"\n\t "<<d;

        cout<<"\n\t "<<e;

        cout<<"\n\tEnter Your Choice:2";sl=2;
        if (num==5) x=5;
        else if (num==2) x=5;
        else x=5;
        break;
        case 5:
            cout<<"\n\t"<<sl1<<a<<sl2;

        cout<<"\n\t "<<b;

        cout<<"\n\t "<<c;

        cout<<"\n\t "<<d;

        cout<<"\n\t "<<e;

        cout<<"\n\tEnter Your Choice:1";sl=1;
        if (num==5) x=4;
        else if (num==2) x=1;
        else if (num==3) x=3;
        else if (num==4) x=2;
        break;
        default:cout<<"\n\tWrong!!2"<<x;
        getch();
        exit(0);
        }
        break;
  case 20480:
    clrscr();                //DOWN
    l=strlen(title);

     cout<<"\n\t"<<title;
  cout<<"\n";

  for(i=0;i<l;i++)
  cout<<under;
        switch(x)
        {
        case 1:
        cout<<" "<<a<<"\n"
        <<" "<<b<<"\n"
        <<" "<<c<<" \n"
        <<" "<<d<<" \n"
        <<sl1<<e<<sl2;

        cout<<"\n\tEnter Your Choice:5";sl=5;
        x=5;
        break;
        case 2:
        cout<<" "<<a<<"\n"
        <<" "<<b<<"\n"
        <<" "<<c<<" \n"
        <<sl1<<d<<sl2
        <<"\n "<<e<<" \n";

        cout<<"\n\tEnter Your Choice:4";sl=4;
        if (num==4) x=5;
        else x=1;
        break;
        case 3:
        cout<<"\t "<<a<<"\n"
        <<"\t "<<b<<"\n\t"
        <<sl1<<c<<sl2
        <<"\n\t "<<d<<" \n"
        <<"\t "<<e<<"\n ";

        cout<<"\n\tEnter Your Choice:3";sl=3;
        if (num==5) x=2;
        else if (num==3) x=5;
        else x=2;
        break;
        case 4:
        cout<<"\n\t "<<a<<"\n"
        <<"\t"<<sl1<<b<<sl2
        <<"\n\t "<<c<<" \n"
        <<"\t "<<d<<" \n"
        <<"\t "<<e<<" \n";

        cout<<"\n\tEnter Your Choice:2";sl=2;
        if (num==5) x=3;
        else if (num==2) x=5;
        else x=3;
        break;
        case 5:
        cout<<"\n\t"<<sl1<<a<<sl2
        <<"\n\t "<<b<<"\n"
        <<"\t "<<c<<" \n"
        <<"\t "<<d<<" \n"
        <<"\t "<<e<<" \n";

        cout<<"\n\tEnter Your Choice:1";sl=1;
        if (num==5) x=4;
        else if (num==2) x=4;
        else x=4;
        break;
        default:
        cout<<"\n\tWrong!!2"<<x;getch();exit(0);
        }
break;
case 283:sl=6; goto end;
case 561:sl=1;goto end;
case 818:sl=2;goto end;
case 1075:sl=3;goto end;
case 1332:sl=4;goto end;
case 1589:sl=5;goto end;
case 1846:sl=6;goto end;
case 7181:goto end;
default:break;
 }
  key=bioskey(0);
 }
end:
return sl;
}


/********************************Menu To View Marks**************************/
void view()
 {
 int opt,i,reg,flag=0;
 char n[20],ch;
 view:
 opt=menu(5,"1.View All","2.Search Reg No","3.Show Failers","4.Read From File"
           ,"5.Back","[","]", "Dispay Menu","=");
 switch(opt)
  {
  case 1:                //Show All Marks
  for(i=0;i<10;i++)
   {
   clrscr();
   if(s[i].redgno!=NULL)
    {
    cout<<"                            Report Card Of "<<s[i].name
      <<"\n\tRegistration Number:"<<s[i].redgno<<"\n\tClass:"<<s[i].clas
      <<"\n\tAddress:"<<s[i].address<<"\n\tFather's Name:"<<s[i].fname
      <<"\n\tDate Of Birth:"<<s[i].dob.dd<<"-"<<s[i].dob.mm<<"-"<<s[i].dob.yyyy
      <<"\n\tStream:"<<s[i].st_code<<"\n\n\
-------------------------------------------------------------------------------\
    \n\tSubject Marks\n\t-------------\nS\tubject 1 :"
      <<s[i].sub1<<"\n\tSubject 2 :"<<s[i].sub2<<"\n\tSubject 3 :"<<s[i].sub3
      <<"\n\tSubject 4 :"<<s[i].sub4<<"\n\tSubject 5 :"<<s[i].sub5
      <<"\n\tTotal     :"<<s[i].total<<"\n\tGrade     :"<<s[i].div;
    cout<<"\n\n\tPress Any Key To Continue..";
    getch();
    }
   else break;
   }
  break;
  case 3:clrscr();                  //Show Failers
  for(i=0;i<records;i++)
   {
   if((s[i].sub1<33)||(s[i].sub2<33)||(s[i].sub3<33)||(s[i].sub4<33)||(s[i].sub5<33))
    {
    cout<<"                Report Card Of "<<s[i].name
      <<"\n\tRegistration Number:"<<s[i].redgno<<"\n\tClass:"<<s[i].clas
      <<"\n\tAddress:"<<s[i].address<<"\n\tFather's Name:"<<s[i].fname
      <<"\n\tDate Of Birth:"<<s[i].dob.dd<<"-"<<s[i].dob.mm<<"-"<<s[i].dob.yyyy
      <<"\n\tStream:"<<s[i].st_code<<"\n\n\t\
-------------------------------------------------------------------------------\
    \n\tSubject Marks\n\t-------------\n\tSubject 1 :"
      <<s[i].sub1<<"\n\tSubject 2 :"<<s[i].sub2<<"\n\tSubject 3 :"<<s[i].sub3
      <<"\n\tSubject 4 :"<<s[i].sub4<<"\n\tSubject 5 :"<<s[i].sub5
      <<"\n\tTotal     :"<<s[i].total<<"\n\tGrade     :"<<s[i].div;
      cout<<"\n\n\tPress Any Key To Continue...";
    flag=1;
    getch();
    }
   }
  if(flag==0)
   {
   cout<<"\n\tNo Failers Found";
   getch();
   view();
   }
  break;
  case 2:clrscr();                           //Search By Reg No
  cout<<"\n\n\tEnter Number To Be Searched:";
  cin>>reg;
  for(i=0;i<10;i++)
   {
   if(s[i].redgno==reg)
    {
    cout<<"                Report Card Of "<<s[i].name
      <<"\n\tRegistration Number:"<<s[i].redgno<<"\nClass:"<<s[i].clas
      <<"\n\tAddress:"<<s[i].address<<"\n\tFather's Name:"<<s[i].fname
      <<"\n\tDate Of Birth:"<<s[i].dob.dd<<"-"<<s[i].dob.mm<<"-"<<s[i].dob.yyyy
      <<"\n\tStream:"<<s[i].st_code<<"\n\n\
-------------------------------------------------------------------------------\
    \n\tSubject Marks\n\t-------------\n\tSubject 1 :"
      <<s[i].sub1<<"\n\tSubject 2 :"<<s[i].sub2<<"\n\tSubject 3 :"<<s[i].sub3
      <<"\n\tSubject 4 :"<<s[i].sub4<<"\n\tSubject 5 :"<<s[i].sub5
      <<"\n\tTotal     :"<<s[i].total<<"\n\tGrade     :"<<s[i].div;
    flag=1;
    getch();
    }
   }
  if(flag==0)
   {
   cout<<"\n\tRecord Not Found";
   getch();
   view();
   }
  break;
  case 4:                                    //Read File
  clrscr();
  cout<<"\n\n\tEnter Name Of Student:";gets(n);
  ifstream fil;
  strcat(n,".txt");
  fil.open(n);
  while(!fil.eof())


  {
  fil.get(ch);
  cout<<ch;
  }
  cout<<"\n\n\tPress Any Key To Continue...";
  getch();
  break;
  case 5:student_menu();                      //Exit
  default:student_menu();
  }
 goto view;
 }

/******************************Student Menu*********************************/
void student_menu()
 {
 unsigned int tredg;
 char ch='y',ch1;
 do
  {
  clrscr();
  ch1=menu(3,"1.Add Students","2.Display Student","3.Back","","","[","] "
        ,"Student Menu","=");
  switch(ch1)
   {
   case 1:clrscr();                             //Marks
      add();
      break;
   case 2:clrscr();                             //View Marks
      view();
      break;
   case 3:main_menu();                          //Main Menu
      getch();
      break;
   case 6:main_menu();                      //Main Menu
      getch();
      break;

   default:cout<<"\n\n\tWorng Choice!!";
   }
  cout<<"\n\n\tDo You Want to Continue?(Y/N)";
  cin>>ch;
  }
 while(ch=='y'||ch=='Y');
 main_menu();
 }

/*********************************Main Menu**********************************/
void main_menu()
{
char ch1;
do{
clrscr();
ch1=menu(4,"1. Students Details","2. Modify Students","3. Exit"," ",""," [","]","Student Information System","=");
switch(ch1)
{
case 1:                       //Student Menu
       student_menu();
       break;
case 2:                       //Marks Menu
       mark_menu();
       break;
case 3:            //Exit
       exit(0);
       break;

default:
    cout<<"\n\n\tWorng Choice!!";
}
}while(ch1==3);
}

/**********************************Marks Menu********************************/
void mark_menu()
{
int t_redg,i,opt,flag=0;
char ch='y',na[20];
do
{
clrscr();
cout<<"\n\tPress Esc to Quit";
opt=menu(3,"1.Modify Student","2.Remove Student","3.Back",
           "",""," [","] "," Menu","=");
switch(opt)
{
case 1:    clrscr();                //Modify Student
    mod();
    getch();
    mark_menu();
    break;
case 2:    clrscr();                //Delete Student
    cout<<"\n\tWhich Student Do you want to Delete\n\tEnter Reg No:";
    cin>>t_redg;
    for(i=0;i<10;i++)
     {
     if(s[i].redgno==t_redg)
      {
      strcat(na,s[i].name);
      strcat(na,".txt");
      remove(na);
      cout<<"\n\tThe Record of "<<s[i].name<<" is removed.";
      flag=1;
      break;
      }
     }
    if(flag==0)
     cout<<"\n\tRecord not found";
    mark_menu();
    break;
default:main_menu();
}

cout<<"\n\tDo you want to Continue?(Y/N)...";
cin>>ch;
}while(ch=='y'||ch=='Y');
if(ch=='n'||ch=='N')
main_menu();
}

/******************************Main Function*********************************/
void main()
{
clrscr();
clrscr();
main_menu();
getch();
}

/************************************End*************************************/
student stud;
//Input values to stu
file.write(reinterpret_cast<char*>(&stu),sizeof(student);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.