1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#include "MyInclude.h"
#define MAX_STUDENT_NUM 60
typedef struct{
int number;
TCHAR name[10];
int kor;
int math;
int eng;
int tot;
float avg;
int rnk;
int *d1;
int *d2;
}STUDENT_SCORE;
extern int readDataAsNum(HWND hSrc, int *data);
extern void writeNumToEdit(HWND hDst, int *data, int dataNum);
void writeScoreNameToEdit(HWND hDst, STUDENT_SCORE *stdScore, int stdNum);
BOOL readScoreNameFromEdit(HWND hSrc, STUDENT_SCORE *stdScore, int *rtnStdNum);
void scoreCalculator(HWND hwnd, HWND hSrc, HWND hDst){
TCHAR buff[BUFF_SIZE];
DWORD fileSize;
char* tok;
int MAX_COL_NUM = 5;
int NUMPOS=0, KORPOS=1, MATHPOS=2, ENGPOS=3, TOTPOS=4;
int stdScore[MAX_STUDENT_NUM][MAX_COL_NUM], stdNum;
fileSize = GetWindowText(hSrc, buff, BUFF_SIZE);
buff[fileSize+1] = NULL;
stdNum = 0;
tok = strtok(buff, "\r\n");
while(tok != NULL){
sscanf(tok,"%d %d %d %d\r\n",&stdScore[stdNum][NUMPOS],&stdScore[stdNum][KORPOS],
&stdScore[stdNum][MATHPOS],&stdScore[stdNum][ENGPOS]);
tok = strtok(NULL, "\r\n");
stdNum++;
if(stdNum >= MAX_PRIME_NUM){
MessageBox(hwnd, "The number of students is out of the storage range.", "Arrangement grade processing.", MB_OK);
return;
}
}
for(int i=0; i<stdNum; i++){
stdScore[i][TOTPOS] = stdScore[i][KORPOS]+stdScore[i][MATHPOS]+stdScore[i][ENGPOS];
}
TCHAR str[MAX_DATA_NUM];
sprintf(buff,"%-s\t%-s\t%-s\t%-s\t%-s\t\r\n","Number","Kor","Math","Eng", "Total");
for(int i=0; i<stdNum; i++){
sprintf(str,"%-d\t%-d\t%-d\t%-d\t%-d\t\r\n", stdScore[i][NUMPOS],stdScore[i][KORPOS],
stdScore[i][MATHPOS],stdScore[i][ENGPOS],stdScore[i][TOTPOS]);
strcat(buff,str);
}
strcat(buff,"\r\n");
SetWindowText(hDst, buff);
}
void scoreCalculatorWithName(HWND hwnd, HWND hSrc, HWND hDst){
int stdNum;
STUDENT_SCORE stdScore[MAX_STUDENT_NUM];
if(readScoreNameFromEdit(hSrc, stdScore, &stdNum) == FALSE){
MessageBox(hwnd, "The number of students is out of the storage range.", "Structure grade processing.", MB_OK);
return;
};
for(int i=0; i<stdNum; i++){
stdScore[i].tot = stdScore[i].kor+stdScore[i].math+stdScore[i].eng;
stdScore[i].avg = (float)stdScore[i].tot/3;
}
for(int i=0; i<stdNum; i++){
stdScore[i].rnk = 1;
for(int j=0; j<stdNum; j++){
if(stdScore[i].tot < stdScore[j].tot)stdScore[i].rnk++;
}
}
writeScoreNameToEdit(hDst, stdScore, stdNum);
}
BOOL readScoreNameFromEdit(HWND hSrc, STUDENT_SCORE *stdScore, int *rtnStdNum){
TCHAR buff[BUFF_SIZE];
DWORD fileSize;
char *tok;
int stdNum = 0;
fileSize = GetWindowText(hSrc, buff, BUFF_SIZE);
buff[fileSize+1] = NULL;
tok = strtok(buff, "\r\n");
while(tok != NULL){
sscanf(tok,"%d %s %d %d %d\r\n", &stdScore[stdNum].number,&stdScore[stdNum].name,
&stdScore[stdNum].kor,&stdScore[stdNum].math,&stdScore[stdNum].eng);
tok = strtok(NULL, "\r\n");
stdNum++;
if(stdNum >= MAX_STUDENT_NUM){
return FALSE;
}
}
*rtnStdNum = stdNum;
return TRUE;
}
void writeScoreNameToEdit(HWND hDst, STUDENT_SCORE *stdScore, int stdNum){
TCHAR buff[BUFF_SIZE];
TCHAR str[MAX_DATA_NUM];
sprintf(buff,"%-s\t%-s\t%-s\t%-s\t%-s\t%-s\t%-s\t %-s \r\n",
"Number","name","Kor","Math","Eng","Total","Average","Rank");
for(int i=0; i<stdNum; i++){
sprintf(str,"%-d\t%-s\t%-d\t%-d\t%-d\t%-d\t%-.1f\t%-d\r\n",
stdScore[i].number, stdScore[i].name,
stdScore[i].kor, stdScore[i].math,stdScore[i].eng,
stdScore[i].tot, stdScore[i].avg,stdScore[i].rnk);
strcat(buff,str);
}
strcat (buff,"\r\n");
SetWindowText(hDst, buff);
}
| |