?? stu_info_7.8.c
字號:
***返回值:無
*****************************************************************/
void AddName() //姓名
{
char tempname[100];
int i,len,f=0;
do{
ClearMessage();
Gotoxy(0,19);
printf("Please Input len:1-20 a-z or A-Z alpha. <example:zhang san>");
Gotoxy(40,8);
len=GetString(tempname,20);
Left_Right(tempname);
len = strlen(tempname);
if(len==0)
{
ClearMessage();
Gotoxy(0,19);
printf("Error NULL!Please enter again!");
getch();
continue;
}
for(i=0;i<len;i++)
{
if(!(isalpha(tempname[i])||tempname[i]==' ')) //判斷是不是字母
{
ClearMessage();
Gotoxy(0,19);
printf("Error!Input illegal char,Please enter again.");
getch();
Gotoxy(40,8);
printf("%*s",40," ");
break;
}
}
if(i>=len)
break;
}while(1);
Gotoxy(40,8);
printf("%*s",40," ");
Gotoxy(40,8);
printf("%s",tempname);
strcpy(data.name,tempname);
//strcpy(stu_link.studate.name,tempname);
}
/*****************************************************************
***函數名:AddAge
***參數:無
***功能:判斷非法字符
***返回值:無
*****************************************************************/
void AddAge()
{
int i=0,len,k=0;
char tempage[40];
do
{
i=0;
Gotoxy(40,9);
ClearMessage();
Gotoxy(0,19);
printf("Please Input <10-20> digit. <example:15>");
Gotoxy(40,9);
len=GetString(tempage,2);
if(len==0)
{
ClearMessage();
Gotoxy(0,19);
cprintf("Error!age is NULL!Please Input age<10-20>.");
continue;
}
for(i=0;i<len;i++)
{
if(!(isdigit(tempage[i])))
{
ClearMessage();
Gotoxy(0,19);
cprintf("Error!Input illegal int.Please Input age<10-20>.");
getch();
Gotoxy(40,9);
printf("%*s",40," ");
Gotoxy(40,9);
tempage[0]='\0';
break;
}
}
k=atoi(tempage);
if(k>=10 && k<=20)
{
break;
}
else
{
ClearMessage();
Gotoxy(0,19);
cprintf("Error!Please Input age<10-20>.");
getch();
Gotoxy(40,9);
printf("%*s",40," ");
Gotoxy(40,9);
tempage[0]='\0';
continue;
}
if(i>=len)
break;
else
continue;
}while(1);
Gotoxy(40,9);
printf("%-d",k);
data.age=atoi(tempage);
//stu_link.studate.age=atoi(tempage);
}
/*****************************************************************
***函數名:AddScore
***參數:無
***功能:實現5門成績輸入、判斷是否合法
***返回值:無
*****************************************************************/
void AddScore()
{
char tempscore[7];
int j,len;
float k;
int i=0;
Gotoxy(40,10);
do
{
ClearMessage();
Gotoxy(0,19);
printf("Please Input <0.0-100.0> digit. <example:100>");
Gotoxy(40,10+i);
len=GetString(tempscore,5);
if(len==0)
{
ClearMessage();
Gotoxy(0,19);
printf("Error!age is NULL!Please Input score<0-100>.");
ClearMessage();
continue;
}
for(j=0;j<len;j++)
{
if(!(isdigit(tempscore[j])) || tempscore[j]=='.') //判斷是不是數字 或"."
{
ClearMessage();
Gotoxy(0,19);
printf("Error!Input illegal int.Please Input score<0-100>.");
getch();
Gotoxy(40,10+i);
printf("%*s",40," ");
Gotoxy(40,10+i);
tempscore[0]='\0';
break;
}
else
{
k=(float)atof(tempscore);
if(k>=0 && k<=100)
{
Gotoxy(40,10+i);
printf("%.1f",k);
data.score[i]=(float)atof(tempscore);
//stu_link.studate.score[i]=(float)atof(tempscore);
i++;
break;
}
else
{
ClearMessage();
Gotoxy(0,19);
printf("Error!Please Input score<0-100>.");
getch();
Gotoxy(40,10+i);
printf("%*s",40," ");
Gotoxy(40,10+i);
tempscore[0]='\0';
break;
}
}
}
if(i>=5)
break;
else
continue;
}while(1);
Gotoxy(0,19);
}
/*****************************************************************
***函數名:PrintData
***參數:無
***功能:實現數據打印、分頁
***返回值:無
*****************************************************************/
void PrintData()
{
int i,page=1,pages=10,totalpages; //page 頁碼 pages 每頁10條數據 totalpages總頁碼
int x,y;
char ch;
system("cls");
Gotoxy(28,3);
printf(PRINTDATA);
MakeMenuInfo();
Gotoxy(0,0);
do
{
Gotoxy(0,6);
for(i=6;i<18;i++) //清除6-17行
printf("%*s",80," ");
Gotoxy(0,5);
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);
if(count==0)
{
ClearMessage();
Gotoxy(0,19);
printf("Error!Data is NULL.");
printf("Pleased key to continue ...");
fflush(stdin);
getch();
return;
}
if(count<=pages)
totalpages=1;
else
if(count%pages==0)
totalpages=count/pages;
else
totalpages=count/pages+1;
if(totalpages==page) //一頁
{
for(i=(page-1)*pages;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];
avg[i]=(double)total[i]/5.0;
printf("%-4s%-21s%-5d%-8.1f%-7.1f%-7.1f%-8.1f%-8.1f%-6.1f%-4.1lf\n",stu[i].sno,stu[i].name,stu[i].age,
stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4],total[i],avg[i]);
}
}
else
{
for(i=(page-1)*pages;i<(page-1)*pages+pages;i++)
{
total[i]=stu[i].score[0]+stu[i].score[1]+stu[i].score[2]+stu[i].score[3]+stu[i].score[4];
avg[i]=(double)total[i]/5.0;
printf("%-4s%-21s%-5d%-8.1f%-7.1f%-7.1f%-8.1f%-8.1f%-6.1f%-4.1lf\n",stu[i].sno,stu[i].name,stu[i].age,
stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4],total[i],avg[i]);
}
}
fflush(stdin);
do
{
Gotoxy(20,17);
printf("Counts=%d Page[%d/%d]",count,page,totalpages);
Gotoxy(15,16);
printf("Press [U/u] PageUp%c [D/d] PageDown%c [Esc] Back %c:",24,25,27);
Getxy(&x,&y);
//[U]/[u] 85/117 [D]/[d] 68/100 [Esc] 27
ch=getche();
if(ch=='U' || ch=='u')
{
if(page==1)
{
ClearMessage();
Gotoxy(0,19);
printf("The First one page!");
getch();
Gotoxy(x+1,y);
printf("\b \b");
continue;
}
else
{
page--;
break;
}
}
else if(ch=='d' || ch=='D')
{
if(page==totalpages)
{
ClearMessage();
Gotoxy(0,19);
printf("The Last one page!");
getch();
Gotoxy(x+1,y);
printf("\b \b");
continue;
}
else
{
page++;
break;
}
}
else if(ch==27)
{
return;
}
else
{
ClearMessage();
Gotoxy(0,19);
printf("Error!Please enter again");
getch();
Gotoxy(x+1,y);
printf("\b \b");
continue;
}
}while(1);
}while(1);
}
/*****************************************************************
***函數名:Exit_Save
***參數:無
***功能:退出并詢問是否保存數據系統
***返回值:無
*****************************************************************/
void Exit_Save()
{
int x,y;
if(save_flag==1)
{
do
{
ClearMessage();
Gotoxy(0,19);
printf("Data is not save.Are you save Data(Yes/No/Cancel)?[Y]/[N]/[C]]");
Getxy(&x,&y);
Gotoxy(x,y);
ch=getche();
getch();
if(ch=='Y' || ch=='y')
{
SaveData();
break;
}
else if(ch=='N' || ch=='n')
{
Exit_System();
}
else if(ch=='C' || ch=='c')
return ;
else
{
ClearMessage();
Gotoxy(0,19);
printf("Error!Please enter again.");
getch();
continue;
}
}while(ch=='Y' || ch=='y');
}
else
{
Exit_System();
}
}
/*****************************************************************
***函數名:Exit_System
***參數:無
***功能:退出系統
***返回值:無
*****************************************************************/
void Exit_System()
{
do
{
ClearMessage();
Gotoxy(0,19);
printf("Are you exit system(Yes/No/Cancel)?[Y]/[N]/[C]]");
ch=getche();
getch();
if(ch=='Y' || ch=='y')
{
ClearMessage();
Gotoxy(0,19);
printf("Thanks You this system!");
exit(0);
}
else if(ch=='N' || ch=='n')
{
ClearMessage();
Gotoxy(0,19);
printf("Pleased key to continue ...");
getch();
return ;
}
else if(ch=='C' || ch=='c')
{
return ;
}
else
{
ClearMessage();
Gotoxy(0,19);
printf("Error!Please enter again.");
getch();
continue;
}
}while(1);
}
/*****************************************************************
***函數名:SearchData
***參數:無
***功能:實現學號與姓名查詢
***返回值:無
*****************************************************************/
void SearchData()
{
int i,s,x,y;
char *Search[]=
{ "1.sno select:",
"2.name select:",
"0.return MenuList:"
};
system("cls");
Gotoxy(32,3);
printf(SEARCH);
MakeMenuInfo();
Gotoxy(0,0);
Gotoxy(0,8);
s=JuZhong(Search,3); //菜單項--居中顯示
for(i=0;i<=2;i++) //打印菜單項
printf("%*s%s\n",s," ",Search[i]);
Gotoxy(26,14);
printf("Please Make a choices[0-2]:");
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
{
Gotoxy(x,y);
ch=getche();
getch();
switch(ch)
{
case '1':SearchSno();SearchData();break;
case '2':SearchName();SearchData();break;
case '0':return;break;
default:InputError(x,y,ch);continue;
}
}while(!(ch>='0' && ch<='2'));
}
/*****************************************************************
***函數名:SearchSno
***參數:無
***功能:實現學號查詢
***返回值:無
*****************************************************************/
void SearchSno()//學號查詢
{
int x,y,i,j,flag,t;
char no[5];
int num,len;// 記錄SNO;
Gotoxy(0,5);
for(i=5;i<18;i++) //清除5-17行
printf("%*s",80," ");
do
{
flag=0;
fflush(stdin);
Gotoxy(20,10);
printf("Please Input select no:");
Getxy(&x,&y);
Gotoxy(0,19);
printf("Please Input 0-9 digit. <example:001>");
Gotoxy(x,y);
gets(no);
len = strlen(no);
if(len==0)
{
ClearMessage();
Gotoxy(0,19);
printf("Error NULL!Please enter again!");
getch();
continue;
}
t=atoi(no);
sprintf(no,"%03d",t);
Gotoxy(20,10);
printf("Please wait!The system is searching...");
Sleep(300);
for(j=0;j<count;j++)
{
if(strcmp(no,stu[j].sno)==0) //找到記錄
{
flag=1;
num=atoi(no); //把NO轉化為INT型
Gotoxy(0,5);
for(i=5;i<18;i++) //清除5-17行
printf("%*s",80," ");
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");
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]);
ClearMessage();
Gotoxy(0,19);
printf("select ID:%-4d success!",t);
break;
}
else
continue;
}
if(!flag)
{
ClearMessage();
Gotoxy(0,19);
printf("sorry!not record!Pleased key to continue ...");
getch();
break;
}
do
{
Gotoxy(8,16);
printf("Press [U/u] Update [D/d] Delete [Y/y] Continue [Esc] Back:");
Getxy(&x,&y);
ch=getche();
Gotoxy(0,20);
printf("%*s",80," ");
if(ch=='U' || ch=='u')
{
UpdateData(num,x,y);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -