Skip to content

Commit 2a8f92e

Browse files
committed
Separated two files for two instructions (inputs + prints).
1 parent 193e090 commit 2a8f92e

File tree

4 files changed

+281
-0
lines changed

4 files changed

+281
-0
lines changed

src/Instructions/Inputs.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "Inputs.h"
2+
3+
namespace FPL::Instruction::Inputs {
4+
std::string returnInputFinalValue(FPL::Types::BUILTIN_TYPE& type, FPL::Data::Data& data) {
5+
std::string finalValue;
6+
if (type == FPL::Types::INT) {
7+
int v;
8+
std::cin >> v;
9+
finalValue = std::to_string(v);
10+
if (finalValue == "0" || v == 0) {
11+
inputTypeError(data);
12+
}
13+
std::cout << std::endl;
14+
} else if (type == FPL::Types::DOUBLE) {
15+
double v;
16+
std::cin >> v;
17+
finalValue = std::to_string(v);
18+
if (finalValue == "0" || v == 0) {
19+
inputTypeError(data);
20+
}
21+
std::cout << std::endl;
22+
} else {
23+
std::cin >> finalValue;
24+
}
25+
26+
return finalValue;
27+
}
28+
}

src/Instructions/Inputs.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include <iostream>
4+
#include <string>
5+
6+
#include "../Essentials/Types.h"
7+
#include "../Essentials/Utils/Data.h"
8+
#include "../Essentials/Utils/ErrorsCodeManagement.h"
9+
10+
namespace FPL::Instruction::Inputs {
11+
std::string returnInputFinalValue(FPL::Types::BUILTIN_TYPE& type, FPL::Data::Data& data);
12+
}

