diff options
| author | Syndamia <kamen@syndamia.com> | 2023-12-03 15:28:54 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2023-12-03 15:28:54 +0200 |
| commit | b7f2b4797f8578bc23141399cfd93d4f22fbc206 (patch) | |
| tree | a5bcf4cded17b7e4056a66d1534df2464065de1a /week07/ex3.cpp | |
| parent | 0996e05988b5d38faba0f616f06e6dcc7466930e (diff) | |
| download | upp-2023-solutions-b7f2b4797f8578bc23141399cfd93d4f22fbc206.tar upp-2023-solutions-b7f2b4797f8578bc23141399cfd93d4f22fbc206.tar.gz upp-2023-solutions-b7f2b4797f8578bc23141399cfd93d4f22fbc206.zip | |
[w7] Solved simpler exercises
Diffstat (limited to 'week07/ex3.cpp')
| -rw-r--r-- | week07/ex3.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/week07/ex3.cpp b/week07/ex3.cpp new file mode 100644 index 0000000..a616dc3 --- /dev/null +++ b/week07/ex3.cpp @@ -0,0 +1,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 = □ 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; +} |
