-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckint.cpp
76 lines (70 loc) · 1.69 KB
/
checkint.cpp
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
#include "checkint.h"
bool checkInt::inputYear(int num)
{
try
{
checkYear(num);
}
catch(ArgumentException ex)
{
qDebug() << "Error message: " << ex.what();
qDebug() << "Error code: " << ex.GetErrorCode();
return false;
}
return true;
}
bool checkInt::inputMileage(int num)
{
try
{
checkMileage(num);
}
catch(ArgumentException ex)
{
qDebug() << "Error message: " << ex.what();
qDebug() << "Error code: " << ex.GetErrorCode();
return false;
}
return true;
}
bool checkInt::inputPrice(int num)
{
try
{
checkPrice(num);
}
catch(ArgumentException ex)
{
qDebug() << "Error message: " << ex.what();
qDebug() << "Error code: " << ex.GetErrorCode();
return false;
}
return true;
}
void checkInt::checkYear(int num)
{
if(num == 0)
throw ArgumentException("parameter is not integer.");
if(num == INT_MAX)
throw ArgumentException("parametr is overflow");
if(num < 1900 || num > 2022)
throw ArgumentException("parameter out of range.");
}
void checkInt::checkMileage(int num)
{
if(num == 0)
throw ArgumentException("parameter is not integer.");
if(num == INT_MAX)
throw ArgumentException("parametr is overflow");
if(num < 1 || num > 1500000)
throw ArgumentException("parameter out of range.");
}
void checkInt::checkPrice(int num)
{
if(num == 0)
throw ArgumentException("parameter is not integer.");
if(num == INT_MAX)
throw ArgumentException("parametr is overflow");
if(num < 1 || num > 1000000)
throw ArgumentException("parameter out of range.");
}