Student Management System Amazing Project in C Language ((Source Code)

 #include<stdio.h>

#include<conio.h>
#include<graphics.h>

void insert_record();
void display_record();
void search_record();
void del_record();
void update_record();
void sort_record();
struct student
{
int roll;
char sec[10];
char name[40];
int marks;
float per;
};

struct student s;
void main()
{



  int i;
  char un[20],pass[20],pass1[20]="kush";
clrscr();
textbackground(YELLOW);
window(1,1,80,25);
clrscr();
textcolor(WHITE+BLINK);
gotoxy(28,2);
cprintf("STUDENT MANAGEMENT SYSTEM");
gotoxy(65,23);
printf("Version 2.0");
gotoxy(65,24);
printf("Made By India");
textbackground(WHITE);
window(10,5,70,20);
clrscr();
textcolor(BLUE);
gotoxy(19,3);
cprintf("%c WELCOME TO LOGIN PAGE %c",16,17);
gotoxy(19,4);
cprintf("-------------------------");

window(20,10,60,15);
textbackground(GREEN);
clrscr();

gotoxy(4,2);
textcolor(WHITE);
cprintf("   %c User Name: ",16);
gets(un);
label:
clrscr();
gotoxy(4,2);
printf("   %c User Name: %s",16,un);
gotoxy(4,4);
cprintf("   %c Password: ",16);
scanf("%s",&pass);
if(stricmp(pass,pass1)!=0)
{
	gotoxy(14,6);
	textcolor(BLUE+BLINK);
	cprintf("Wrong Password !!");
	getch();
	textcolor(WHITE);

goto label;
}
else
{
window(1,1,80,25);
textbackground(55);
clrscr();
textcolor(BLACK);
gotoxy(28,3);
cprintf("Developed By:-RT LAVKUSH");
gotoxy(35,5);
cprintf("Version 2.0");
gotoxy(37,6);
cprintf("INDIAN");
gotoxy(30,12);
cprintf("Loading..........");
textcolor(BLUE);
gotoxy(15,16);
for (i=1;i<=20;i++)
{
cprintf("%c",220);
delay(150);

}
gotoxy(33,15);
textcolor(RED+BLINK);
cprintf("  Server Slow!!");
gotoxy(35,16);
	for(i=1;i<=10;i++)
	{   textcolor(BLUE);
		cprintf("%c",220);
		delay(700);
	}
gotoxy(45,16);
	for(i=1;i<=22;i++)
	{
		textcolor(BLUE);
		cprintf("%c",220);
		delay(5);
	}
} 


	  while(1)
	{
	char ch;
	clrscr();
   textbackground(YELLOW);
   window(1,1,80,25);
	clrscr();
   textcolor(WHITE);
   gotoxy(2,2);
   cprintf(" HARI OM                [00.00.0000] & [00.00]          Developer:-RT LavKush");
   gotoxy(3,6);
   cprintf(" %c CONTACT %c",16,17);
   gotoxy(3,8);
   cprintf("[ RT LAVKUSH ]");
   gotoxy(3,9);
   cprintf("--------------");
   gotoxy(3,10);
   cprintf("%c 6207259544",26);
   gotoxy(3,11);
   cprintf("--------------");
   gotoxy(3,12);
   cprintf("%c 6200994028",26);
   gotoxy(3,13);
   cprintf("--------------");
   gotoxy(3,14);
   cprintf("  YOUTUBE");
   gotoxy(3,15);
   cprintf("    ^");
   gotoxy(3,16);
   cprintf(" HERRY CODE");
   gotoxy(3,17);
   cprintf("--------------");
   gotoxy(3,18);
   cprintf("   Gmail");
   gotoxy(3,19);
   cprintf(" (kush22aur");
   gotoxy(3,20);
   cprintf("@gmail.com)");
   gotoxy(3,21);
   cprintf("--------------");
   gotoxy(3,22);
   cprintf("  WEBSITE");
   gotoxy(3,23);
   cprintf("     ^");
   gotoxy(3,24);
   cprintf("hari4your.blogspot.com");
   textcolor(WHITE);
   gotoxy(67,6);
   cprintf("  %c ABOUT %c",16,17);
   gotoxy(66,8);
   cprintf("  Guide By:-");
   gotoxy(65,9);
   cprintf("   MD Jahangir");
   gotoxy(65,10);
   cprintf("  -------------");
   gotoxy(65,11);
   cprintf("  Co-Developer:-");
   gotoxy(65,12);
   cprintf("   Best Friends");
   gotoxy(67,13);
   cprintf("-------------");
   gotoxy(67,14);
   cprintf("  Based On");

   gotoxy(69,15);
   cprintf("   ^");
   gotoxy(67,16);
   cprintf("   Student ");
   gotoxy(67,17);
   cprintf(" Management");


  // cprintf("-------------");
   gotoxy(67,18);
   cprintf("   System");
   gotoxy(67,19);
   cprintf("-------------");
   gotoxy(67,21);
   cprintf("-------------");
   gotoxy(67,22);
   cprintf("For More Info");
   gotoxy(68,23);
   cprintf("    ^");
   gotoxy(57,24);
   cprintf("lavkush106.blogspot.com");

   //clrscr();
	window(18,6,65,23);
  textbackground(BLACK);

  clrscr();
//  gotoxy(15,3);
 //cprintf("------------------");
   textbackground(WHITE);
   textcolor(RED);
   gotoxy(12,3);
   cprintf("        MAIN MENU        ");
   textbackground(BLACK);
   textcolor(WHITE);


	 gotoxy(13,6);
	 cprintf("1 %c JOIN NEW STUDENT",26);
	 gotoxy(13,7);
	 cprintf("2 %c DISPLAY STUDENTS",26);
	 gotoxy(13,8);
	 cprintf("3 %c SEARCH STUDENT",26);
	 gotoxy(13,9);
	 cprintf("4 %c REMOVE STUDENT",26);
	 gotoxy(13,10);
	 cprintf("5 %c UPDATE DETAILS",26);
	 gotoxy(13,11);
	 cprintf("6 %c SHORT DETAILS",26);
	 gotoxy(13,12);
	 cprintf("7 %c LEAVE",26);
	 gotoxy(8,14);
	 printf("---------------------------------");
	 gotoxy(7,15);
	 printf("|                                 |");
	 textcolor(YELLOW);

	 gotoxy(14,15);
	 cprintf("Enter Your Choice ?");
		 gotoxy(8,16);
	 printf("---------------------------------");
		 gotoxy(38,15);

		ch=getche();



	 switch(ch)
	 {
		   case '1':
		clrscr();
			   insert_record();
			   break;
		case '2':
		clrscr();
			display_record();

			break;
		 case '3':
		 clrscr();
			 search_record();
			 break;
		  case '4':
		  clrscr();
			  del_record();
			  break;
		   case '5':
			clrscr();
			   update_record();
			   break;
			case '6': clrscr();
				sort_record();
				break;
			 case '7':
				exit(0);
				break;
			default:
			gotoxy(18,17);
			textcolor(RED+BLINK);
				cprintf("Try Again !");
				getch();
				break;


		  }

		}


 }
 //*****************FUNCTIONS**************************
//  1
 void insert_record()
 {

	   FILE *fp;
	  fp=fopen("stu.txt","a");
	  if(fp==NULL)
	  {
		printf("\n\t\tError: Cannot Open The File!!!");
		return;

	  }
	  window(1,1,80,25);
	  textbackground(WHITE);
	  clrscr();
	/*   window(1,1,40,25);
	  textbackground(WHITE);
	  clrscr();   */

	  textcolor(BLUE);
	   gotoxy(28,2);
	  cprintf("ENTER NEW STUDENT DETAILS ");
	  gotoxy(15,4);
	  cprintf("Enter Student Roll Number:");
	  scanf("%d",&s.roll);
	  fflush(stdin);
	  gotoxy(15,5);
	  cprintf("Enter Student Name:");
	  scanf("%s",s.name);
	  gotoxy(15,6);
	  cprintf("Enter Student Section:");
	  scanf("%s",s.sec);
	  gotoxy(15,7);
	  cprintf("Enter Student Total Marks:");
	  scanf("%d",&s.marks);
	  gotoxy(15,8);
	  cprintf("Enter Student Percentage:");
	  scanf("%f",&s.per);
	  fwrite(&s,sizeof(s),1,fp);
	  {
	  textcolor(BLACK+BLINK);
		  gotoxy(14,14);
		cprintf("!!!Student Record Inserted Successfully");


		getch();
	  }

	  fclose(fp);

	 }




 // 2
 void display_record()
{
	FILE *fp;
	int i;    //  intialization
	fp=fopen("stu.txt","r");
	if(fp==NULL)
	{
	   printf("Error :Cannot open the file!!!");
	   return;
	}
	window(1,1,80,25);
	textbackground(23);
	clrscr();
	textcolor(22);
	gotoxy(24,2);
	cprintf("  WELCOME TO STUDENT RECORDS");
	gotoxy(24,3);
	cprintf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
	gotoxy(1,5);
	cprintf("      Roll.No      Student Name     Section    Marks     Percentage\n");
	gotoxy(1,6);
	textcolor(YELLOW);
	cprintf("     ---------------------------------------------------------------");
	i=5;                                //extre variable
	while((fread(&s,sizeof(s),1,fp))==1)
	{

	textbackground(BLUE);
	gotoxy(5,i=i+2);    //i increase by sir
	textcolor(WHITE);
	cprintf(" %c  %d         %s           %s       %d       %f",16,s.roll,s.name,s.sec,s.marks,s.per);
	/*
	gotoxy(6,7);
	cprintf(" %c  %d         ",16,s.roll);
	gotoxy(19,7);
	cprintf(" %s       ",s.name);
	gotoxy(39,7);
	cprintf(" %s       ",s.sec);
	gotoxy(48,7);
	cprintf(" %d       ",s.marks);
	gotoxy(57,7);
	cprintf(" %f ",s.per); */
	}
	getch();

	fclose(fp);

}

// 3

void search_record()
{
	 int ro,flag=0;
	 FILE *fp;
	 fp=fopen("stu.txt","r");
	 if(fp==NULL)
	 {
	   window(1,1,80,25);
	 clrscr();
	 printf("\n\t\tError: Cannot open the file\n");
	 return;
	 }
	 textbackground(15);
	 window(1,1,80,25);
	 clrscr();
	 gotoxy(30,4);
	 textcolor(BLUE+BLINK);
	 cprintf("SEARCH BY ROLL NUMBER");
	 gotoxy(8,8);
	 printf("Enter Student Roll No Which You Want To Search:");
	 scanf("%d",&ro);
	 while(fread(&s,sizeof(s),1,fp)>0)
 //	 while(fread(&s,sizeof(s),1,fp)>0 && flag==0)
	 {
	   if(s.roll==ro)
	   {
	   flag=1;
	   clrscr();

	   //textbackground(BLUE);
	   textcolor(BLACK);
	   gotoxy(25,3);
	   printf("THIS RECORD SEARCHED BY YOU");
	   gotoxy(25,4);
	  // textbackground(YELLOW);
	   cprintf("%c--------------------------%c",16,17);

	   gotoxy(2,6);
	   cprintf("Roll.No       Student Name             Section    Marks    Percentage");
	   gotoxy(2,7);
	   cprintf("----------------------------------------------------------------------");
	   gotoxy(2,8);
	   cprintf("\n %d             %s                 %s       %d       %f",s.roll,s.name,s.sec,s.marks,s.per);
	   getch();
	   }
	 }
	 if(flag==0)
	 {
	 gotoxy(24,20);
	 textcolor(RED+BLINK);
	 cprintf("No Such Record Found !!!!");
	 getch();
	 }
fclose(fp);
}
// 4

void del_record()
{


  char name[40];
  unsigned flag=0;
// int ro,flag=0;
  FILE *fp,*ft;
  fp=fopen("stu.txt","r");
 // ft=fopen("temt.txt","w");
 if(fp==NULL)
  {

 window(1,1,80,25);
	 clrscr();

	 gotoxy(17,40);
	 printf("Error: Cannot Open The File!!!");
	 return;
  }
	window(1,1,80,25);
	clrscr();
 gotoxy(29,2);
 textcolor(WHITE+BLINK);
 cprintf(" DELETE BY NAME");
 gotoxy(29,3);
 textcolor(BLUE);
 cprintf("----------------");
 gotoxy(10,8);
  printf("Enter Student Name Which You Want To Delete:");
  //printf("Enter Student Roll Which You Want To Delete:");
  scanf("%s",&name);
  //scanf("%d",&ro);

  ft=fopen("temp.txt","a");
   while(fread(&s,sizeof(s),1,fp)==1)
  {
	  if(stricmp(name,s.name)==0)
	  //if(ro==s.roll)
	  {
		  gotoxy(20,14);
	  textcolor(RED+BLINK);
	  cprintf("Record Deleted Successfully");
	  getch();
	   flag=1;

	  }
	 else
	  fwrite(&s,sizeof(s),1,ft);



	 }
	if(flag==0)
	{
	 gotoxy(25,18);
	 textcolor(RED+BLINK);
	 cprintf(" Oops! Not Found");
	 getch();
	}

  fclose(fp);
  fclose(ft);
  remove("stu.txt");
  rename("temp.txt","stu.txt");

}

// 5

void update_record()
{
	 int ro,flag=0;
	 FILE *fp;
	 fp=fopen("stu.txt","r");
	 if(fp==NULL)
	 {
	  window(1,1,80,25);
	  clrscr();
	  printf("\n\t\tError: Cannot Open the File!!!");
	  return;
	 }
	   window(1,1,80,25);
	   textbackground(WHITE);
	 clrscr();
	  l:
	  clrscr();
	 gotoxy(25,5);
	 textcolor(BLUE+BLINK);
	 cprintf(" UPDATE BY ROLL NUMBER");
	 gotoxy(25,6);
	 textcolor(RED);
	 cprintf("-----------------------");

	 gotoxy(14,10);
	 textcolor(BLACK);
	 cprintf("Enter Roll Number of Student:");
	 scanf("%d",&ro);

	 while(fread(&s,sizeof(s),1,fp)>0 && flag==0)
	 {
	 if(s.roll==ro)
	 {
	   window(1,1,80,25);
	 clrscr();
	 textcolor(BLUE);
	 gotoxy(22,2);
	 cprintf("YOU WANT TO UPDATE THIS RECORD");
	 gotoxy(6,4);
	 textcolor(BLACK);
	 cprintf("    Roll No   Name of Student   Section  Marks  Percentage");
	 gotoxy(4,5);
	 cprintf("      ------------------------------------------------------");
	 gotoxy(4,6);
	 cprintf("        %d       %s            %s      %d    %f",s.roll,s.name,s.sec,s.marks,s.per);

	 gotoxy(22,9);
	 textcolor(RED+BLINK);
	 cprintf(" %c Now Enter The Details %c",16,17);

	 textcolor(BLUE);
	 gotoxy(14,12);
	 cprintf("Enter Roll Number:");
	 cscanf("%d",&s.roll);
	 //fflush(stdin);
	 gotoxy(14,14);
	 cprintf("Enter The Name:");
	 cscanf("%s",&s.name);
	 gotoxy(14,16);
	 cprintf("Enter The Section:");
	 cscanf("%s",&s.sec);
	 gotoxy(14,18);
	 cprintf("Enter The Marks:");
	 cscanf("%d",&s.marks);
	 gotoxy(14,20);
	 cprintf("Enter The Percentage:");
	 cscanf("%f",&s.per);
	 fseek(fp,-(long)sizeof(s),1);
	 fwrite(&s,sizeof(s),1,fp);
	 gotoxy(18,22);
	 textcolor(BLACK+BLINK);
	 cprintf("Record Updated Successfully");
	 getch();
	 flag=1;
	 }
	 else
	 {
	 gotoxy(20,20);
	 textcolor(GREEN+BLINK);
	 cprintf("Enter Correct Roll No!!");
	 textcolor(0);
	 getch();
	 goto l;
	 }
	 }
	 if(flag==0)
	 {

	 printf("\n\t\tError: Something Went Wrong!!!");

	 }
fclose(fp);
}
// 6

void sort_record()
{
	  struct student temp;
	  struct student arr[50];

	  int i,j,k=0;
	  FILE *fp;
	  fp=fopen("stu.txt","r");
	  if(fp==NULL)
	  {
	window(1,1,80,25);
	  clrscr();
	  printf("\n\t\tError: Cannot Open the File!!!");
	  }
	  i=0;
	  while(fread(&arr[i],sizeof(arr[i]),1,fp)==1)
	  {
	 i++;
	 k++;
	  }
	  for(i=0;i<k;i++)
	  {
	  for(j=0;j<k-i-1;j++)
	  {
		if(arr[j].roll>arr[j+1].roll)
		{
		  temp=arr[j];
		  arr[j]=arr[j+1];
		  arr[j+1]=temp;
		  }
		}
	  }

	  for(i=0;i<k;i++)
	  {
	window(1,1,80,25);
	textbackground(YELLOW);
	clrscr();
	gotoxy(25,2);
	textcolor(WHITE+BLINK);
	cprintf("SHORTED LIST OF RECORD");
	gotoxy(4,4);
	textcolor(BLACK);
	cprintf("Roll No  Student Name    Section     Marks     Percentage");
	gotoxy(4,5);
	cprintf("----------------------------------------------------------");
	gotoxy(4,6);
	cprintf(" %d         %s            %s          %d         %f",arr[i].roll,arr[i].name,arr[i].sec,arr[i].marks,arr[i].per);


	  }

	fclose(fp);
	getch();
	window(1,1,80,60);
	textbackground(YELLOW);
	clrscr();
}

Previous Post Next Post