- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
#include <iostream>
using namespace std;
const char _Arr_Digit [] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'},
_Arr_Mantissa [] = {'e', 'E'},
_Arr_Sign [] = {'-', '+'},
_Arr_Dot[] = {'.'},
_Arr_Combo[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.'};
const bool DIGIT = false, SIGN = false, OTHER = true;
bool _Call_Mantissa = false, _flag_dot = false, _flag_mant = false;
int _position_mant;
bool Parse_symbol (char _symb, const char* _Arr, int _size_arr);
bool Parse_full_string (string _checking, int _offset, int _amount, bool _sec_cond, const char* _Arr, int _size_arr, bool _Drive);
bool Parse_the_first_symbol (string _checking);
bool Parse_the_second_symbol (string _checking);
bool Control_result (int i, string _checking);
bool Parse_mantissa (string _checking);
bool Parse_full_string_before_mantissa (int i, string _checking);
bool Parse_the_first_symbol_after_mantissa (string _checking);
bool Parse_full_string_after_mantissa (string _checking);
long double Questioning (char s);
long double Questioning (char s) {
string _checking;
while (true) {
cout << "Введите значение " << s << ": ";
getline(cin, _checking);
if (_checking.length() == 0)
cout << "Вы не ввели значение!" << endl;
else if (!Parse_the_first_symbol(_checking))
cout << "Некорректное значение!" << endl;
else return strtold(_checking.c_str(), nullptr); }}
bool Parse_symbol (char _symb, const char* _Arr, int _size_arr) {
for (int i = 0; i <= _size_arr; i++)
if (_symb == _Arr[i]) return true;
return false; }
bool Parse_full_string (string _checking, int _offset, int _amount, bool _sec_cond, const char* _Arr, int _size_arr, bool _Drive) {
bool _parse_flag;
int _parse_count = 0;
for (int j = _offset; j < _amount; j++) {
if (Parse_symbol(_checking[j], _Arr, _size_arr)) {
_parse_count++;
if (_sec_cond) return false;
if (_Drive) {
if (_Call_Mantissa)
_sec_cond = (j == (_amount-1));
if (_parse_flag) return false;
_parse_flag = true;
if (_Call_Mantissa) {
_flag_mant = _parse_flag;
_position_mant = j;
}
}
}
}
if (!_Drive) {
if ((_amount - _offset) == _parse_count) return true;
else return false;
}
else return true;
}
bool Parse_the_first_symbol (string _checking) {
int LENGTH = _checking.length();
bool _parse_cond = (LENGTH < 2);
if (Parse_full_string (_checking, 0, 1, _parse_cond, _Arr_Sign, 1, SIGN))
return Parse_the_second_symbol (_checking);
else if (Parse_full_string (_checking, 0, 1, false, _Arr_Digit, 9, DIGIT))
return Control_result (0, _checking);
else return false; }
bool Parse_the_second_symbol (string _checking) {
if (Parse_full_string (_checking, 1, 2, false, _Arr_Digit, 9, DIGIT))
return Control_result (1, _checking);
else return false; }
bool Control_result (int i, string _checking) {
if (!Parse_mantissa (_checking)) return false;
else if (_flag_mant) {
string _before_mantissa = _checking.substr(0, _position_mant);
string _after_mantissa = _checking.substr(_position_mant + 1);
return (Parse_full_string_before_mantissa (i, _before_mantissa)
&& Parse_the_first_symbol_after_mantissa (_after_mantissa)); }
else return Parse_full_string_before_mantissa (i, _checking); }
bool Parse_mantissa (string _checking) {
int LENGTH = _checking.length();
_Call_Mantissa = true;
bool cash = Parse_full_string (_checking, 0, LENGTH, false, _Arr_Mantissa, 1, OTHER);
_Call_Mantissa = false;
return cash; }
bool Parse_full_string_before_mantissa (int i, string _checking) { // but the first symbol
int LENGTH = _checking.length();
return Parse_full_string (_checking, i, LENGTH, false, _Arr_Dot, 0, OTHER) &&
Parse_full_string (_checking, i, LENGTH, false, _Arr_Combo, 10, DIGIT); }
bool Parse_the_first_symbol_after_mantissa (string _checking) {
int LENGTH = _checking.length();
bool _parse_cond = (LENGTH < 2);
if ((Parse_full_string (_checking, 0, 1, _parse_cond, _Arr_Sign, 1, SIGN)) ||
(Parse_full_string (_checking, 0, 1, false, _Arr_Digit, 9, DIGIT)))
return Parse_full_string_after_mantissa (_checking);
else return false; }
bool Parse_full_string_after_mantissa (string _checking) {
int LENGTH = _checking.length();
return Parse_full_string (_checking, 1, LENGTH, false, _Arr_Digit, 9, DIGIT); }