Popular Posts

6/25/2012

Student Management in C Programming

Download Here
Code Here :
============================================

#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<process.h>
char menu1[6][30]={"Add","Show & Edit","Sort","Search","Delete"};
struct student{ char id[20];
char name[20];
char sex;
char birth[20];
char phonenum[20];
char room[20];
char department[50];
char fathername[50];
char fatherjob[50];
char mothername[50];
char motherjob[50];
char highschool[50];
char graduateyear[20];
char graduatelevel;
char placebirth[50];
char homeaddress[50];
     }stu[50]={NULL},temp,temp1[50];
char move='s';
int y=2,x=3,n=0,countstudent=0;
void menu();
void menu2();
void add();
void show();
void edit(int );
void search1(int );
void showlist(int);
void listsearch(int,int);
void temp1show(int );
void load();
void del();
void sort();
void bordersearch(int ,int );
void border(int );
void search();
void main()
{ menu();
}

void menu()
{
clrscr();
load();
do
{       cancel:
clrscr();
switch(tolower(move))
{
case 's': y++;
break;
case 'w': y--;
break;
case 13:        if(y==0)
add();
if(y==1)
show();
if(y==4)
del();
if(y==2)
sort();
if(y==3)
search();
clrscr();
break;
}
if(y>=5)
y=0;
if(y<0)
y=4;
for(int i=0;i<6;i++)
{ if(i==y)
{ gotoxy(x,i+2);
textcolor(RED);
cprintf("%s",menu1[i]);
}
else
{
gotoxy(x,i+2);
textcolor(WHITE);
cprintf("%s",menu1[i]);
}
gotoxy(20,20);
textcolor(WHITE);
FILE *daro1;
daro1=fopen("countstu.txt","r");
/* if(daro1==NULL)
{
puts("Can't open file");
exit(1);
}
*/  //It run this first if we run this "r" can't open. If we have delete the file countstu.txt.
fscanf(daro1," %d ",&countstudent);
gotoxy(2,29);
textcolor(YELLOW);
cprintf("Number of students=%d",countstudent);
fclose(daro1);
}
gotoxy(2,31);
textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
gotoxy(2,33);
textcolor(YELLOW);
cprintf("ESC=exit");
move=getch();
}while(move!=27);
clrscr();
gotoxy(10,10);
textcolor(YELLOW);
cprintf("Do you want to exit ?");
gotoxy(2,31);
textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
char exit[2][10]={"Yes","No"};
int x1=0,y1=12;
char ch='d';
do
{ switch(tolower(ch))
{ case 'a': x1--;
 break;
case 'd': x1++;
 break;
case 13:  if(x1==1)
 goto cancel;
 if(x1==0)
 goto exit;
}
if(x1>1)
x1=0;
if(x1<0)
x1=1;
int x2=12;
for(int i=0;i<2;i++)
{
if(i==x1)
{       gotoxy(x2,y1);
textcolor(RED);
cprintf("%s",exit[i]);
}
else
{ gotoxy(x2,y1);
textcolor(WHITE);
cprintf("%s",exit[i]);
}
x2=x2+5;
}
ch=getch();
}while(1);
exit:
}
void add()
{
clrscr();
textcolor(WHITE);
cprintf("Enter number of added students:");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
printf("%d",i+1);
printf("\tPlease fill all the information below");
printf("\tId=");
fflush(stdin);
gets(stu[i].id);
if(strcmp(stu[i].id,NULL)==0)
strcpy(stu[i].id,".");
printf("\tName=");
fflush(stdin);
gets(stu[i].name);
if(strcmp(stu[i].name,NULL)==0)
strcpy(stu[i].name,".");

printf("\tSex=");
fflush(stdin);
scanf("%c",&stu[i].sex);
if(stu[i].sex==NULL)
stu[i].sex='.';
printf("\tBirthday=");
fflush(stdin);
gets(stu[i].birth);
if(strcmp(stu[i].birth,NULL)==0)
strcpy(stu[i].birth,".");
printf("\tPhone number=");
fflush(stdin);
gets(stu[i].phonenum);
if(strcmp(stu[i].phonenum,NULL)==0)
strcpy(stu[i].phonenum,".");
printf("\tRoom=");
fflush(stdin);
gets(stu[i].room);
if(strcmp(stu[i].room,NULL)==0)
strcpy(stu[i].room,".");
printf("\tDepartment=");
fflush(stdin);
gets(stu[i].department);
if(strcmp(stu[i].department,NULL)==0)
strcpy(stu[i].department,".");
printf("\tFather's name=");
fflush(stdin);
gets(stu[i].fathername);
if(strcmp(stu[i].fathername,NULL)==0)
strcpy(stu[i].fathername,".");
printf("\tFather's job=");
fflush(stdin);
gets(stu[i].fatherjob);
if(strcmp(stu[i].fatherjob,NULL)==0)
strcpy(stu[i].fatherjob,".");
printf("\tMother's name=");
fflush(stdin);
gets(stu[i].mothername);
if(strcmp(stu[i].mothername,NULL)==0)
strcpy(stu[i].mothername,".");
printf("\tMother's job=");
fflush(stdin);
gets(stu[i].motherjob);
if(strcmp(stu[i].motherjob,NULL)==0)
strcpy(stu[i].motherjob,".");
printf("\tGraduated School=");
fflush(stdin);
gets(stu[i].highschool);
if(strcmp(stu[i].highschool,NULL)==0)
strcpy(stu[i].highschool,".");
printf("\tGraduated Level=");
fflush(stdin);
scanf("%c",&stu[i].graduatelevel);
if(stu[i].graduatelevel==NULL)
stu[i].graduatelevel='.';
printf("\tGraduated Year=");
fflush(stdin);
gets(stu[i].graduateyear);
if(strcmp(stu[i].graduateyear,NULL)==0)
strcpy(stu[i].graduateyear,".");
printf("\tPlace of birth:");
fflush(stdin);
gets(stu[i].placebirth);
if(strcmp(stu[i].placebirth,NULL)==0)
strcpy(stu[i].placebirth,".");
printf("\tHome address:");
fflush(stdin);
gets(stu[i].homeaddress);
if(strcmp(stu[i].homeaddress,NULL)==0)
strcpy(stu[i].homeaddress,".");
}
countstudent=countstudent+n;
FILE *daro,*daro1;
daro=fopen("123.txt","a");
daro1=fopen("countstu.txt","w");
if(daro==NULL||daro1==NULL)
{ puts("Can't open file");
getch();
exit(1);
}
fprintf(daro1," %d ",countstudent);
for(i=0;i<n;i++)
fprintf(daro," %s %s %c %s %s %s %s %s %s %s %s %s %c %s %s %s ",stu[i].id,stu[i].name,stu[i].sex,stu[i].birth,stu[i].phonenum,stu[i].room,stu[i].department,stu[i].fathername,stu[i].fatherjob,stu[i].mothername,stu[i].motherjob,stu[i].highschool,stu[i].graduatelevel,stu[i].graduateyear,stu[i].placebirth,stu[i].homeaddress);
fclose(daro);
fclose(daro1);

}
void show()
{       clrscr();
load();
char move='s';
int x,y;
do{
switch(tolower(move))
{ case 's':y++;
break;
case 'w':y--;
break;
case 13: edit(y);
break;
}
if(y>=countstudent)
y=0;
if(y<0)
y=countstudent-1;
clrscr();
menu2();
for(int i=0;i<countstudent;i++)
{
if(i==y)
{       gotoxy(1,(i+1)*2);
textcolor(RED);
showlist(i);
border(i);
}
else
{       gotoxy(1,(i+1)*2);
textcolor(WHITE);
showlist(i);
border(i);
}
}
gotoxy(2,48);
textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
gotoxy(2,46);
textcolor(YELLOW);
cprintf("ESC=Back");
move=getch();
}while(move!=27);
exit:
}
void load()
{ clrscr();
int i=0;
FILE *daro;
daro=fopen("123.txt","r");
menu2();
while(fscanf(daro," %s %s %c %s %s %s %s %s %s %s %s %s %c %s %s %s ",stu[i].id,stu[i].name,&stu[i].sex,stu[i].birth,stu[i].phonenum,stu[i].room,stu[i].department,stu[i].fathername,stu[i].fatherjob,stu[i].mothername,stu[i].motherjob,stu[i].highschool,&stu[i].graduatelevel,stu[i].graduateyear,stu[i].placebirth,stu[i].homeaddress)!=EOF)
i++;
fclose(daro);

}
void del()
{ int x1=1,y1=0 ;
char ch1='s';
clrscr();
do
{ clrscr();
textcolor(WHITE);
fflush(stdin);
menu2();
load();
switch(tolower(ch1))
{ case 'w': y1--;
 break;
case 's': y1++;
 break;
case 13:   clrscr();
 menu2();
 for(int i=y1;i<countstudent;i++)
 stu[i]=stu[i+1];
 countstudent--;
 FILE *daro1,*daro;
 daro=fopen("123.txt","w");
 daro1=fopen("countstu.txt","w");
 if(daro==NULL||daro1==NULL)
 { puts("Can't open file");
exit(1);
 }
 fprintf(daro1," %d ",countstudent);
 for(i=0;i<countstudent;i++)
 fprintf(daro," %s %s %c %s %s %s %s %s %s %s %s %s %c %s %s %s ",stu[i].id,stu[i].name,stu[i].sex,stu[i].birth,stu[i].phonenum,stu[i].room,stu[i].department,stu[i].fathername,stu[i].fatherjob,stu[i].mothername,stu[i].motherjob,stu[i].highschool,stu[i].graduatelevel,stu[i].graduateyear,stu[i].placebirth,stu[i].homeaddress);
 fclose(daro);
 fclose(daro1);
 break;

}
if(y1>=countstudent)
y1=0;
if(y1<0)
y1=countstudent-1;
if(x1>=7)
x1=0;
if(x1<0)
x1=6;
for(int i=0;i<countstudent;i++)
{       fflush(stdin);
if(i==y1)
{ textcolor(RED);
showlist(i);
border(i);
}
else
{
textcolor(WHITE);
showlist(i);
border(i);
}
}
gotoxy(2,44);
textcolor(YELLOW);
cprintf("ENTER=To delete file");
gotoxy(2,48);
textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
gotoxy(2,46);
textcolor(YELLOW);
cprintf("ESC=Back");
ch1=getch();
}while(ch1!=27);
exit:
}
void menu2()
{       textcolor(GREEN);
gotoxy(3,2);
cprintf("ID");
gotoxy(9,2);
cprintf("Name");
gotoxy(20,2);
cprintf("Sex");
gotoxy(27,2);
cprintf("Birthday");
gotoxy(40,2);
cprintf("Phone");
gotoxy(53,2);
cprintf("Room");
gotoxy(61,2);
cprintf("Department");

}
void showlist(int i)
{
gotoxy(3,(i+2)*2);
cprintf("%s",stu[i].id);
gotoxy(9,(i+2)*2);
cprintf("%s",stu[i].name);
gotoxy(20,(i+2)*2);
cprintf("%c",stu[i].sex);
gotoxy(27,(i+2)*2);
cprintf("%s",stu[i].birth);
gotoxy(40,(i+2)*2);
cprintf("%s",stu[i].phonenum);
gotoxy(53,(i+2)*2);
cprintf("%s",stu[i].room);
gotoxy(61,(i+2)*2);
cprintf("%s",stu[i].department);
}
void border(int i)
{       textcolor(BLUE);
gotoxy(2,2);
cprintf("³");
gotoxy(2,3);
cprintf("³");
gotoxy(2,1);
cprintf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿");
gotoxy(72,2);
cprintf("³");
gotoxy(72,3);
cprintf("³");

gotoxy(2,((i+2)*2)-1);
cprintf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿");

gotoxy(2,((i+2)*2)-1);
cprintf("³");
gotoxy(2,(i+2)*2);
cprintf("³");
gotoxy(2,((i+2)*2)+1);
cprintf("³");

gotoxy(8,2);
cprintf("³");
gotoxy(8,3);
cprintf("³");
gotoxy(8,((i+2)*2)-1);
cprintf("³");
gotoxy(8,(i+2)*2);
cprintf("³");
gotoxy(8,((i+2)*2)+1);
cprintf("³");

gotoxy(19,2);
cprintf("³");
gotoxy(19,3);
cprintf("³");
gotoxy(19,((i+2)*2)-1);
cprintf("³");
gotoxy(19,(i+2)*2);
cprintf("³");
gotoxy(19,((i+2)*2)+1);
cprintf("³");

gotoxy(26,2);
cprintf("³");
gotoxy(26,3);
cprintf("³");
gotoxy(26,((i+2)*2)-1);
cprintf("³");
gotoxy(26,(i+2)*2);
cprintf("³");
gotoxy(26,((i+2)*2)+1);
cprintf("³");

gotoxy(39,2);
cprintf("³");
gotoxy(39,3);
cprintf("³");
gotoxy(39,((i+2)*2)-1);
cprintf("³");
gotoxy(39,(i+2)*2);
cprintf("³");
gotoxy(39,((i+2)*2)+1);
cprintf("³");

gotoxy(52,2);
cprintf("³");
gotoxy(52,3);
cprintf("³");
gotoxy(52,((i+2)*2)-1);
cprintf("³");
gotoxy(52,(i+2)*2);
cprintf("³");
gotoxy(52,((i+2)*2)+1);
cprintf("³");

gotoxy(60,2);
cprintf("³");
gotoxy(60,3);
cprintf("³");
gotoxy(60,((i+2)*2)-1);
cprintf("³");
gotoxy(60,(i+2)*2);
cprintf("³");
gotoxy(60,((i+2)*2)+1);
cprintf("³");

gotoxy(72,((i+2)*2)-1);
cprintf("³");
gotoxy(72,(i+2)*2);
cprintf("³");
gotoxy(72,((i+2)*2)+1);
cprintf("³");

if(i==countstudent-1)
{ gotoxy(2,((i+2)*2)+1);
cprintf("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ");

}

}
void bordersearch(int i,int n)
{       textcolor(BLUE);
gotoxy(2,2);
cprintf("³");
gotoxy(2,3);
cprintf("³");
gotoxy(2,1);
cprintf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿");
gotoxy(72,2);
cprintf("³");
gotoxy(72,3);
cprintf("³");

gotoxy(2,((i+2)*2)-1);
cprintf("ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿");

gotoxy(2,((i+2)*2)-1);
cprintf("³");
gotoxy(2,(i+2)*2);
cprintf("³");
gotoxy(2,((i+2)*2)+1);
cprintf("³");

gotoxy(8,2);
cprintf("³");
gotoxy(8,3);
cprintf("³");
gotoxy(8,((i+2)*2)-1);
cprintf("³");
gotoxy(8,(i+2)*2);
cprintf("³");
gotoxy(8,((i+2)*2)+1);
cprintf("³");

gotoxy(19,2);
cprintf("³");
gotoxy(19,3);
cprintf("³");
gotoxy(19,((i+2)*2)-1);
cprintf("³");
gotoxy(19,(i+2)*2);
cprintf("³");
gotoxy(19,((i+2)*2)+1);
cprintf("³");

gotoxy(26,2);
cprintf("³");
gotoxy(26,3);
cprintf("³");
gotoxy(26,((i+2)*2)-1);
cprintf("³");
gotoxy(26,(i+2)*2);
cprintf("³");
gotoxy(26,((i+2)*2)+1);
cprintf("³");

gotoxy(39,2);
cprintf("³");
gotoxy(39,3);
cprintf("³");
gotoxy(39,((i+2)*2)-1);
cprintf("³");
gotoxy(39,(i+2)*2);
cprintf("³");
gotoxy(39,((i+2)*2)+1);
cprintf("³");

gotoxy(52,2);
cprintf("³");
gotoxy(52,3);
cprintf("³");
gotoxy(52,((i+2)*2)-1);
cprintf("³");
gotoxy(52,(i+2)*2);
cprintf("³");
gotoxy(52,((i+2)*2)+1);
cprintf("³");

gotoxy(60,2);
cprintf("³");
gotoxy(60,3);
cprintf("³");
gotoxy(60,((i+2)*2)-1);
cprintf("³");
gotoxy(60,(i+2)*2);
cprintf("³");
gotoxy(60,((i+2)*2)+1);
cprintf("³");

gotoxy(72,((i+2)*2)-1);
cprintf("³");
gotoxy(72,(i+2)*2);
cprintf("³");
gotoxy(72,((i+2)*2)+1);
cprintf("³");

if(i==n)
{ gotoxy(2,((i+2)*2)+1);
cprintf("ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ");

}

}
void temp1show(int i)
{
gotoxy(3,(i+2)*2);
cprintf("%s",temp1[i].id);
gotoxy(9,(i+2)*2);
cprintf("%s",temp1[i].name);
gotoxy(20,(i+2)*2);
cprintf("%c",temp1[i].sex);
gotoxy(27,(i+2)*2);
cprintf("%s",temp1[i].birth);
gotoxy(40,(i+2)*2);
cprintf("%s",temp1[i].phonenum);
gotoxy(53,(i+2)*2);
cprintf("%s",temp1[i].room);
gotoxy(61,(i+2)*2);
cprintf("%s",temp1[i].department);
}

