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
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#define loop(v, lo, hi) for((v)=(lo); (v)<(hi); (v)++)
int sum(int a, int b) { return a + b; }
int sub(int a, int b) { return a - b; }
int multi(int a, int b) { return a * b; }
int divv(int a, int b) { return a / b; }
int mod(int a, int b) { return a % b; }
// calculator3과 typedef_calculator3이 동일한 동작을 하도록 FP, FPP를 typedef를 이용하여 작성하세요.
typedef int i;
typedef i fi();
typedef fi* pfi;
typedef pfi fpfi();
typedef fpfi* FP; // FP 작성
typedef FP* FPP; // FPP 작성
//// calculator3은 함수 포인터 배열을 매개변수로 받고 함수 포인터를 반환하는 함수
//// typedef_calculator3과 동일한 선언이 되도록 calculator3의 헤더 부분을 작성합니다.
//// typedef 사용금지
//void (*signal(int sig, void(*)(void)))(void);
int (*calculator3(int (**fp)(int,int),int arr_size))(int,int){
int low = 0;
int high = arr_size - 1;
int random_Num = (rand() % (high + 1)) + low; //난수 발생범위를 low에서 high 범위내에 출력되는 코드
return fp[random_Num];
}
FP typedef_calculator3(FPP fp, int arr_size) {
return calculator3(fp, arr_size);
}
//
//// calculator2는 함수 포인터 배열을 매개변수 받는 함수
//// calculator2 함수는 arr_size 범위내로 난수발샘
//// 사칙연산을 위한 피연산자는 11,7로 고정
//// 난수에 따라 함수 수행 후 출력
//// 수행된 함수 포인터를 반환함
//
int calculator2(FPP fp, char *optor, int arr_size) {
int random_Num;
int fir = 11, sec = 7;
int low = 0;
int high = arr_size - 1;
printf("난수 발생 범위 %d ~ %d\n", low, high);
random_Num = (rand() % (high + 1)) + low; //난수 발생범위를 low에서 high 범위내에 출력되는 코드
printf("난수 : %d\n", random_Num);
printf("함수 실행 : %d %c %d = %d\n", fir, optor[random_Num], sec, fp[random_Num](fir, sec));
return random_Num;
}
int typedef_calculator2(FPP fp, char* optor, int arr_size) {
return calculator2(fp, optor, arr_size);
}
//calculator는 함수 포인터 배열을 인수로 받는 함수
//fir와sec값으로 모든 사칙연산을 구현 출력하시오
int calculator(FPP fp, int arr_size) {
int dx;
char a;
int fir = 11, sec = 7;
for (int dx = 0; dx < arr_size; dx++) {
switch (dx)
{
case 0: a = '+'; break;
case 1: a = '-'; break;
case 2: a = '*'; break;
case 3: a = '/'; break;
case 4: a = '%'; break;
default:
break;
}
printf("%d %c %d = %d\n", fir, a, sec, (*fp[dx])(fir, sec));
}
puts("");
}
int typedef_calculator(FPP fp, int arr_size) {
return calculator(fp, arr_size);
}
int main(void) {
int(*fpa[])(int, int) = { sum, sub, multi, divv, mod }; // 1. fpa는 함수 포인터 배열
char optor[] = { '+', '-', '*', '/', '%' };
int dx;
srand(time(NULL));
// typedef 를 사용하지 않은 함수 호출
calculator(fpa, sizeof(fpa) / sizeof(fpa[0]));
calculator2(fpa, optor, sizeof(fpa) / sizeof(fpa[0]));
loop(dx, 0, 5)
{
Sleep(300);
printf("random RUN!! : %d\n", calculator3(fpa, sizeof(fpa) / sizeof(fpa[0]))(11, 7));
}
// typedef 를 사용한 함수 호출
typedef_calculator(fpa, sizeof(fpa) / sizeof(fpa[0]));
typedef_calculator2(fpa, optor, sizeof(fpa) / sizeof(fpa[0]));
loop(dx, 0, 5)
{
Sleep(300);
printf("random RUN!! : %d\n", typedef_calculator3(fpa, sizeof(fpa) / sizeof(fpa[0]))(11, 7));
}
}
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 |
'딥러닝 기반 영상인식 개발 전문가 과정 > 리눅스' 카테고리의 다른 글
5월 27일 VIM (0) | 2019.05.27 |
---|---|
5월25일 리눅스 실습들 (0) | 2019.05.25 |
5월23일 여러가지 소스코드들 (0) | 2019.05.23 |
5월 23일 명령어 history (0) | 2019.05.22 |
5월 21일 history , 설명 (0) | 2019.05.21 |