src/Instructions/Prints.cpp

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
#include "Prints.h"
2+
3+
namespace FPL::Instruction::Prints {
4+
void managementPrint_VARIABLE(FPL::Data::Data &data, FPL::VariableDef &var) {
5+
auto conditionOperator = ExpectConditionOperator(data);
6+
if (conditionOperator.has_value()) {
7+
auto conditionValue = ExpectValue(data);
8+
if (!conditionValue.has_value()) {needValueNextOperatorCondition(data);}
9+
10+
if (conditionOperator == "=") {
11+
if (var.VariableType.Type == Types::INT) {
12+
int varV = stringToInt(var.VariableValue, "");
13+
int condV = stringToInt(conditionValue->StatementName, "");
14+
printWithOperatorCondition_INT("=", varV, condV);
15+
} else if (var.VariableType.Type == Types::DOUBLE) {
16+
double varV = stringToDouble(var.VariableValue, "");
17+
double condV = stringToDouble(conditionValue->StatementName, "");
18+
printWithOperatorCondition_DOUBLE("=", varV, condV);
19+
} else {
20+
wrongType(data);
21+
}
22+
} else if (conditionOperator == ">") {
23+
if (var.VariableType.Type == Types::INT) {
24+
int varV = stringToInt(var.VariableValue, "");
25+
int condV = stringToInt(conditionValue->StatementName, "");
26+
printWithOperatorCondition_INT(">", varV, condV);
27+
} else if (var.VariableType.Type == Types::DOUBLE) {
28+
double varV = stringToDouble(var.VariableValue, "");
29+
double condV = stringToDouble(conditionValue->StatementName, "");
30+
printWithOperatorCondition_DOUBLE(">", varV, condV);
31+
} else {
32+
wrongType(data);
33+
}
34+
} else if (conditionOperator == "<") {
35+
if (var.VariableType.Type == Types::INT) {
36+
int varV = stringToInt(var.VariableValue, "");
37+
int condV = stringToInt(conditionValue->StatementName, "");
38+
printWithOperatorCondition_INT("<", varV, condV);
39+
} else if (var.VariableType.Type == Types::DOUBLE) {
40+
double varV = stringToDouble(var.VariableValue, "");
41+
double condV = stringToDouble(conditionValue->StatementName, "");
42+
printWithOperatorCondition_DOUBLE("<", varV, condV);
43+
} else {
44+
wrongType(data);
45+
}
46+
} else if (conditionOperator == ">=") {
47+
if (var.VariableType.Type == Types::INT) {
48+
int varV = stringToInt(var.VariableValue, "");
49+
int condV = stringToInt(conditionValue->StatementName, "");
50+
printWithOperatorCondition_INT(">=", varV, condV);
51+
} else if (var.VariableType.Type == Types::DOUBLE) {
52+
double varV = stringToDouble(var.VariableValue, "");
53+
double condV = stringToDouble(conditionValue->StatementName, "");
54+
printWithOperatorCondition_DOUBLE(">=", varV, condV);
55+
} else {
56+
wrongType(data);
57+
}
58+
} else if (conditionOperator == "<=") {
59+
if (var.VariableType.Type == Types::INT) {
60+
int varV = stringToInt(var.VariableValue, "");
61+
int condV = stringToInt(conditionValue->StatementName, "");
62+
printWithOperatorCondition_INT("<=", varV, condV);
63+
} else if (var.VariableType.Type == Types::DOUBLE) {
64+
double varV = stringToDouble(var.VariableValue, "");
65+
double condV = stringToDouble(conditionValue->StatementName, "");
66+
printWithOperatorCondition_DOUBLE("<=", varV, condV);
67+
} else {
68+
wrongType(data);
69+
}
70+
}
71+
} else {
72+
std::cout << var.VariableValue;
73+
}
74+
}
75+
76+
void managementPrint_ARGUMENT(FPL::Data::Data &data, std::optional<FPL::FonctionArgumentDef> &arg) {
77+
auto conditionOperator = ExpectConditionOperator(data);
78+
if (conditionOperator.has_value()) {
79+
auto conditionValue = ExpectValue(data);
80+
if (!conditionValue.has_value()) {needValueNextOperatorCondition(data);}
81+
82+
if (conditionOperator == "=") {
83+
if (arg->ArgumentType.Type == Types::INT) {
84+
int varV = stringToInt(arg->ArgumentValue, "");
85+
int condV = stringToInt(conditionValue->StatementName, "");
86+
printWithOperatorCondition_INT("=", varV, condV);
87+
} else if (arg->ArgumentType.Type == Types::DOUBLE) {
88+
double varV = stringToDouble(arg->ArgumentValue, "");
89+
double condV = stringToDouble(conditionValue->StatementName, "");
90+
printWithOperatorCondition_DOUBLE("=", varV, condV);
91+
} else {
92+
wrongType(data);
93+
}
94+
} else if (conditionOperator == ">") {
95+
if (arg->ArgumentType.Type == Types::INT) {
96+
int varV = stringToInt(arg->ArgumentValue, "");
97+
int condV = stringToInt(conditionValue->StatementName, "");
98+
printWithOperatorCondition_INT(">", varV, condV);
99+
} else if (arg->ArgumentType.Type == Types::DOUBLE) {
100+
double varV = stringToDouble(arg->ArgumentValue, "");
101+
double condV = stringToDouble(conditionValue->StatementName, "");
102+
printWithOperatorCondition_DOUBLE(">", varV, condV);
103+
} else {
104+
wrongType(data);
105+
}
106+
} else if (conditionOperator == "<") {
107+
if (arg->ArgumentType.Type == Types::INT) {
108+
int varV = stringToInt(arg->ArgumentValue, "");
109+
int condV = stringToInt(conditionValue->StatementName, "");
110+
printWithOperatorCondition_INT("<", varV, condV);
111+
} else if (arg->ArgumentType.Type == Types::DOUBLE) {
112+
double varV = stringToDouble(arg->ArgumentValue, "");
113+
double condV = stringToDouble(conditionValue->StatementName, "");
114+
printWithOperatorCondition_DOUBLE("<", varV, condV);
115+
} else {
116+
wrongType(data);
117+
}
118+
} else if (conditionOperator == ">=") {
119+
if (arg->ArgumentType.Type == Types::INT) {
120+
int varV = stringToInt(arg->ArgumentValue, "");
121+
int condV = stringToInt(conditionValue->StatementName, "");
122+
printWithOperatorCondition_INT(">=", varV, condV);
123+
} else if (arg->ArgumentType.Type == Types::DOUBLE) {
124+
double varV = stringToDouble(arg->ArgumentValue, "");
125+
double condV = stringToDouble(conditionValue->StatementName, "");
126+
printWithOperatorCondition_DOUBLE(">=", varV, condV);
127+
} else {
128+
wrongType(data);
129+
}
130+
} else if (conditionOperator == "<=") {
131+
if (arg->ArgumentType.Type == Types::INT) {
132+
int varV = stringToInt(arg->ArgumentValue, "");
133+
int condV = stringToInt(conditionValue->StatementName, "");
134+
printWithOperatorCondition_INT("<=", varV, condV);
135+
} else if (arg->ArgumentType.Type == Types::DOUBLE) {
136+
double varV = stringToDouble(arg->ArgumentValue, "");
137+
double condV = stringToDouble(conditionValue->StatementName, "");
138+
printWithOperatorCondition_DOUBLE("<=", varV, condV);
139+
} else {
140+
wrongType(data);
141+
}
142+
}
143+
} else {
144+
std::cout << arg->ArgumentValue;
145+
}
146+
}
147+
148+
void printWithOperatorCondition_INT(std::string_view currOP, int a, int b) {
149+
if (currOP == "=") {
150+
if (a == b) {
151+
std::cout << "vrai";
152+
} else {
153+
std::cout << "faux";
154+
}
155+
} else if (currOP == "<") {
156+
if (a < b) {
157+
std::cout << "vrai";
158+
} else {
159+
std::cout << "faux";
160+
}
161+
} else if (currOP == ">") {
162+
if (a > b) {
163+
std::cout << "vrai";
164+
} else {
165+
std::cout << "faux";
166+
}
167+
} else if (currOP == ">=") {
168+
if (a >= b) {
169+
std::cout << "vrai";
170+
} else {
171+
std::cout << "faux";
172+
}
173+
} else if (currOP == "<=") {
174+
if (a <= b) {
175+
std::cout << "vrai";
176+
} else {
177+
std::cout << "faux";
178+
}
179+
}
180+
}
181+
182+
void printWithOperatorCondition_DOUBLE(std::string_view currOP, double a, double b) {
183+
if (currOP == "=") {
184+
if (a == b) {
185+
std::cout << "vrai";
186+
} else {
187+
std::cout << "faux";
188+
}
189+
} else if (currOP == "<") {
190+
if (a < b) {
191+
std::cout << "vrai";
192+
} else {
193+
std::cout << "faux";
194+
}
195+
} else if (currOP == ">") {
196+
if (a > b) {
197+
std::cout << "vrai";
198+
} else {
199+
std::cout << "faux";
200+
}
201+
} else if (currOP == ">=") {
202+
if (a >= b) {
203+
std::cout << "vrai";
204+
} else {
205+
std::cout << "faux";
206+
}
207+
} else if (currOP == "<=") {
208+
if (a <= b) {
209+
std::cout << "vrai";
210+
} else {
211+
std::cout << "faux";
212+
}
213+
}
214+
}
215+
}

src/Instructions/Prints.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include <iostream>
4+
#include <string>
5+
#include <vector>
6+
#include <map>
7+
#include <optional>
8+
#include <sstream>
9+
#include <iterator>
10+
#include <algorithm>
11+
12+
#include "../Essentials/Utils/Data.h"
13+
#include "../Essentials/Utils/ErrorsCodeManagement.h"
14+
#include "../Essentials/Utils/Expecter.h"
15+
16+
#include "../Essentials/Definitions/Fonction.h"
17+
#include "../Essentials/Definitions/Variables.h"
18+
19+
#include "../Essentials/MathUtils/Converts.h"
20+
21+
namespace FPL::Instruction::Prints {
22+
void printWithOperatorCondition_INT(std::string_view currOP, int a, int b);
23+
void printWithOperatorCondition_DOUBLE(std::string_view currOP, double a, double b);
24+
void managementPrint_VARIABLE(FPL::Data::Data &data, FPL::VariableDef &var);
25+
void managementPrint_ARGUMENT(FPL::Data::Data &data, std::optional<FPL::FonctionArgumentDef> &arg);
26+
}

0 commit comments

Comments
 (0)