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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#pragma warning(disable: 4996)
 
typedef struct _items items;
struct _items
{
    //상품명          단가    개수       금액
    char item_name[20];
    int price; //가격
    int num; //팔린 개수
    int total;
    struct _itmes* next;
 
};
items* head, *tail;
 
void init_list(void)
{
    head = (items*)malloc(sizeof(items)); //왼쪽 기둥
    tail = (items*)malloc(sizeof(items)); // 오른쪽 기둥
    head->next = tail;
    tail->next = tail;
}
 
 
void print_List(void)
{
    items *wk;
    wk = head->next;
    while (wk != tail)
    {
        printf("제품명:%s 단가:%d 팔린개수:%d\n", wk->item_name, wk->price, wk->num);
        wk = wk->next;
    }
    printf("\n---------------------------------------------------------------------------------------------------\n");
 
}
 
items* find_List(char *data)
{
    items *wk;
    wk = head->next;
    int cnt = 1;
 
    while (strcmp(wk->item_name, data) && wk != tail)
    {
        wk = wk->next;
    }
 
    if (wk != tail)
    {
        //puts("성공");
    }
    else
    {
        puts("실패");
    }
    return wk;
}
 
 
void print_all()
{
    items *wk;
    int i = 1;
    wk = head->next;
 
    printf("============================================\n삼성전자 온라인  매출 현황\n== == == == == == == == == == == == == == == == == == == == == ==\n");
    printf("번호\t\t\t상품명\t단가\t판매개수\t금액\n");
    printf("-----------------------------------------------------\n");
 
    while (wk != tail)
    {
        printf("%d\t%20s\t%d\t%d\t%d\n", i, wk->item_name, wk->price, wk->num, wk->num*wk->price);
        wk = wk->next;
        i++;
    }
}
 
void print_all_k(items **k)
{
    int i = 0;
    printf("============================================\n삼성전자 온라인  매출 현황\n== == == == == == == == == == == == == == == == == == == == == ==\n");
    printf("번호\t\t\t상품명\t단가\t판매개수\t금액\n");
    printf("-----------------------------------------------------\n");
    for (i = 0; i < 19; i++)
 
    {
        printf("%d\t%20s\t%d\t%d\t%d\n", i + 1, k[i]->item_name, k[i]->price, k[i]->num, (k[i]->num) * (k[i]->price));
    }
}
 
void arrcopy(items **k)
{
    items *wk;
    int i = 0;
    wk = head->next;
    while (wk != tail)
    {
        k[i] = wk;
        wk = wk->next;
        i++;
    }
}
 
int sort_item_name(const void* a, const void* b) //이름 오름차순 
{
    return strcmp((*(items **)a)->item_name, (*(items **)b)->item_name);
}
 
int sort_item_name_2(const void* a, const void* b) // 이름 내림차순
{
    return strcmp((*(items **)b)->item_name, (*(items **)a)->item_name);
}
 
int sort_price(const void* a, const void* b) //단가 오름차순
{
    if (((*(items **)b)->price) > ((*(items **)a)->price)) return -1;
    if (((*(items **)b)->price) < ((*(items **)a)->price)) return 1;
    else return 0;
}
 
int sort_price2(const void* a, const void* b) //단가 내림차순
{
    if (((*(items **)b)->price) < ((*(items **)a)->price)) return -1;
    if (((*(items **)b)->price) > ((*(items **)a)->price)) return 1;
    else return 0;
}
 
int sort_num(const void* a, const void* b) //판매개수 오름차순
{
 
    if (((*(items **)b)->num) > ((*(items **)a)->num)) return -1;
    if (((*(items **)b)->num) < ((*(items **)a)->num)) return 1;
 
    else return 0;
}
 
int sort_num2(const void* a, const void* b) //판매개수 내림차순
{
 
    if (((*(items **)b)->num) < ((*(items **)a)->num)) return -1;
    if (((*(items **)b)->num) > ((*(items **)a)->num)) return 1;
    else return 0;
}
 
int sort_total(const void* a, const void* b) //판매금액 오름차순
{
    int total_a = (((*(items **)a)->price)*((*(items **)a)->num));
    int total_b = (((*(items **)b)->price)*((*(items **)b)->num));
    if (total_b < total_a) return -1;
    if (total_b > total_a) return 1;
    else return 0;
}
 
