-
Notifications
You must be signed in to change notification settings - Fork 2
/
jceDates.cpp
60 lines (57 loc) · 1.31 KB
/
jceDates.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
#include "jceDates.h"
#include <sstream> //to_string function
template <typename T>
std::string to_string(T value)
{
std::ostringstream os;
os << value;
return os.str();
}
jceDates::jceDates()
{
//defaul choises.
this->fSemester = "0";
this->fYear = "2010";
this->tSemester = "2";
this->tYear = "2014";
}
void jceDates::setDate()
{
int fy,fs,ty,ts;
while (true) {
system("clear");
std::cout << "\n----------------jce API alpha----------------" << std::endl;
std::cout << "\tplease specify the date" << std::endl;
std::cout << "\t\tFrom year: ";
std::cin >> fy;
std::cout << "\t\tFrom semester: ";
std::cin >> fs;
std::cout << "\t\tTo year: ";
std::cin >> ty;
std::cout << "\t\tTo semester: ";
std::cin >> ts;
if (!(checkSemesterInput(ts) && checkSemesterInput(fs)
&& checkYearInput(fy) && checkYearInput(ty)))
printf("your input is out of range.\n please try again.");
else
{
this->fSemester = to_string(fs);
this->fYear = to_string(fy);
this->tSemester = to_string(ts);
this->tYear = to_string(ty);
break;
}
}
}
bool jceDates::checkSemesterInput(int num)
{
if ((num > 3) || (num < 0)) //out of semester range
return false;
return true;
}
bool jceDates::checkYearInput(int num)
{
if ((num > 2020) || (num < 2000)) //out of year range
return false;
return true;
}