?? mis_sms(finish).c
字號:
/*
*********************************************************
* 頭文件
*********************************************************
*/
#include <stdio.h>
#include <windows.h>
#include <wincon.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/*
*********************************************************
* 常量
*********************************************************
*/
#define DEBUG
#define __0 0x60
#define _0 0x30
#define _1 0x31
#define _2 0x32
#define _3 0x33
#define _4 0x34
#define _5 0x35
#define _6 0x36
#define _7 0x37
#define _ESC 0x1B
#define _PAGEUP 0x49
#define _PAGEDOWN 0x51
#define _DELETE 0x53
#define _BACKSPACE 0x08
#define _ENTER 13
#define _HOME 71
#define _END 79
#define _INSERT 82
#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_LEFT 75
#define KEY_RIGHT 77
#define ERROR -3
#define STU_MAX 999 //學生最大上限
#define BACKMENU -1
#define INSERT_RECORD -1
#define MAKE_NEW_FILE -2
#define EMPTY -2
#define BACK 240
#define FOREGROUND_WHILE 0x000F
const int FILE_NAME_LIMIT = 8;
const int ISVALID_FILENAME_VALID= 1;
const int ISVALID_FILENAME_ERROR = -1;
const int ISVALID_FILENAME_EMPTY = -2;
const int ISVALID_FILENAME_OVERFLOW = -3;
const int ISVALID_FILENAME_ERRORDOT = -4;
/*
*********************************************************
* 變量
*********************************************************
*/
FILE *fp,*fp1;
char fn[20];
int savedatalabel=0; // 0 表示內(nèi)存中沒有數(shù)據(jù)
char loadfilename[9]={'\0'}; // 記錄載入的文件名,如果是新建的記錄,文件名為空
int filedatachange = -1;
int stu_count=1; //記錄學生數(shù)
int dataend=0;
int exitflag=0;
int searchflag=0;
int statflag = 0;
int sortway=3;
struct stu_info
{
char sno[6];
char sname[21];
int sage;
char schi[6];
char smath[6];
char seng[6];
char spho[6];
char sche[6];
};
typedef struct stu_info Stu_Info;
struct stu_lnode
{
struct stu_info data;
struct stu_lnode *next,*pre;
};
typedef struct stu_lnode Stu_Lnode;
Stu_Lnode *in,*head,*tail,*p,*temp,*temphead,*temptail;
/*
*********************************************************
* 函數(shù)原型
*********************************************************
*/
/*
*************************************************************
* 函數(shù)描述:定位光標位置的函數(shù)
* 輸入?yún)?shù):x,y 用于指定要定位到的坐標
* 返回值 :無
*************************************************************
*/
void GoToXY(int x, int y)
{
COORD pos = {x,y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); // 獲取標準輸出設備句柄
SetConsoleCursorPosition(hOut, pos);
}
void WhereXY(int *x, int *y)
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); // 獲取標準輸出設備句柄
COORD pos;
CONSOLE_SCREEN_BUFFER_INFO bInfo;
GetConsoleScreenBufferInfo( hOut, &bInfo );
pos = bInfo.dwCursorPosition;
*x = pos.X;
*y = pos.Y;
}
/*
*************************************************************
* 函數(shù)描述:在指定坐標畫矩形函數(shù)
* 輸入?yún)?shù):矩形左上角的X Y 坐標 矩形內(nèi)顯示的字符串
* 返回值 :無
*************************************************************
*/
void PrintRectangle(int x,int y,char *str)
{
int j=0,i,len,space;
len=strlen(str);
if (len%2 == 0)
space=(20-len)/2;
else
{
space=(21-len)/2;
j=1;
}
GoToXY(x,y);
printf("%c",218);
for (i=0;i<20+j;i++)
printf("%c",196);
printf("%c",191);
GoToXY(x,y+1);
printf("%c",179);
for (i=0;i<space;i++)
printf(" ");
printf("%s",str);
for (i=0;i<space;i++)
printf(" ");
printf("%c",179);
GoToXY(x,y+2);
printf("%c",192);
for (i=0;i<20+j;i++)
printf("%c",196);
printf("%c",217);
}
/*
*************************************************************
* 函數(shù)描述:信息添加界面繪制的函數(shù)
* 輸入?yún)?shù):自動生成的學號字符串
* 返回值 :無
*************************************************************
*/
void PrintSubjectMenu(char *stu_No)
{
GoToXY(15,3);
printf(" No:");
printf("%s",stu_No);
GoToXY(15,4);
printf(" Name:");
GoToXY(15,5);
printf(" Age:");
GoToXY(15,6);
printf(" Chinese Score:");
GoToXY(15,7);
printf(" English Score:");
GoToXY(15,8);
printf(" Math Score:");
GoToXY(15,9);
printf(" Phogric Score:");
GoToXY(15,10);
printf("Chemical Score:");
}
/*
*************************************************************
* 函數(shù)描述:計算總分的函數(shù)
* 輸入?yún)?shù):q 為結(jié)構(gòu)體指針,指向要統(tǒng)計的學生
* 返回值 :通過str 返回統(tǒng)計結(jié)構(gòu)
*************************************************************
*/
void CalculateTotal(Stu_Lnode *q,char str[5])
{
int len;
float total;
total=atof(q->data.schi)+atof(q->data.seng)+atof(q->data.smath)+atof(q->data.spho)+atof(q->data.sche);
sprintf(str,"%0.1f",total);
len=strlen(str);
if(str[len-1]!='0')
str[len-1]='5';
}
/*
*************************************************************
* 函數(shù)描述:計算平均分的函數(shù)
* 輸入?yún)?shù):同上
* 返回值 :同上
*************************************************************
*/
void CalculateAvg(Stu_Lnode *q,char str[5])
{
int len;
float savg;
savg=(atof(q->data.schi)+atof(q->data.seng)+atof(q->data.smath)+atof(q->data.spho)+atof(q->data.sche))/5.0;
sprintf(str,"%0.1f",savg);
len=strlen(str);
if(str[len-1]!='0')
str[len-1]='5';
}
/*
*************************************************************
* 函數(shù)描述:按學號和總分排序的函數(shù)
* 輸入?yún)?shù):排序方式 (4種)
* 返回值 :若沒有數(shù)據(jù)為空
*************************************************************
*/
int StructSort(int way)
{
int i,count=0,j;
char str1[5],str2[5];
Stu_Lnode *q;
Stu_Lnode *stemp = (Stu_Info *)malloc(sizeof(Stu_Info));
q=head;
if(q==NULL)
{
return EMPTY;
}
while(q!=tail)
{
count++; //計算節(jié)點
q=q->next;
}
if (count == 0)
return EMPTY;
q=head->next;
for(i=0;i<count;i++)
{
for (j=1;j<count-i;j++)
{
CalculateTotal(q,str1);
CalculateTotal(q->next,str2);
if(
(way==4 && atoi(q->data.sno) < atoi(q->next->data.sno))
||
(way==3 && atoi(q->data.sno) > atoi(q->next->data.sno))
||
(way==2 && atof(str1) < atof(str2))
||
(way==1 && atof(str1) > atof(str2))
)
{
memcpy(stemp,q,sizeof(Stu_Info));
memcpy(q,q->next,sizeof(Stu_Info));
memcpy(q->next,stemp,sizeof(Stu_Info));
}
q=q->next;
}
q=head->next;
}
}
/*
*************************************************************
* 函數(shù)描述:打印學生信息的函數(shù)
* 輸入?yún)?shù):同上
* 返回值 :同上
*************************************************************
*/
void PrintStudentRecord(Stu_Lnode *q,char *stotal,char *savg,int k)
{
int chil,engl,mathl,phyl,chel,totall,avgl,avgl_2;
int i;
chil=engl=mathl=phyl=chel=totall=avgl=avgl_2=32;
switch(k)
{
case 1:
chil=179;
break;
case 2:
engl=179;
break;
case 3:
mathl=179;
break;
case 4:
phyl=179;
break;
case 5:
chel=179;
break;
case 6:
totall=179;
break;
default :
break;
}
printf("%c %-4s%-21s%-3d%c%-5s%c%-7s%c%-4s%c%-7s%c%-8s%c%-5s%c%c%-5s\n",
179,q->data.sno,q->data.sname,q->data.sage,chil,q->data.schi,engl,q->data.seng,mathl,q->data.smath,phyl,q->data.spho,chel,q->data.sche,totall,stotal,avgl,avgl_2,savg);
}
int GetchKey()
{
int _key;
while(1)
{
_key=getch();
if(_key>200)
{
_key = getch();
break;
}
return _key;
}
return _key;
}
void ClearMassage()
{
int i,j;
for(i=0;i<4;i++)
{
GoToXY(1,18+i);
for (j=0;j<78;j++)
printf(" ");
}
}
/*
*************************************************************
* 函數(shù)描述:清除指定行的函數(shù)
* 輸入?yún)?shù):行首的X Y 坐標
* 返回值 :無
*************************************************************
*/
void Clear(int x,int y)
{
int i;
GoToXY(x,y);
for(i=0;i<78;i++)
printf(" ");
}
void SpaceAlert()
{
GoToXY(1,19);
printf("Alert , First character can't input \"Space\"");
Sleep(800);
Clear(1,19);
}
void PrintAlert(int top)
{
Clear(1,19);
GoToXY(1,19);
if (top>0 && top<10)
{
printf("Error---Please make choise between [0-%d]",top);
}
else
{
printf("Error---Please press key with [ENTER] and [ESC]");
}
GoToXY(1,20);
printf("Press any key to continue");
GetchKey();
ClearMassage();
}
int GetString(char *str,int lenlimit)
{
int key,i=0;
while (1)
{
key=GetchKey();
if (key == _ESC)
{
str[i]='\0';
return -1;
}
if (key==_BACKSPACE)
{
if (i==0)
{
continue;
}
else
{
printf("\b \b");
i--;
continue;
}
}
if (key==_ENTER)
{
str[i]='\0';
if (i==0)
{
return EMPTY;
}
return 1;
}
if (i==lenlimit)
{
continue;
}
if (isprint(key))
{
str[i]=key;
i++;
putchar(key);
continue;
}
}
}
int InputDataCheck(char *str,int lenlimit,int x,int y)
{
int xx,yy;
int space=0,front=0;
int i=0;
int stringisvalid=1 ;
while(1)
{
str[i]=GetchKey();
WhereXY(&xx,&yy);
if (str[0]==' ')
SpaceAlert();
if (xx==x+lenlimit)
{
while(1)
{
if(str[i]==_BACKSPACE || str[i] == _ENTER)
break;
str[i]=GetchKey();
}
}
if (xx!=x)
{
if (str[i]==' ')
{
GoToXY(x+i,y);
printf("%c",str[i]);
i++;
continue;
}
}
if (isdigit(str[i]))// || isalpha(str[i]) || str[i]=='.')
{
GoToXY(x+i,y);
printf("%c",str[i]);
}
else
{
if (str[i]==_BACKSPACE)
{
WhereXY(&xx,&yy); //定位光標
if (xx!=x) //如果不在第一個元素
{
str[--i]='\0';
printf("\b");
printf(" ");
printf("\b");
continue;
}
else //如果是第一個元素
{
GoToXY(x,y);
continue;
}
}
if(str[i] == _ENTER) //若是回車
{
WhereXY(&xx,&yy);
if (xx!=x) //不在第一個元素
{
str[i]='\0';
GoToXY(x,y);
printf("%s",str);
return 1;
}
else
return EMPTY;
}
else
GoToXY(x+i,y);
continue;
}
i++;
}
}
void ClearDisplay(int x,int y)
{
int i,j;
for (i=0;i<16;i++)
{
GoToXY(x,y+i);
for (j=0;j<78;j++)
printf(" ");
}
}
void ClearAll()
{
ClearMassage();
ClearDisplay(1,1);
}
void PrintRecordFrame(int k)
{
int chil,engl,mathl,phyl,chel,totall,avgl,avgl_2;
int i;
chil=engl=mathl=phyl=chel=totall=avgl=avgl_2=32;
switch(k)
{
case 1:
chil=engl=179;
break;
case 2:
engl=mathl=179;
break;
case 3:
mathl=phyl=179;
break;
case 4:
phyl=chel=179;
break;
case 5:
chel=totall=179;
break;
case 6:
totall=avgl_2=179;
break;
default :
break;
}
GoToXY(0,0);
printf("%c",218);
GoToXY(1,0);
for (i=0;i<78;i++)
printf("%c",196);
printf("%c",191);
GoToXY(0,1);
printf("%c No Name Age%cChina%cEnglish%cMath%cPhysics%cChemical%cTotal%c%cAvg %c\n",179,chil,engl,mathl,phyl,chel,totall,avgl,avgl_2,179);
GoToXY(0,2);
printf("%c",179);
for (i=0;i<78;i++)
printf("%c",196);
printf("%c",179);
GoToXY(0,3);
for (i=0;i<9;i++);
printf("%c",179);
GoToXY(0,13);
printf("%c",195);
for (i=0;i<78;i++)
printf("%c",196);
printf("%c",180);
//GoToXY(2,3);
}
void ClearPrintDisplayAll()
{
int i,j;
GoToXY(1,1);
for (i=0;i<12;i++)
{
for (j=0;j<78;j++)
printf(" ");
GoToXY(1,2+i);
}
for (i=0;i<3;i++)
{
GoToXY(1,14+i);
for (j=0;j<78;j++)
printf(" ");
}
}
void PrintSign(char *str,int yy)
{
GoToXY(1,yy);
printf(" ");
GoToXY(78,yy);
printf(" ");
if (strcmp("up",str)==0)
yy--;
if (strcmp("down",str)==0)
yy++;
GoToXY(1,yy);
printf("[");
GoToXY(78,yy);
printf("]");
}
ClearPrintDisplay()
{
int i,j;
GoToXY(1,3);
for (i=0;i<10;i++)
{
for (j=0;j<78;j++)
printf(" ");
GoToXY(1,4+i);
}
}
void PrintTopBorder()
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -