aboutsummaryrefslogtreecommitdiff
path: root/week07/ex3.cpp
blob: a616dc3aad9393915f84d7796a9d975aa05f196a (plain) (blame)
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
#include <iostream>

double abs(double val) {
	return (val > 0) ? val : -val;
}

double square(double val) {
	return val * val;
}

double afterFloatingPoint(double val) {
	return val - (int)val;
}

double beforeFloatingPoint(double val) {
	return (int)val;
}

int main() {
	double (*useFunc)(double);
	char buf;
	std::cin >> buf;
	switch(buf) {
		case 'a': useFunc = &abs; break;
		case 's': useFunc = &square; break;
		case 'h': useFunc = &afterFloatingPoint; break;
		case 'f': useFunc = &beforeFloatingPoint; break;
	}

	for (int i = 0; i < 5; i++) {
		double temp;
		std::cin >> temp;
		std::cout << useFunc(temp) << " ";
	}
	std::cout << std::endl;
}