Page

C++ Program to Student Management System

#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<process.h>
#include<graphics.h>
#include<stdio.h>
struct stud
{
char n[30];
char father[30];
char mother[30];
char address[60];
char city[30];
int roll;
int per;
};
void showthanks();

void   main()
{

    int gdriver = DETECT, gmode,errorcode;
    initgraph(&gdriver, &gmode, "../bgi");
    int rol;
    setbkcolor(4);
    settextstyle(4,0,6);
    outtextxy(190,40,"WELCOME");
    outtextxy(260,170,"TO");
    settextstyle(4,0,5);
    outtextxy(70,320,"sourcecodernp.blogspot.com");
    getch();

    cleardevice();
    setbkcolor(5);
    settextstyle(1,0,6);
    outtextxy(190,40,"WELCOME");
    outtextxy(260,170,"TO");
    settextstyle(1,0,4);
    outtextxy(100,320,"STUDENT MANGEMENT SYSTEM");
    settextstyle(1,1,6);
    outtextxy(20,30,"C++ PROJECT");
    getch();

    cleardevice();

    stud s,m;
    char ch;
    while(1)
    {
    circle(150,80,60);
    circle(150,230,60);
    circle(150,380,60);
    circle(400,80,60);
    circle(400,230,60);
    circle(400,380,60);
    settextstyle(1,0,1);
    setbkcolor(GREEN);
    outtextxy(125,65,"1.LIST");
    outtextxy(105,215,"2.SEARCH");
    outtextxy(105,365,"3.APPEND");
    outtextxy(355,65,"4.MODIFY");
    outtextxy(355,210,"5.DELETE");
    outtextxy(375,365,"6.EXIT");

    outtextxy(67,440,"\n\nYOUR CHOICE ::");
    gotoxy(42,29);
    settextstyle(1,0,4);
    cin>>ch;
    switch(ch)
    {
case '1' :
   ifstream fin("STUDT.dat",ios::binary);
   int counter=0;
   while(fin.read((char*) &s,sizeof(s)))
   {
clrscr();
cleardevice();
setbkcolor(RED);
gotoxy(10,10);
cout<<"\n\t\t\tName :"<<s.n;
cout<<"\n\t\t\tRoll number :"<<s.roll;
cout<<"\n\t\t\tPercentage :"<<s.per;
cout<<"\n\t\t\tFather Name :"<<s.father;
cout<<"\n\t\t\tMother Name :"<<s.mother;
cout<<"\n\t\t\tAddress :"<<s.address;
cout<<"\n\t\t\tCity :"<<s.city;
cout<<"\n\nPress any key to continue\n";
getch();
counter++;
   }
   if (counter==0)
   {
cleardevice();
settextstyle(3,0,4);
setbkcolor(13);
outtextxy(40,50,"LIST IS EMPTY");
outtextxy(50,100,"Press any key to continue");
   }
   getch();
   cleardevice();
break;
case '2' :
   cleardevice();
   setbkcolor(5);
   int r,q=0;
   ifstream f1("STUDT.dat",ios::binary);
   cout<<"\nEnter the roll number of student::";
   cin>>r;
   while(f1.read((char *)&s,sizeof(s)))
   {
   if(s.roll==r)
   {
   setbkcolor(YELLOW);
   gotoxy(10,10);
   cout<<"The student is found!"<<endl;
   cout<<"Name ::"<<s.n<<endl;
   cout<<"Father Name ::"<<s.father<<endl;
   cout<<"Mother Name ::"<<s.mother<<endl;
   cout<<"Address::"<<s.address<<endl;
   cout<<"City::"<<s.city<<endl;
   cout<<"Percentage ::"<<s.per;
   q=1;
   }
   }
   if(q==0)
   {
   setbkcolor(14);
   cout<<"\nStudent not found in the list!";
   cout<<"\nPress any key to continue...";
   }
   getch();
   cleardevice();
break;
case '3' :
   ofstream fout("STUDT.dat",ios::binary|ios::app);
   char c='y';
   while(c=='y'||c=='Y')
   {
   cleardevice();
   setbkcolor(13);
   gotoxy(10,10);

   cout<<"\nEnter name ::";
   gets(s.n);
   cout<<"\nEnter Father Name::";
   gets(s.father);
   cout<<"\nEnter Mother Name::";
   gets(s.mother);
   cout<<"\nEnter Address::";
   gets(s.address);
   cout<<"\nEnter City::";
   gets(s.city);
   cout<<"\nEnter Roll Number :";
   cin>>s.roll;
   cout<<"\nEnter Percentage::";
   cin>>s.per;
   fout.write((char *)&s,sizeof(s));
   cout<<"\nDo You Want to Add Another Record ::";
   cin>>c;
   }
   cleardevice();
   fout.close();
break;
case '4' :
   cleardevice();
   setbkcolor(3);
   cout<<"Enter the roll no.";
cin>>rol;
   ifstream fi("STUDT.dat",ios::binary);
   ofstream out("temp");
   int f=1;
    while(fi.read((char*) &s,sizeof(s)))
    {
    if(s.roll!=rol)
{
 out.write((char*) &s,sizeof(s));
}
else
{
gotoxy(10,10);
cout<<"\nEnter New name ::";
gets(m.n);
cout<<"\nEnter New Father name ::";
gets(m.father);
cout<<"\nEnter New Mother name ::";
gets(m.mother);
cout<<"\nEnter New Address ::";
gets(m.address);
cout<<"\nEnter New City::";
gets(m.city);    //cin>>s.city;
m.roll=s.roll;
cout<<"\nEnter Percentage::";
cin>>m.per;
out.write((char *)&m,sizeof(m));
f=0;
}
    }
      fi.close();
      out.close();
      if(f==1)
      {
cout<<"not found";
      }
      else
      {
   remove("STUDT.dat");
   rename("temp","STUDT.dat");
      }
    getch();
    cleardevice();

break;
case '5' :
   cleardevice();
   setbkcolor(5);
   gotoxy(10,10);
   cout<<"Enter the roll no.";
cin>>rol;
   ifstream outfi("STUDT.dat",ios::binary);
   ofstream fouts("temp");
   f=1;
   while(outfi.read((char*) &s,sizeof(s)))
    {
    if(s.roll!=rol)
{
 fouts.write((char*) &s,sizeof(s));
}
else
{
f=0;
}
    }
      outfi.close();
      fouts.close();
      if(f==1)
      {
cout<<"Not Found In List!";
      }
     else
     {
remove("STUDT.dat");
rename("temp","STUDT.dat");
outtextxy(50,100,"Press any key to continue");
      }
    getch();
    cleardevice();
break;
case '6' :
showthanks();
exit(0);
}//end of switch
    }//end of while(1)
}//end of main()


void showthanks() {
    cleardevice();
    setbkcolor(3);
    outtextxy(240,80,"THANK YOU");
    outtextxy(260,170,"*-*-*-*-*");
    settextstyle(1,0,4);
    outtextxy(100,320,"sourcecodernp.blogspot.com");
    getch();
}



OUTPUT









No comments:

Post a Comment