-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.cpp
More file actions
157 lines (140 loc) · 3.04 KB
/
Copy pathFunctions.cpp
File metadata and controls
157 lines (140 loc) · 3.04 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
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
#include <iostream>
#include <string>
int sum(const int&, const int&);
int sub(const int&, const int&);
int division(const int&, const int&);
int mult(const int&, const int&);
int mod(const int&, const int&);
double sum(const double&, const double&);
double sub(const double&, const double&);
double division(const double&, const double&);
double mult(const double&, const double&);
//ñ÷èòàåì, ÷òî ,áèíàðíûé îò 0 äî 99
enum Operation {
Sum,
Sub,
Division,
Mult,
Mod,
Exp,
};
Operation askForOperation();
bool isUnary(Operation);
double applyUnaryOperation(Operation, double x);
double applyBinaryOperation(Operation, double a, double b);
void printResult(double);
double askForNumber(const std::string&, int&);
double askForNumber(const std::string&, double&);
int main()
{
while (true) {
std::string var_type, operation;
std::cout << "Input type of numbers" << "\n";
std::cin >> var_type;
int numberOfOperation;
if (var_type == "int") {
Operation operation = askForOperation();
double result;
if (isUnary(operation)) {
double x;
askForNumber("Input the number", x);
result = applyUnaryOperation(operation, x);
} else {
double a;
a = askForNumber("Input the 1st number", a);
double b;
b = askForNumber("Input the 1st number", b);
}
}
}
return 0;
}
// int argument
int sum(const int& a, const int& b)
{
return a + b;
}
int sub(const int& a, const int& b)
{
return a - b;
}
int division(const int& a, const int& b)
{
return a / b;
}
int mult(const int& a, const int& b)
{
return a * b;
}
int mod(const int& a, const int& b)
{
return a % b;
}
// double argument
double sum(const double& a, const double& b)
{
return a + b;
}
double sub(const double& a, const double& b)
{
return a - b;
}
double division(const double& a, const double& b)
{
return a / b;
}
double mult(const double& a, const double& b)
{
return a * b;
}
Operation askForOperation()
{
std::string menu = "sum = 0 \n sub = 1 \n division = 2\n mult = 3 \n mod = 4\n exp = 5";
std::cout << "operation";
Operation operation;
int numberOfOperation;
std::cout << "Input operation.\n" << menu;
std::cin >> numberOfOperation;
//return (Operation)numberOfOperation;
return static_cast <Operation>(numberOfOperation);
}
bool isUnary(Operation operation)
{
if (operation > 99) {
return true;
}
return false;
}
double applyUnaryOperation(Operation, double x)
{
//TODO
}
double applyBinaryOperation(Operation operation, double a, double b)
{
//TODO
double result;
switch (operation)
{
case Sum: result = sum(a, b);
break;
case Sub: result = sub(a, b);
break;
case Mult: result = mult(a, b);
break;
case Division: result = division(a, b);
break;
}
}
void printResult(double)
{
}
double askForNumber(const std::string& label, int& arg)
{
std::cout << label;
std::cin >> arg;
}
double askForNumber(const std::string& label, double& arg)
{
std::cout << label;
std::cin >> arg;
}