void listsearch(int i,int y)
{
gotoxy(3,(y+2)*2);
cprintf("%s",stu[i].id);
gotoxy(9,(y+2)*2);
cprintf("%s",stu[i].name);
gotoxy(20,(y+2)*2);
cprintf("%c",stu[i].sex);
gotoxy(27,(y+2)*2);
cprintf("%s",stu[i].birth);
gotoxy(40,(y+2)*2);
cprintf("%s",stu[i].phonenum);
gotoxy(53,(y+2)*2);
cprintf("%s",stu[i].room);
gotoxy(61,(y+2)*2);
cprintf("%s",stu[i].department);


}
void search()
{ clrscr();
char search[5][40]={"Search by Id","Search by Name","Search by phone number","Search by Department","Search by room"};
int x=11,y=0,i;
char ch='s',choice;
do
{
switch(tolower(ch))
{ case 'w': y--;
 break;
case 's': y++;
 break;
case 13:  clrscr();
 char search[20];
 load();
 clrscr();
 if(y==0)
 { printf("\n\nPlease enter 'Id' that you want to search:");
gets(search);
clrscr();

menu2();
int y2=0;
for(i=0;i<countstudent;i++)
if(strcmp(stu[i].id,search)==0)
{ listsearch(i,y2);
temp1[y2]=stu[i];
y2++;
getch();

}
search1(y2);

 }
 else if(y==1)
 { printf("\n\nPlease enter 'Name' that you want to search:");
gets(search);
clrscr();
menu2();
int y2=0;
for(i=0;i<countstudent;i++)
if(strcmp(stu[i].name,search)==0)
{ listsearch(i,y2);
temp1[y2]=stu[i];
y2++;

}
search1(y2);

 }
 else if(y==2)
 { printf("\n\nPlease enter 'Phone number' that you want to search:");
gets(search);
clrscr();
menu2();
int y2=0;
for(i=0;i<countstudent;i++)
if(strcmp(stu[i].phonenum,search)==0)
{ listsearch(i,y2);
temp1[y2]=stu[i];
y2++;

}
search1(y2);
 }
 else if(y==3)
 { printf("\n\nPlease enter 'Department' that you want to search:");
gets(search);
clrscr();
menu2();
int y2=0;
for(i=0;i<countstudent;i++)
if(strcmp(stu[i].department,search)==0)
{ listsearch(i,y2);
temp1[y2]=stu[i];
y2++;


}
search1(y2);
 }
 else
 { printf("\n\nPlease enter 'Room' that you want to search:");
gets(search);
clrscr();
menu2();
int y2=0;
for(i=0;i<countstudent;i++)
if(strcmp(stu[i].room,search)==0)
{ listsearch(i,y2);
temp1[y2]=stu[i];
y2++;

}
search1(y2);
 }

 clrscr();
 break;
}

if(y>=5)
y=0;
if(y<0)
y=4;
for(int  i=0;i<5;i++)

{
if(i==y)
{       gotoxy(x,(i+5)*2);
textcolor(RED);
cprintf("%s",search[i]);
}
else
{ gotoxy(x,(i+5)*2);
textcolor(WHITE);
cprintf("%s",search[i]);
}
}
gotoxy(2,48);
textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
gotoxy(2,46);
textcolor(YELLOW);
cprintf("ESC=Back");
ch=getch();
}while(ch!=27);

}
void sort()
{ clrscr();
char sort[5][40]={"Sort by Id","Sort by Name","Sort by phone number","Sort by Department","Sort by room"};
int x=11,y=0;
char ch='s',choice;
do
{
switch(tolower(ch))
{ case 'w': y--;
 break;
case 's': y++;
 break;
case 13:  gotoxy(2,20);
 textcolor(YELLOW);
 cprintf("Press 'A' to sort A->Z");
 gotoxy(2,22);
 textcolor(YELLOW);
 cprintf("Press 'Z' to sort Z->A");
 choice=getch();
 for(int i=0;i<countstudent;i++)
for(int j=i+1;j<countstudent;j++)
switch(tolower(choice))
{
 case 'a': switch(y)
{ case 0: if(strcmp(stu[i].id,stu[j].id)>0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 1: if(strcmp(stu[i].name,stu[j].name)>0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 2: if(atoi(stu[i].phonenum)>atoi(stu[j].phonenum))
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 3: if(strcmp(stu[i].department,stu[j].department)>0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 4: if(strcmp(stu[i].room,stu[j].room)>0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
}
break;
 case 'z': switch(y)
{ case 0: if(strcmp(stu[i].id,stu[j].id)<0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 1: if(strcmp(stu[i].name,stu[j].name)<0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 2: if(atoi(stu[i].phonenum)<atoi(stu[j].phonenum))
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 3: if(strcmp(stu[i].department,stu[j].department)<0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
case 4: if(strcmp(stu[i].room,stu[j].room)<0)
{     temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
break;
}
break;
}

FILE *daro;
daro=fopen("123.txt","w");
if(daro==NULL)
{
puts("Can't open file");
exit(1);
}
for(i=0;i<countstudent;i++)
fprintf(daro," %s %s %c %s %s %s %s %s %s %s %s %s %c %s %s %s ",stu[i].id,stu[i].name,stu[i].sex,stu[i].birth,stu[i].phonenum,stu[i].room,stu[i].department,stu[i].fathername,stu[i].fatherjob,stu[i].mothername,stu[i].motherjob,stu[i].highschool,stu[i].graduatelevel,stu[i].graduateyear,stu[i].placebirth,stu[i].homeaddress);
fclose(daro);
gotoxy(30,25);
textcolor(BLUE);
cprintf("Sorted has been completed.");
getch();
clrscr();
break;

}

if(y>=5)
y=0;
if(y<0)
y=4;
for(int  i=0;i<5;i++)

{
if(i==y)
{       gotoxy(x,(i+5)*2);
textcolor(RED);
cprintf("%s",sort[i]);
}
else
{ gotoxy(x,(i+5)*2);
textcolor(WHITE);
cprintf("%s",sort[i]);
}
}
gotoxy(2,48);
textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
gotoxy(2,46);
textcolor(YELLOW);
cprintf("ESC=Back");
ch=getch();
}while(ch!=27);
exit:
}
void search1(int y2)
{ char c='s';
int y1=0;
clrscr();
do{ switch(tolower(c))
{ case 'w': y1--;break;
case 's': y1++;break;
case 13: clrscr();
textcolor(WHITE);
cprintf("          Transcribe view");
cprintf("\n\n\r\rID:%s",temp1[y1].id);
cprintf("\n\n\r\rName:%s",temp1[y1].name);
cprintf("\n\n\r\rSex:%c",temp1[y1].sex);
cprintf("\n\n\r\rBirthday:%s",temp1[y1].birth);
cprintf("\n\n\r\rPhone number:%s",temp1[y1].phonenum);
cprintf("\n\n\r\rRoom:%s",temp1[y1].room);
cprintf("\n\n\r\rDepartment:%s",temp1[y1].department);
cprintf("\n\n\r\rFather's name:%s",temp1[y1].fathername);
cprintf("\n\n\r\rFather's job:%s",temp1[y1].fatherjob);
cprintf("\n\n\r\rMother's name:%s",temp1[y1].mothername);
cprintf("\n\n\r\rMother's job:%s",temp1[y1].motherjob);
cprintf("\n\n\r\rGraduated School:%s",temp1[y1].highschool);
cprintf("\n\n\r\rGraduated Level:%c",temp1[y1].graduatelevel);
cprintf("\n\n\r\rGraduated year:%s",temp1[y1].graduateyear);
cprintf("\n\n\r\rPlace of birth:%s",temp1[y1].placebirth);
cprintf("\n\n\r\rHome address:%s",temp1[y1].homeaddress);
gotoxy(2,46);
textcolor(YELLOW);
cprintf("ESC=Back");
getch();

clrscr();


break;



}
if(y1>=y2)
y1=0;
if(y1<0)
y1=y2-1;
menu2();
for(int k=0;k<=y2;k++)
{
if(y1==k)
{
textcolor(RED);
temp1show(k);
}
else
{
textcolor(WHITE);
temp1show(k);
}
bordersearch(k,y2);
gotoxy(2,48);
}

textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
gotoxy(2,46);
textcolor(YELLOW);
cprintf("ESC=Back");
c=getch();
clrscr();
}while(c!=27);

}
void edit(int y1)
{
clrscr();
char edit[16][50]={"Id:","Name:","Sex:","Birthday:","Phone number:","Room:","Department:","Father's name:","Father's job:","Mother's name:","Mother's job:","Graduated school:","Graduated level:","Graduated year:","Place of birth:","Home address:"};
char ch='s';
int y=0,i=0;
do
{
switch(ch)
{ case 'w': y--;
break;
case 's': y++;
break;
case 13:        clrscr();
for(int j=0;j<16;j++)
{ if(j==y)
{       gotoxy(2,(j+1)*2);
textcolor(RED);
cprintf("%s",edit[j]);
}
else
{       gotoxy(2,(j+1)*2);
textcolor(WHITE);
cprintf("%s",edit[j]);
}
if(j==0)
cprintf("%s",stu[y1].id);
if(j==1)
cprintf("%s",stu[y1].name);
if(j==2)
cprintf("%c",stu[y1].sex);
if(j==3)
cprintf("%s",stu[y1].birth);
if(j==4)
cprintf("%s",stu[y1].phonenum);
if(j==5)
cprintf("%s",stu[y1].room);
if(j==6)
cprintf("%s",stu[y1].department);
if(j==7)
cprintf("%s",stu[y1].fathername);
if(j==8)
cprintf("%s",stu[y1].fatherjob);
if(j==9)
cprintf("%s",stu[y1].mothername);
if(j==10)
cprintf("%s",stu[y1].motherjob);
if(j==11)
cprintf("%s",stu[y1].highschool);
if(j==12)
cprintf("%s",stu[y1].graduateyear);
if(j==13)
cprintf("%c",stu[y1].graduatelevel);
if(j==14)
cprintf("%s",stu[y1].placebirth);
if(j==15)
cprintf("%s",stu[y1].homeaddress);
}
gotoxy(2,(y+1)*2);
textcolor(WHITE);
cprintf("%s",edit[y]);
textcolor(RED);
if(y==0)
gets(stu[y1].id);
else if(y==1)
gets(stu[y1].name);
else if(y==2)
scanf("%c",&stu[y1].sex);
else if(y==3)
gets(stu[y1].birth);
else if(y==4)
gets(stu[y1].phonenum);
else if(y==5)
gets(stu[y1].room);
else if(y==6)
gets(stu[y1].department);
else if(y==7)
gets(stu[y1].fathername);
else if(y==8)
gets(stu[y1].fatherjob);
else if(y==9)
gets(stu[y1].mothername);
else if(y==10)
gets(stu[y1].motherjob);
else if(y==11)
gets(stu[y1].highschool);
else if(y==12)
gets(stu[y1].graduateyear);
else if(y==13)
scanf("%c",&stu[y1].graduatelevel);
else if(y==14)
gets(stu[y1].placebirth);
else//if(y==15)
gets(stu[y1].homeaddress);

FILE *daro;
daro=fopen("123.txt","w");
if(daro==NULL)
{ puts("Can't open file");
exit(1);
}
for(j=0;j<countstudent;j++)
fprintf(daro," %s %s %c %s %s %s %s %s %s %s %s %s %c %s %s %s ",stu[j].id,stu[j].name,stu[j].sex,stu[j].birth,stu[j].phonenum,stu[j].room,stu[j].department,stu[j].fathername,stu[j].fatherjob,stu[j].mothername,stu[j].motherjob,stu[j].highschool,stu[j].graduatelevel,stu[j].graduateyear,stu[j].placebirth,stu[j].homeaddress);
fclose(daro);

break;
}
if(y>=16)
y=0;
if(y<0)
y=15;
textcolor(WHITE);
gotoxy(10,1);
cprintf("Transcribe view");
for(i=0;i<16;i++)
{ if(i==y)
{       gotoxy(2,(i+1)*2);
textcolor(RED);
cprintf("%s",edit[i]);
}
else
{       gotoxy(2,(i+1)*2);
textcolor(WHITE);
cprintf("%s",edit[i]);
}
if(i==0)
cprintf("%s",stu[y1].id);
if(i==1)
cprintf("%s",stu[y1].name);
if(i==2)
cprintf("%c",stu[y1].sex);
if(i==3)
cprintf("%s",stu[y1].birth);
if(i==4)
cprintf("%s",stu[y1].phonenum);
if(i==5)
cprintf("%s",stu[y1].room);
if(i==6)
cprintf("%s",stu[y1].department);
if(i==7)
cprintf("%s",stu[y1].fathername);
if(i==8)
cprintf("%s",stu[y1].fatherjob);
if(i==9)
cprintf("%s",stu[y1].mothername);
if(i==10)
cprintf("%s",stu[y1].motherjob);
if(i==11)
cprintf("%s",stu[y1].highschool);
if(i==12)
cprintf("%s",stu[y1].graduateyear);
if(i==13)
cprintf("%c",stu[y1].graduatelevel);
if(i==14)
cprintf("%s",stu[y1].placebirth);
if(i==15)
cprintf("%s",stu[y1].homeaddress);

}
gotoxy(2,44);
textcolor(YELLOW);
cprintf("ENTER=To rename");
gotoxy(2,48);
textcolor(YELLOW);
cprintf("NOTE: The Selected file is");
textcolor(RED);
cprintf(" red.");
gotoxy(2,46);
textcolor(YELLOW);
cprintf("ESC=Back");
ch=getch();
clrscr();
}while(ch!=27);



}

// Don't forget to shared it to your friends ..!

0 comments:

Post a Comment