Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <string>
- #include <windows.h>
- #include <conio.h>
- #include <stdio.h>
- #include <cwchar>
- #include <winuser.h>
- #include <tchar.h>
- using namespace std;
- // ==========ПЕРЕМЕЩЕНИЕ КУРСОРА НА ВЫБРАННУЮ ПОЗИЦИЮ==========
- void gotoxy(int xpos, int ypos)
- {
- COORD scrn;
- HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);
- scrn.X = xpos; scrn.Y = ypos;
- SetConsoleCursorPosition(hOuput, scrn);
- }
- bool valid_date(int _Year, int _Month, int _DayNo)
- {
- int days_in_month[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
- if (_Year % 4 == 0)
- days_in_month[2] = 29;
- if ((_Month < 1) || (_Month > 12))
- return false;
- if ((_DayNo < 1) || (_DayNo > days_in_month[_Month]))
- return false;
- return true;
- }
- int main()
- {
- int length = 0;
- int pospos = 0;
- int posarrays[8] = { 0, 1, 3, 4, 6, 7, 8, 9 };
- int pos = posarrays[pospos];
- string mask1 = "__.__.____";
- cout << mask1;
- while (length != 8) {
- int ch = _getch();
- if (ch == 8 && length != 0) {
- length--;
- mask1[pos - ((length == 3 || length == 1) ? 2 : 1)] = '_'; // пропускаем точки
- gotoxy(0, 0);
- pospos--;
- pos = posarrays[pospos];
- cout << mask1;
- } else if (ch >= '0' && ch <= '9') {
- length++;
- mask1[pos] = ch;
- gotoxy(0, 0);
- pospos++;
- pos = posarrays[pospos];
- cout << mask1;
- }
- }
- string d = mask1.substr(0, 2);
- string m = mask1.substr(3, 2);
- string y = mask1.substr(6, 4);
- if (valid_date(stoi(y), stoi(m), stoi(d))) {
- cout << "ok";
- }
- else cout << "error";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement