-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclsInputValidate copy.h
More file actions
141 lines (123 loc) · 3.82 KB
/
Copy pathclsInputValidate copy.h
File metadata and controls
141 lines (123 loc) · 3.82 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
// MIT License
// Copyright (c) 2025 Abiza Chiheb
// See the LICENSE file for full details.
#pragma once
#include <iostream>
#include <string>
#include "../String-library/clsString.h"
#include "../Date-library/clsDate.h"
class clsInputValidate
{
public:
static bool IsNumberBetween(short Number, short From, short To)
{
if (Number >= From && Number <= To)
return true;
else
return false;
}
static bool IsNumberBetween(int Number, int From, int To)
{
if (Number >= From && Number <= To)
return true;
else
return false;
}
static bool IsNumberBetween(double Number, double From, double To)
{
if (Number >= From && Number <= To)
return true;
else
return false;
}
static bool IsDateBetween(clsDate Date, clsDate From, clsDate To)
{
// Date>=From && Date<=To
if ((clsDate::IsDate1AfterDate2(Date, From) || clsDate::IsDate1EqualDate2(Date, From)) &&
(clsDate::IsDate1BeforeDate2(Date, To) || clsDate::IsDate1EqualDate2(Date, To)))
{
return true;
}
// Date>=To && Date<=From
if ((clsDate::IsDate1AfterDate2(Date, To) || clsDate::IsDate1EqualDate2(Date, To)) &&
(clsDate::IsDate1BeforeDate2(Date, From) || clsDate::IsDate1EqualDate2(Date, From)))
{
return true;
}
return false;
}
static int ReadIntNumber(string ErrorMessage = "Invalid Number, Enter again\n")
{
int Number;
while (!(cin >> Number))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << ErrorMessage;
}
return Number;
}
static int ReadIntNumberBetween(int From, int To, string ErrorMessage = "Number is not within range, Enter again:\n")
{
int Number = ReadIntNumber();
while (!IsNumberBetween(Number, From, To))
{
cout << ErrorMessage;
Number = ReadIntNumber();
}
return Number;
}
static double ReadFloatNumber(string ErrorMessage = "Invalid Number, Enter again\n")
{
float Number;
while (!(cin >> Number))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << ErrorMessage;
}
return Number;
}
static double ReadFloatNumberBetween(double From, double To, string ErrorMessage = "Number is not within range, Enter again:\n")
{
float Number = ReadFloatNumber();
while (!IsNumberBetween(Number, From, To))
{
cout << ErrorMessage;
Number = ReadDblNumber();
}
return Number;
}
static double ReadDblNumber(string ErrorMessage = "Invalid Number, Enter again\n")
{
double Number;
while (!(cin >> Number))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << ErrorMessage;
}
return Number;
}
static double ReadDblNumberBetween(double From, double To, string ErrorMessage = "Number is not within range, Enter again:\n")
{
double Number = ReadDblNumber();
while (!IsNumberBetween(Number, From, To))
{
cout << ErrorMessage;
Number = ReadDblNumber();
}
return Number;
}
static bool IsValideDate(clsDate Date)
{
return clsDate::IsValidDate(Date);
}
static string ReadString()
{
string S1 = "";
// Usage of std::ws will extract allthe whitespace character
getline(cin >> ws, S1);
return S1;
}
};