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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning(disable:4996)
 
typedef struct student
{
    char *name;
    int *kor;
    int *eng;
    int *mat;
    int *total;
    float *avg;
}STU;
void memalloc(STU **stu,int *num); //메모리할당
void input(STU *stu,int num); //입력
void output(STU *stu,int num); //출력
void del(STU *stu,int num); //메모리 삭제
void namesearch(STU *stu,int num); //이름검색
void scoresearch(STU *stu,int num); //성적검색
void repeat(STU *stu,int num);//반복
void repair(STU *stu,int num);//수정
 
const char *scoName[6]={"Name","Kor","Eng","Mat","Total","Avg"};
int main()
{
    STU *stu=NULL
    int num;
 
    memalloc(&stu,&num);
    input(stu,num);
    system("cls");
    repeat(stu,num);
    del(stu,num);
}
void input(STU *stu,int num)
{
 
    int name_num;
 
    for(int i=0;i<num;i++){
 
        printf("%s input: ",scoName[0]);
        scanf("%s",stu->name);
        printf("%s input: ",scoName[1]);
        scanf("%d",stu->kor);
        printf("%s input: ",scoName[2]);
        scanf("%d",stu->eng);
        printf("%s input: ",scoName[3]);
        scanf("%d",stu->mat);
 
        *stu->total = *stu->kor+*stu->eng+*stu->mat; 
        *stu->avg = *stu->total/3.f; 
 
        stu++;
 
    }
 
 
}
 
void memalloc(STU **stu,int *num)
{    
 
    printf("몇명?: ");
    scanf("%d",num);
 
 
    if(*stu == NULL)
    {
        *stu = (STU *)calloc(*num,sizeof(STU)); 
 
        for(int i=0;i < *num;i++)
        {
            (*stu+i)->name = (char*)calloc(10,sizeof(char));
            (*stu+i)->kor = (int *)calloc(1,sizeof(int));
            (*stu+i)->eng = (int *)calloc(1,sizeof(int));
            (*stu+i)->mat = (int *)calloc(1,sizeof(int));
            (*stu+i)->total = (int *)calloc(1,sizeof(int));
            (*stu+i)->avg = (float *)calloc(1,sizeof(float));
 
        }
 
    }
}
 
 
 
void output(STU *stu,int num)
{
 
 
    puts("");
    printf("============================\n");
    puts("");
    int i=0;
 
    for(i=0;i<6;i++)
    {
        printf("%s\t",scoName[i]);
    }
    puts("");
 
    for(i=0;i<num;i++)
    {
        printf("%s\t",stu->name);
        printf("%d\t",*stu->kor);
        printf("%d\t",*stu->eng);
        printf("%d\t",*stu->mat);
 
        printf("%d\t",*stu->total);
        printf("%f\n",*stu->avg);
 
        stu++;
    }
}
 
void del(STU *stu,int num)
{
    int i=0;
    for(i=0;i<num;i++)
    {    
        free((stu+i)->name);
        free((stu+i)->kor);
        free((stu+i)->eng);
        free((stu+i)->mat);
        free((stu+i)->total);
        free((stu+i)->avg);
    }
    free(stu);
}
 
 
void namesearch(STU *stu,int num)
{
    int i,j;
    char search[100];
    char q;
    do{
        printf("찾고자하는 이름을 입력하세요:");
        scanf("%s",&search);
        for (i=0;i<num;i++)
        {
            if (strcmp((stu+i)->name,search) == 0)
            {
                for(j=0;j<6;j++)
                {
                    printf("%s\t",scoName[j]);
                }
                puts("");
 
                printf("%s\t",(stu+i)->name);
                printf("%d\t",*(stu+i)->kor);
                printf("%d\t",*(stu+i)->eng);
                printf("%d\t",*(stu+i)->mat);
 
                printf("%d\t",*(stu+i)->total);
                printf("%f\n",*(stu+i)->avg);
 
                break;
 
            }
 
            if (i==num-1)
            {
                printf("검색결과가없습니다.\n");
                printf("이름을 다시 입력하시려면 y 입력, 종료하시려면 아무키나 누르세요:");
                fflush(stdin);
                scanf("%c",&q);
 
            }
 
 
 
        }
 
 
    }while(q=='y' || q=='Y');
}
 
 
 
