-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculatingwithFunctions.cpp
More file actions
61 lines (54 loc) · 2.15 KB
/
CalculatingwithFunctions.cpp
File metadata and controls
61 lines (54 loc) · 2.15 KB
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
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include <string>
#include <sstream>
#include <climits>
#include<iomanip>
/* */
// Number functions
auto zero(auto op = nullptr) { return op ? op(0) : 0; }
auto one(auto op = nullptr) { return op ? op(1) : 1; }
auto two(auto op = nullptr) { return op ? op(2) : 2; }
auto three(auto op = nullptr) { return op ? op(3) : 3; }
auto four(auto op = nullptr) { return op ? op(4) : 4; }
auto five(auto op = nullptr) { return op ? op(5) : 5; }
auto six(auto op = nullptr) { return op ? op(6) : 6; }
auto seven(auto op = nullptr) { return op ? op(7) : 7; }
auto eight(auto op = nullptr) { return op ? op(8) : 8; }
auto nine(auto op = nullptr) { return op ? op(9) : 9; }
// Operation functions
auto plus(int right) { return [=](int left) { return left + right; }; }
auto minus(int right) { return [=](int left) { return left - right; }; }
auto times(int right) { return [=](int left) { return left * right; }; }
auto divided_by(int right) { return [=](int left) { return left / right; }; }
int main()
{
seven(times(five()));
return 0;
}
/*Description:
This time we want to write calculations using functions and get the results. Let's have a look at some examples:
seven(times(five())); // must return 35
four(plus(nine())); // must return 13
eight(minus(three())); // must return 5
six(divided_by(two())); // must return 3
Requirements:
There must be a function for each number from 0 ("zero") to 9 ("nine")
There must be a function for each of the following mathematical operations: plus, minus, times, divided_by
Each calculation consist of exactly one operation and two numbers
The most outer function represents the left operand, the most inner function represents the right operand
Division should be integer division. For example, this should return 2, not 2.666666...:
eight(divided_by(three()));
Functional Programming*/
// /> フ
// | n n 彡
// /`ミ_xノ
// / |
// / ヽ ノ
// │ | | |
// / ̄| | | |
// | ( ̄ヽ__ヽ_)__)
// \二つ
// ITS CAT FOR YOU