int sort_total2(const void* a, const void* b) //판매금액 내림차순
{
    int total_a = (((*(items **)a)->price)*((*(items **)a)->num));
    int total_b = (((*(items **)b)->price)*((*(items **)b)->num));
    if (total_b > total_a) return -1;
    if (total_b < total_a) return 1;
    else return 0;
}
 
void write(items **k)
{
    FILE *fp;
    int i = 0;
    fp = fopen("save.txt""w");
    while (k[i]->next != tail)
    {
        fprintf(fp, "%s %d %d %d\n", k[i]->item_name, k[i]->price, k[i]->num, (k[i]->num) * (k[i]->price));
        i++;
    }
    fclose(fp);
}
 
int main()
{
    items* k[20];
    items i;
    items * temp;
    FILE *fp;
    init_list();
 
    fp = fopen("item.txt""r");
 
    while (!feof(fp))
    {
        items *nw = (items*)malloc(sizeof(items));
        nw->next = head->next;
        head->next = nw;
        fscanf(fp, "%s %d"&i.item_name, &i.price);
        strcpy(nw->item_name, i.item_name);
        nw->price = i.price;
        nw->num = 0;
 
    }
    fclose(fp);
 
    fp = fopen("sales.txt""r");
    while (!feof(fp))
    {
        fscanf(fp, "%s %d"&i.item_name, &i.num);
        temp = find_List(i.item_name);
        temp->num = i.num;
        temp->total = temp->num * temp->price;
    }
 
    fclose(fp);
 
    arrcopy(k);
 
    int q = 0;
    int q2 = 0;
    char search[20];
    while (1) {
        printf("=====  M E N U  =====\n");
        printf("1.매출현황 출력\n");
        printf("2.매출현황 내보내기\n");
        printf("3.상품 찾기\n");
        printf("4.상품 삭제(구현X)\n");
        printf("5.매출현황 배열 (구현X)\n");
        printf("6.정렬\n");
        printf("7.종료\n");
        scanf("%d"&q);
        switch (q)
        {
        case 1: print_all(); break;
        case 2: write(k); break;
        case 3:
            printf("검색 상품 입력:");
            scanf("%s", search);
            temp = find_List(search);
            printf("============================================\n삼성전자 온라인  매출 현황\n== == == == == == == == == == == == == == == == == == == == == ==\n");
            printf("상품명\t단가\t판매개수\t금액\n");
            printf("-----------------------------------------------------\n");
            printf("%s\t%d\t%d\t%d\n", temp->item_name, temp->price, temp->num, temp->num*temp->price);
            break;
        case 6:
            printf("정렬기준을 선택하시오\n");
            printf("(상품명=0, 단가=1, 판매개수=2, 판매금액=3):");
            scanf("%d"&q);
            printf("정렬방법을 선택하시오.\n(오름차순=0, 내림차순=1):");
            scanf("%d"&q2);
 
            switch (q2)
            {
            case 0:
                if (q == 0)
                {
                    qsort(k, 19sizeof(items*), sort_item_name);  print_all_k(k);
                }
                if (q == 1)
                {
                    qsort(k, 19sizeof(items*), sort_price);  print_all_k(k);
                }
 
                if (q == 2)
                {
                    qsort(k, 19sizeof(items*), sort_num);  print_all_k(k);
                }
 
                if (q == 3)
                {
                    qsort(k, 19sizeof(items*), sort_total);  print_all_k(k);
                }
                break;
            case 1:
                if (q == 0)
                {
                    qsort(k, 19sizeof(items*), sort_item_name_2);  print_all_k(k);
                }
                if (q == 1)
                {
                    qsort(k, 19sizeof(items*), sort_price2);  print_all_k(k);
                }
                if (q == 2)
                {
                    qsort(k, 19sizeof(items*), sort_num2);  print_all_k(k);
                }
                if (q == 3)
                {
                    qsort(k, 19sizeof(items*), sort_total2);  print_all_k(k);
                }
                break;
            default:
                break;
            }
            break;
        case 7return 0;
        default:
            break;
        }
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

+ Recent posts