void scoresearch(STU *stu,int num)
{
    char q;
    int i,j;
    float find;
    int k=0;
    printf("평균 몇점이상 검색할까요?:");
    scanf("%f",&find);
 
    for(i=0;i<num;i++)
    {
        do{
            if ( *((stu+i)->avg) >= find )
            {
                for(j=0;j<6;j++)
                {
                    printf("%s\t",scoName[j]);
                }
                puts("");
 
                printf("%s\t",(stu+i)->name);
                printf("%d\t",*(stu+i)->kor);
                printf("%d\t",*(stu+i)->eng);
                printf("%d\t",*(stu+i)->mat);
                printf("%d\t",*(stu+i)->total);
                printf("%f\n",*(stu+i)->avg);
                k++;
 
            }
 
            if(k==0)
            {
                printf("검색결과가없습니다.\n");
                printf("점수를 다시 입력하시려면 y, 종료하시려면 아무키나 누르세요:");
                fflush(stdin);
                scanf("%c",&q);
 
 
            }
 
 
        }while(q=='y' || q=='Y');
        break;
    }
}
 
 
 
void repeat(STU *stu,int num)
{
    int num2;
    char q;
 
    do{
        system("cls");
        num2=0;
        printf("처음 화면\n");
        printf("1.이름검색 2.점수검색 3.전체출력 4.수정 :");
        scanf("%d",&num2);
 
        switch(num2)
        {
 
        case 1:    namesearch(stu,num); break;
        case 2: scoresearch(stu,num); break;
        case 3: output(stu,num); break;
        case 4: repair(stu,num); break;
        defaultprintf("잘못입력하셨습니다."); break;
        }
 
        printf("\n처음화면으로 돌아가려면 y 입력, 종료하려면 아무키나 누르세요:");
        fflush(stdin);
        scanf("%c",&q);
    }while(q=='y' || q=='Y');
 
}
 
//수정
void repair(STU *stu,int num)
{
 
    int i;
    char search[100];
    char subject[100];
    char q;
    int k=0;
    do{
        printf("누구의 성적을 수정할까요?:");
        scanf("%s",&search);
 
        for (i=0;i<num;i++)
        {
            if (strcmp((stu+i)->name,search) == 0)
            {
                do{
                    printf("어떤 과목을 수정할까요?:");
                    scanf("%s",subject);
 
 
 
                    if(strcmp(scoName[1],subject)==0)
                    {
                        printf("현재 %s의 %s 성적:%d\n",search,scoName[1],*(stu+i)->kor);
                        printf("%s의 %s 성적을 몇점으로 수정할까요? :",search,scoName[1]);
                        scanf("%d",(stu+i)->kor);
                        printf("수정된 %s의 %s 성적:%d\n",search,scoName[1],*(stu+i)->kor);
                        break;
 
                    }
                    if(strcmp(scoName[2],subject)==0)
                    {
                        printf("현재 %s의 %s 성적:%d\n",search,scoName[2],*(stu+i)->eng);
                        printf("%s의 %s 성적을 몇점으로 수정할까요? :",search,scoName[2]);
                        scanf("%d",(stu+i)->eng);
                        printf("수정된 %s의 %s 성적:%d\n",search,scoName[2],*(stu+i)->eng);
                        break;
 
                    }
                    if(strcmp(scoName[3],subject)==0)
                    {
                        printf("현재 %s의 %s 성적:%d\n",search,scoName[3],*(stu+i)->mat);
                        printf("%s의 %s 성적을 몇점으로 수정할까요? :",search,scoName[3]);
                        scanf("%d",(stu+i)->mat);
                        printf("수정된 %s의 %s 성적:%d\n",search,scoName[3],*(stu+i)->mat);
                        break;
 
                    }
                    else 
                    {
                        printf("과목을 잘못 입력하셨습니다.\n");
                        printf("다시입력하시려면 y, 종료하시려면 아무키나 누르세요:");
                        fflush(stdin);
                        scanf("%c",&q);
 
                    }
 
                }while(q=='y'||q=='Y');
 
                k++;
                break;
            }
 
            if (k==0)
            {    
                printf("이름을 잘못 입력하셨습니다.\n");
                printf("다시 입력하시려면 y, 종료하시려면 아무키나 누르세요:");
                fflush(stdin);
                scanf("%c",&q);
                break;
 
            }
 
        }
    }while(q=='y'||q=='Y');
 
 
    for (i=0;i<num;i++)
    {
        *stu->total = *stu->kor+*stu->eng+*stu->mat; 
        *stu->avg = *stu->total/3.f; 
        stu++;
    }
}
 
 
 
cs


https://colorscripter.com/s/KdsRQBV

+ Recent posts