?? stu_info_7.8.c
字號:
save_flag=1;
break;
}
else if(ch=='D' || ch=='d')
{
DeleteData(num,x,y);
save_flag=1;
break;
}
else if(ch=='Y' || ch=='y')
{
Gotoxy(0,5);
for(i=5;i<18;i++) //清除5-17行
printf("%*s",80," ");
break;
}
else if(ch==27)
{
break;
}
else
{
InputError(x,y,ch);
}
}while(1);
}while(ch=='Y' || ch=='y');
}
/*****************************************************************
***函數名:UpdateData
***參數:int num (ID) x,y光標
***功能:修改數據
***返回值:無
*****************************************************************/
void UpdateData(int num,int x,int y)
{
int i;
char ch;
char *NewAddInfo[]=
{
" Name *:",
" Age *:",
" Chinese *:",
" English *:",
" Math *:",
" Physics *:",
" Chemistry *:"
};
do
{
ClearMessage();
Gotoxy(0,19);
printf("Are you continue Update Data(Y/N)?");
ch=getche();
getch();
if(ch=='Y' || ch=='y')
{
Gotoxy(0,6);
for(i=6;i<18;i++) //清除5-17行
printf("%*s",80," ");
fflush(stdin);
Gotoxy(26,3);
printf(UPDATE);
Gotoxy(35,7);//學號
printf("SNO: %s\n",stu[num-1].sno);
strcpy(data.sno,stu[num-1].sno);
for(i=0;i<7;i++) //打印菜單
{
Gotoxy(20,8+i);
printf("%s\n",NewAddInfo[i]);
}
AddName();
AddAge();
AddScore();
//數據保存
stu[num-1]=data;
ClearMessage();
Gotoxy(0,19);
printf("Date Update success!");
getch();
Gotoxy(0,20);
printf("Pleased key to continue ...");
getch();
return;
}
else if(ch=='N' || ch=='n')
{
return ;
}
else
{
InputError(x,y,ch);
}
}while(!(ch=='Y' || ch=='y' || ch=='N' || ch=='n' ));
}
/*****************************************************************
***函數名:DeleteData
***參數:int num (ID)x,y光標
***功能:刪除數據
***返回值:無
*****************************************************************/
void DeleteData(int num,int x,int y)
{
int i;
char ch;
do
{
ClearMessage();
Gotoxy(0,19);
printf("Are you continue Delete Data(Y/N)?");
ch=getche();
getch();
if(ch=='Y' || ch=='y')
{
fflush(stdin);
count--;
for(i=num-1;i<count;i++)
stu[i]=stu[i+1];
sno[num-1]=0;
ClearMessage();
Gotoxy(0,19);
printf("Date Delete success!Pleased key to continue ...");
getch();
return;
break;
}
else if(ch=='N' || ch=='n')
{
return ;
break;
}
else
{
InputError(x,y,ch);
}
}while(1);
}
/*****************************************************************
***函數名:SearchName
***參數:無
***功能:實現姓名精確、模糊查詢
***返回值:無
*****************************************************************/
void SearchName()
{
int x,y,i,j,flag,k,index=0; //flag找到記錄數 k為光標移動
int num,len;// 記錄SNO;
char tempname[21];
STU temp;
Gotoxy(0,5);
for(i=5;i<18;i++) //清除5-17行
printf("%*s",80," ");
do
{
k=0;
flag=0;
Gotoxy(20,10);
printf("Please Input select name:");
Getxy(&x,&y);
ClearMessage();
Gotoxy(0,19);
printf("Please Input a-z or A-Z len=1-20 alpha. <example:zhang san>");
Gotoxy(x,y);
gets(tempname);
Left_Right(tempname); //左右空處理
len = strlen(tempname);
if(len==0)
{
ClearMessage();
Gotoxy(0,19);
printf("Error NULL!Please enter again!");
getch();
continue;
}
Gotoxy(20,10);
printf("Please wait!The system is searching...");
Sleep(300);
Gotoxy(0,5);
for(i=5;i<18;i++) //清除5-17行
printf("%*s",80," ");
for(j=0;j<count;j++)
{
temp=stu[j];
if(!(strstr(strlwr(temp.name),strlwr(tempname))==NULL)) //找到記錄
{
flag=1;
num=atoi(temp.sno); //把SNO轉化為INT型
Gotoxy(0,5);
total[j]=stu[j].score[0]+stu[j].score[1]+stu[j].score[2]+stu[j].score[3]+stu[j].score[4];
avg[j]=(double)total[j]/5.0;
printf("%-4s%-21s%-4s%-8s%-8s%-5s%-8s%-10s%-6s%-4s\n",
"sno","name","age","chinese","english","math","physics","chemistry","total","avg");
Gotoxy(0,6+k);
printf("%-4s%-21s%-5d%-8.1f%-7.1f%-7.1f%-8.1f%-8.1f%-6.1f%-4.1lf\n",stu[j].sno,stu[j].name,stu[j].age,
stu[j].score[0],stu[j].score[1],stu[j].score[2],stu[j].score[3],stu[j].score[4],total[j],avg[j]);
k++;
index++;
if(k%10==0)
{
printf("Pleased key to continue ...");
getch();
Gotoxy(0,6);
for(i=6;i<18;i++) //清除5-17行
printf("%*s",80," ");
k=0;
}
}
else //沒有找到記錄
{
continue;
}
if(j>=count)
break;
}
if(!flag)
{
ClearMessage();
Gotoxy(0,19);
printf("sorry!not record!Pleased key to continue ...");
getch();
break;
}
else
{
ClearMessage();
Gotoxy(0,19);
printf("select KeyWords:%-4s success! Counts=%d",tempname,index);
}
do
{
Gotoxy(16,17);
printf("The default delete, update the last record!");
Gotoxy(8,16);
printf("Press [U/u] Update [D/d] Delete [Y/y] Continue [Esc] Back:");
Getxy(&x,&y);
//[U]/[u] 85/117 [D]/[d] 68/100
ch=getche();
Gotoxy(0,20);
printf("%*s",80," ");
if(ch=='U' || ch=='u')
{
UpdateData(num,x,y);
save_flag=1;
break;
}
else if(ch=='D' || ch=='d')
{
DeleteData(num,x,y);
save_flag=1;
break;
}
else if(ch=='Y' || ch=='y')
{
Gotoxy(0,5);
for(i=5;i<18;i++) //清除5-17行
printf("%*s",80," ");
break;
}
else if(ch==27)
{
break;
}
else
{
InputError(x,y,ch);
}
}while(1);
}while(ch=='Y' || ch=='y');
}
/*****************************************************************
***函數名:SortData
***參數:無
***功能:實現學號、姓名升序、降序
***返回值:無
*****************************************************************/
void SortData()
{
int s, i,x,y;
char *Sort[]=
{ "1.sno ASC:",
"2.sno DESC:",
"3.name ASC:",
"4.name DESC:",
"5.score ASC",
"6.score DESC",
"0.return MenuList:"
};
system("cls");
Gotoxy(33,3);
printf(SORTDATA);
MakeMenuInfo();
Gotoxy(0,6);
s=JuZhong(Sort,7); //菜單項--居中顯示
for(i=0;i<=6;i++) //打印菜單項
printf("%*s%s\n",s," ",Sort[i]);
Gotoxy(0,0);
Gotoxy(26,14);
printf("Please Make a choices[0-6]:");
Getxy(&x,&y);
if(count==0)
{
ClearMessage();
Gotoxy(0,19);
printf("Error!Data is NULL.");
printf("Pleased key to continue ...");
fflush(stdin);
getch();
return;
}
do
{
fflush(stdin);
ch=getche();
getch();
switch(ch)
{
case '1':SortSnoAsc();SortData();break;
case '2':SortSnoDesc();SortData();break;
case '3':SortNameAsc();SortData();break;
case '4':SortNameDesc();SortData();break;
case '5':SortTotalAsc();SortData();break;
case '6':SortTotalDesc();SortData();break;
case '0':return;break;
default:InputError(x,y,ch);break;
}
}while(!(ch>='0' && ch<='6'));
}
/*****************************************************************
***函數名:Sort_Print_Message
***參數:無
***功能:實現5-17行清空,相關信息打印
***返回值:無
*****************************************************************/
void Sort_Print_Message()
{
int i;
Gotoxy(0,5);
for(i=5;i<18;i++) //清除5-17行
printf("%*s",80," ");
ClearMessage();
Gotoxy(0,19);
printf("Please wait!The system is Sorting...");
Sleep(300);
}
/*****************************************************************
***函數名:SortSnoAsc
***參數:無
***功能:實現學號升序 ----冒泡
***返回值:無
*****************************************************************/
void SortSnoAsc()
{
int i,j,r,k;
STU temp;
Sort_Print_Message();
for(i=1,r=count-1,k=count;i<=r;r=k-1)
{
for(j=r;j>=i;j--) //上浮
{
if(strcmp(stu[j-1].sno,stu[j].sno)>0)
{
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
k=j;
}
}
for(j=k+1,i=k+1;j<=r;j++) //下沉
{
if(strcmp(stu[j-1].sno,stu[j].sno)>0)
{
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
k=j;
}
}
}
PrintData();
}
/*****************************************************************
***函數名:SortSnoDesc
***參數:無
***功能:實現學號降序----冒泡(上浮/下沉)
***返回值:無
*****************************************************************/
void SortSnoDesc()
{
int i,j,r,k;
STU temp;
Sort_Print_Message();
for(i=1,r=count-1,k=count;i<=r;r=k-1)
{
for(j=count-1;j>=i;j--) //上浮
{
if(strcmp(stu[j-1].sno,stu[j].sno)<0)
{
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
k=j;
}
}
for(j=k+1,i=k+1;j<=r;j++) //下沉
{
if(strcmp(stu[j-1].sno,stu[j].sno)<0)
{
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
k=j;
}
}
}
PrintData();
}
/*****************************************************************
***函數名:SortNameAsc
***參數:無
***功能:實現姓名升序--選擇
***返回值:無
*****************************************************************/
void SortNameAsc()
{
int i,j,k;
STU temp;
Sort_Print_Message();
for(i=0;i<count-1;i++)
{
k=i;
for(j=i+1;j<count;j++)
{
if(strcmp(stu[j].name,stu[k].name)<0)
k=j;
}
if(k!=i)
{
temp=stu[k];
stu[k]=stu[i];
stu[i]=temp;
}
}
PrintData();
}
/*****************************************************************
***函數名:SortNameDesc
***參數:無
***功能:實現姓名降序--選擇
***返回值:無
*****************************************************************/
void SortNameDesc()
{
int i,j,k;
STU temp;
Sort_Print_Message();
for(i=0;i<count-1;i++)
{
k=i;
for(j=i+1;j<count;j++)
{
if(strcmp(stu[j].name,stu[k].name)>0)
k=j;
}
if(k!=i)
{
temp=stu[k];
stu[k]=stu[i];
stu[i]=temp;
}
}
PrintData();
}
/*****************************************************************
***函數名:SortTotalAsc
***參數:無
***功能:實現總成績升序------插入排序
***返回值:無
*****************************************************************/
void SortTotalAsc()
{
int i,j;
float t;
STU temptotal;
Sort_Print_Message();
for(i=0;i<count;i++)
total[i]=stu[i].score[0]+stu[i].score[1]+stu[i].score[2]+stu[i].score[3]+stu[i].score[4];
for(i=1;i<count;i++)
{
for(j=0;j<i;j++)
{
if(total[j]>total[i])
{
temptotal=stu[j];
stu[j]=stu[i];
stu[i]=temptotal;
t=total[j];
total[j]=total[i];
total[i]=t;
}
}
}
PrintData();
}
/*****************************************************************
***函數名:SortTotalDesc
***參數:無
***功能:實現總成績降序------插入排序
***返回值:無
*****************************************************************/
void SortTotalDesc()
{
int i,j;
float t;
STU temptotal;
Sort_Print_Message();
for(i=0;i<count;i++)
total[i]=stu[i].score[0]+stu[i].score[1]+stu[i].score[2]+stu[i].score[3]+stu[i].score[4];
for(i=1;i<count;i++)
{
for(j=0;j<i;j++)
{
if(total[j]<total[i])
{
temptotal=stu[j];
stu[j]=stu[i];
stu[i]=temptotal;
t=total[j];
total[j]=total[i];
total[i]=t;
}
}
}
PrintData();
}
/*****************************************************************
***函數名:Getfilename
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -