主题:[原创]学生信息管理(c)---绝对原创(3)
void save(void)
{
textbackground(3);
window(1,3,80,14);
clrscr();
textcolor(15);
puttext(1,3,80,21,buf3);
if((fp=fopen(fileName,"w"))==NULL)
{
window(1,3,80,25);
gotoxy(1,21);
clreol();
textcolor(15);
cprintf(" Cannot Open File!");
return;
}
if(nHead==NULL)
{
textbackground(3);
window(20,10,50,13);
clrscr();
textcolor(15);
window(1,3,80,25);
gotoxy(1,21);
clreol();
cprintf(" HeadPoint Is Empty.");
return;
}
nCurrent=nHead;
do
{
fwrite(nCurrent,sizeof(struct student),1,fp);
nCurrent=nCurrent->next;
}while(nCurrent!=NULL);
window(1,3,80,25);
gotoxy(1,21);
clreol();
textcolor(15);
cprintf(" Save file %s complate!",fileName);
fclose(fp);
}
void saveTo(void)
{
char savefile[30];
show(2);
gets(savefile);
strcpy(fileName,savefile);
if(nHead==NULL)
{
textbackground(3);
window(20,10,50,13);
clrscr();
textcolor(15);
window(1,3,80,25);
gotoxy(1,21);
clreol();
cprintf(" HeadPoint Is Empty.");
return;
}
if((fp=fopen(savefile,"w"))==NULL)
{
window(1,3,80,25);
gotoxy(1,21);
clreol();
cprintf(" Cannot Open File.");
return;
}
textbackground(3);
window(1,3,80,14);
clrscr();
textcolor(15);
nCurrent=nHead;
do
{
fwrite(nCurrent,sizeof(struct student),1,fp);
nCurrent=nCurrent->next;
}while(nCurrent!=NULL);
recordList();
textcolor(15);
window(1,3,80,25);
gotoxy(1,21);
clreol();
cprintf(" Save file %s complete.",fileName);
gotoxy(1,22);
clreol();
cprintf(" File Name: %s",fileName);
fclose(fp);
}
void seleteAll(void)
{
int count=0,countSex=0,countMaths=0,countChinese=0,countEnglish=0;
puttext(1,3,80,21,buf3);
nCurrent=nHead;
if(nHead==NULL)
{
window(1,3,80,25);
gotoxy(1,21);
clreol();
textcolor(15);
clreol();
cprintf(" Data Is Empty!");
return;
}
do
{
count++;
if(nCurrent->stuSex=='m')
{ countSex++; }
if(nCurrent->stuMaths>=60)
{ countMaths++; }
if(nCurrent->stuChinese>=60)
{ countChinese++; }
if(nCurrent->stuEnglish>=60)
{ countEnglish++; }
nCurrent=nCurrent->next;
}while(nCurrent!=NULL);
window(1,3,80,25);
gotoxy(1,21);
textbackground(3);
textcolor(15);
clreol();
cprintf(" Tall Data: %d Record. Men %d. Maths %d Pass. Chinese %d Pass. English %d Pass.\n",count,countSex,countMaths,countChinese,countEnglish);
}
void seleteDelete(int num)
{
int deleteInt;
char deleteChar[20];
show(5);
if(num==2)cprintf("No:");
else cprintf("Name:");
gets(deleteChar);
if(num==2)
{ deleteInt=atoi(deleteChar); }
nCurrent=nHead;
if(nHead==NULL)
{
textbackground(3);
window(20,10,50,13);
clrscr();
window(1,23,80,25);
gotoxy(1,1);
clreol();
textcolor(15);
clreol();
cprintf("File Is Empty!");
return;
}
textbackground(3);
window(20,10,50,13);
clrscr();
puttext(1,3,80,21,buf3);
window(1,23,80,25);
gotoxy(1,1);
textcolor(15);
clreol();
do
{
if(num==2&&nHead->stuNo==deleteInt)
{
nHead=nHead->next;
}
if(num==3&&strcmp(nHead->stuName,deleteChar)==0)
{
nHead=nHead->next;
}
if(num==2&&nTail->stuNo==deleteInt)
{
nTail=nTail->prev;
}
if(num==3&&strcmp(nTail->stuName,deleteChar)==0)
{
nTail=nTail->prev;
}
if(num==2&&nCurrent->stuNo==deleteInt)
{
nCurrent->prev->next=nCurrent->next;
nCurrent->next->prev=nCurrent->prev;
gotoxy(2,1);cprintf("%d",nCurrent->stuNo);
gotoxy(11,1);cprintf("%s",nCurrent->stuName);
gotoxy(26,1);cprintf("%c",nCurrent->stuSex);
gotoxy(37,1);cprintf("%f",nCurrent->stuMaths);
gotoxy(50,1);cprintf("%f",nCurrent->stuChinese);
gotoxy(65,1);cprintf("%f",nCurrent->stuEnglish);
textbackground(3);
window(1,3,80,21);
clrscr();
pageCount=1;
showPageCount();
recordList();
return;
}
if(num==3&&strcmp(nCurrent->stuName,deleteChar)==0)
{
nCurrent->prev->next=nCurrent->next;
nCurrent->next->prev=nCurrent->prev;
gotoxy(2,1);cprintf("%d",nCurrent->stuNo);
gotoxy(11,1);cprintf("%s",nCurrent->stuName);
gotoxy(26,1);cprintf("%c",nCurrent->stuSex);
gotoxy(37,1);cprintf("%f",nCurrent->stuMaths);
gotoxy(50,1);cprintf("%f",nCurrent->stuChinese);
gotoxy(65,1);cprintf("%f",nCurrent->stuEnglish);
textbackground(3);
window(1,3,80,21);
clrscr();
pageCount=1;
showPageCount();
recordList();
return;
}
nCurrent=nCurrent->next;
}while(nCurrent!=NULL);
gotoxy(1,1);
clreol();
cprintf(" Delete Data Complete!");
}
void seleteTall(int num)
{
int i;
struct student *max;
textbackground(3);
window(23,6,38,13);
puttext(1,3,80,21,buf3);
if(nHead==NULL)
{
window(1,23,80,25);
gotoxy(1,1);
clreol();
textcolor(15);
clreol();
cprintf("File Is Empty!");
return;
}
for(nCurrent=nHead;nCurrent->next!=NULL;nCurrent=nCurrent->next)
{
max=nCurrent;
for(nTemp=nCurrent->next;nTemp!=NULL;nTemp=nTemp->next)
{
switch(num)
{
case 2:i=max->stuNo>nTemp->stuNo;break;
case 3:i=strcmp(max->stuName,nTemp->stuName)>0;break;
case 4:i=max->stuMaths>nTemp->stuMaths;break;
case 5:i=max->stuChinese>nTemp->stuChinese;break;
case 6:i=max->stuEnglish>nTemp->stuEnglish;break;
}
if(i!=1)
{
max=nTemp;
}
}
max->prev->next=max->next;
max->next->prev=max->prev;
max->next=nHead;
nHead=max;
}
window(1,23,80,25);
gotoxy(1,1);
textcolor(15);
clreol();
cprintf(" Tall Complete Complete!");
pageCount=1;
showPageCount();
recordList();
}
{
textbackground(3);
window(1,3,80,14);
clrscr();
textcolor(15);
puttext(1,3,80,21,buf3);
if((fp=fopen(fileName,"w"))==NULL)
{
window(1,3,80,25);
gotoxy(1,21);
clreol();
textcolor(15);
cprintf(" Cannot Open File!");
return;
}
if(nHead==NULL)
{
textbackground(3);
window(20,10,50,13);
clrscr();
textcolor(15);
window(1,3,80,25);
gotoxy(1,21);
clreol();
cprintf(" HeadPoint Is Empty.");
return;
}
nCurrent=nHead;
do
{
fwrite(nCurrent,sizeof(struct student),1,fp);
nCurrent=nCurrent->next;
}while(nCurrent!=NULL);
window(1,3,80,25);
gotoxy(1,21);
clreol();
textcolor(15);
cprintf(" Save file %s complate!",fileName);
fclose(fp);
}
void saveTo(void)
{
char savefile[30];
show(2);
gets(savefile);
strcpy(fileName,savefile);
if(nHead==NULL)
{
textbackground(3);
window(20,10,50,13);
clrscr();
textcolor(15);
window(1,3,80,25);
gotoxy(1,21);
clreol();
cprintf(" HeadPoint Is Empty.");
return;
}
if((fp=fopen(savefile,"w"))==NULL)
{
window(1,3,80,25);
gotoxy(1,21);
clreol();
cprintf(" Cannot Open File.");
return;
}
textbackground(3);
window(1,3,80,14);
clrscr();
textcolor(15);
nCurrent=nHead;
do
{
fwrite(nCurrent,sizeof(struct student),1,fp);
nCurrent=nCurrent->next;
}while(nCurrent!=NULL);
recordList();
textcolor(15);
window(1,3,80,25);
gotoxy(1,21);
clreol();
cprintf(" Save file %s complete.",fileName);
gotoxy(1,22);
clreol();
cprintf(" File Name: %s",fileName);
fclose(fp);
}
void seleteAll(void)
{
int count=0,countSex=0,countMaths=0,countChinese=0,countEnglish=0;
puttext(1,3,80,21,buf3);
nCurrent=nHead;
if(nHead==NULL)
{
window(1,3,80,25);
gotoxy(1,21);
clreol();
textcolor(15);
clreol();
cprintf(" Data Is Empty!");
return;
}
do
{
count++;
if(nCurrent->stuSex=='m')
{ countSex++; }
if(nCurrent->stuMaths>=60)
{ countMaths++; }
if(nCurrent->stuChinese>=60)
{ countChinese++; }
if(nCurrent->stuEnglish>=60)
{ countEnglish++; }
nCurrent=nCurrent->next;
}while(nCurrent!=NULL);
window(1,3,80,25);
gotoxy(1,21);
textbackground(3);
textcolor(15);
clreol();
cprintf(" Tall Data: %d Record. Men %d. Maths %d Pass. Chinese %d Pass. English %d Pass.\n",count,countSex,countMaths,countChinese,countEnglish);
}
void seleteDelete(int num)
{
int deleteInt;
char deleteChar[20];
show(5);
if(num==2)cprintf("No:");
else cprintf("Name:");
gets(deleteChar);
if(num==2)
{ deleteInt=atoi(deleteChar); }
nCurrent=nHead;
if(nHead==NULL)
{
textbackground(3);
window(20,10,50,13);
clrscr();
window(1,23,80,25);
gotoxy(1,1);
clreol();
textcolor(15);
clreol();
cprintf("File Is Empty!");
return;
}
textbackground(3);
window(20,10,50,13);
clrscr();
puttext(1,3,80,21,buf3);
window(1,23,80,25);
gotoxy(1,1);
textcolor(15);
clreol();
do
{
if(num==2&&nHead->stuNo==deleteInt)
{
nHead=nHead->next;
}
if(num==3&&strcmp(nHead->stuName,deleteChar)==0)
{
nHead=nHead->next;
}
if(num==2&&nTail->stuNo==deleteInt)
{
nTail=nTail->prev;
}
if(num==3&&strcmp(nTail->stuName,deleteChar)==0)
{
nTail=nTail->prev;
}
if(num==2&&nCurrent->stuNo==deleteInt)
{
nCurrent->prev->next=nCurrent->next;
nCurrent->next->prev=nCurrent->prev;
gotoxy(2,1);cprintf("%d",nCurrent->stuNo);
gotoxy(11,1);cprintf("%s",nCurrent->stuName);
gotoxy(26,1);cprintf("%c",nCurrent->stuSex);
gotoxy(37,1);cprintf("%f",nCurrent->stuMaths);
gotoxy(50,1);cprintf("%f",nCurrent->stuChinese);
gotoxy(65,1);cprintf("%f",nCurrent->stuEnglish);
textbackground(3);
window(1,3,80,21);
clrscr();
pageCount=1;
showPageCount();
recordList();
return;
}
if(num==3&&strcmp(nCurrent->stuName,deleteChar)==0)
{
nCurrent->prev->next=nCurrent->next;
nCurrent->next->prev=nCurrent->prev;
gotoxy(2,1);cprintf("%d",nCurrent->stuNo);
gotoxy(11,1);cprintf("%s",nCurrent->stuName);
gotoxy(26,1);cprintf("%c",nCurrent->stuSex);
gotoxy(37,1);cprintf("%f",nCurrent->stuMaths);
gotoxy(50,1);cprintf("%f",nCurrent->stuChinese);
gotoxy(65,1);cprintf("%f",nCurrent->stuEnglish);
textbackground(3);
window(1,3,80,21);
clrscr();
pageCount=1;
showPageCount();
recordList();
return;
}
nCurrent=nCurrent->next;
}while(nCurrent!=NULL);
gotoxy(1,1);
clreol();
cprintf(" Delete Data Complete!");
}
void seleteTall(int num)
{
int i;
struct student *max;
textbackground(3);
window(23,6,38,13);
puttext(1,3,80,21,buf3);
if(nHead==NULL)
{
window(1,23,80,25);
gotoxy(1,1);
clreol();
textcolor(15);
clreol();
cprintf("File Is Empty!");
return;
}
for(nCurrent=nHead;nCurrent->next!=NULL;nCurrent=nCurrent->next)
{
max=nCurrent;
for(nTemp=nCurrent->next;nTemp!=NULL;nTemp=nTemp->next)
{
switch(num)
{
case 2:i=max->stuNo>nTemp->stuNo;break;
case 3:i=strcmp(max->stuName,nTemp->stuName)>0;break;
case 4:i=max->stuMaths>nTemp->stuMaths;break;
case 5:i=max->stuChinese>nTemp->stuChinese;break;
case 6:i=max->stuEnglish>nTemp->stuEnglish;break;
}
if(i!=1)
{
max=nTemp;
}
}
max->prev->next=max->next;
max->next->prev=max->prev;
max->next=nHead;
nHead=max;
}
window(1,23,80,25);
gotoxy(1,1);
textcolor(15);
clreol();
cprintf(" Tall Complete Complete!");
pageCount=1;
showPageCount();
recordList();
}