123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <ctype.h>
- #include <stdlib.h>
- #include <time.h>
- #include <windows.h>
- #include <math.h>
- // Ãëîáàëüíûå ïåðåìåííûå äëÿ óïðàâëåíèÿ
- int hours = 0, minutes = 0, seconds = 0;
- int running = 1; // Ôëàã ðàáîòû ÷àñîâ
- int paused = 0; // Ôëàã ïàóçû
- HANDLE clockThread; // Äåñêðèïòîð ïîòîêà
- // Ôóíêöèÿ äëÿ óñòàíîâêè êóðñîðà â óêàçàííóþ ïîçèöèþ
- void setCursorPosition(int x, int y) {
- COORD coord;
- coord.X = x;
- coord.Y = y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
- }
- // Ôóíêöèÿ îòîáðàæåíèÿ âðåìåíè
- void displayTime() {
- setCursorPosition(0, 0);
- printf("Òåêóùåå âðåìÿ: %02d:%02d:%02d\n", hours, minutes, seconds);
- fflush(stdout);
- }
- // Ïîòîê äëÿ ÷àñîâ
- DWORD WINAPI clockFunction(LPVOID lpParam) {
- while (running) {
- if (!paused) {
- Sleep(1000); // Çàäåðæêà â 1 ñåêóíäó
- seconds++;
- if (seconds == 60) {
- seconds = 0;
- minutes++;
- if (minutes == 60) {
- minutes = 0;
- hours++;
- if (hours == 24) {
- hours = 0;
- }
- }
- }
- displayTime();
- }
- }
- return 0;
- }
- // Ôóíêöèÿ íàñòðîéêè âðåìåíè
- void setTime() {
- printf("\nÂâåäèòå ÷àñû: \n");
- scanf("%d", &hours);
- printf("Ââåäèòå ìèíóòû: \n");
- scanf("%d", &minutes);
- printf("Ââåäèòå ñåêóíäû: \n");
- scanf("%d", &seconds);
- displayTime();
- }
- // Ñåêóíäîìåð
- void stopwatch() {
- int sw_hours = 0, sw_minutes = 0, sw_seconds = 0;
- printf("\nÑåêóíäîìåð çàïóùåí. Íàæìèòå ëþáóþ êëàâèøó äëÿ îñòàíîâêè.\n");
- while (!kbhit()) {
- Sleep(1000);
- sw_seconds++;
- if (sw_seconds == 60) {
- sw_seconds = 0;
- sw_minutes++;
- if (sw_minutes == 60) {
- sw_minutes = 0;
- sw_hours++;
- }
- }
- setCursorPosition(0, 2);
- printf("\nÑåêóíäîìåð: %02d:%02d:%02d \n", sw_hours, sw_minutes, sw_seconds);
- fflush(stdout);
- }
- getchar(); // Îæèäàíèå íàæàòèÿ êëàâèøè
- setCursorPosition(0, 2);
- printf(" "); // Î÷èñòêà ñòðîêè
- }
- // Òàéìåð
- void timer() {
- int t_hours = 0, t_minutes = 0, t_seconds = 0;
- printf("\nÂâåäèòå âðåìÿ òàéìåðà (÷àñû, ìèíóòû, ñåêóíäû):\n");
- printf("×àñû: \n");
- scanf("%d", &t_hours);
- printf("Ìèíóòû: \n");
- scanf("%d", &t_minutes);
- printf("Ñåêóíäû: \n");
- scanf("%d", &t_seconds);
- printf("\nÒàéìåð çàïóùåí.\n");
- while (t_hours > 0 || t_minutes > 0 || t_seconds > 0) {
- Sleep(1000);
- if (t_seconds > 0) {
- t_seconds--;
- }
- else {
- t_seconds = 59;
- if (t_minutes > 0) {
- t_minutes--;
- }
- else {
- t_minutes = 59;
- if (t_hours > 0) {
- t_hours--;
- }
- }
- }
- setCursorPosition(0, 3);
- printf("Òàéìåð: %02d:%02d:%02d \n", t_hours, t_minutes, t_seconds);
- fflush(stdout);
- }
- printf("\nÒàéìåð çàâåðøåí!\n");
- setCursorPosition(0, 3);
- }
- // Îñíîâíàÿ ôóíêöèÿ
- int main() {
- system("chcp 1251>null");
- int choice;
- // Çàïóñê ïîòîêà ÷àñîâ
- clockThread = CreateThread(NULL, 0, clockFunction, NULL, 0, NULL);
- do {
- setCursorPosition(0, 5); // Ïåðåìåñòèòü êóðñîð ïîä ÷àñû
- printf("\nÌåíþ óïðàâëåíèÿ ÷àñàìè:\n");
- printf("1. Ïàóçà/Ïðîäîëæèòü\n");
- printf("2. Íàñòðîéêà âðåìåíè\n");
- printf("3. Ñåêóíäîìåð\n");
- printf("4. Òàéìåð\n");
- printf("5. Âûõîä\n");
- printf("\nÂûáåðèòå îïöèþ: ");
- scanf("%d", &choice);
- switch (choice) {
- case 1:
- paused = !paused;
- if (paused) {
- printf("\n×àñû íà ïàóçå.\n");
- }
- else {
- printf("\n×àñû ïðîäîëæàþò ðàáîòàòü.\n");
- }
- break;
- case 2:
- setTime();
- break;
- case 3:
- stopwatch();
- break;
- case 4:
- timer();
- break;
- case 5:
- running = 0;
- WaitForSingleObject(clockThread, INFINITE); // Îæèäàíèå çàâåðøåíèÿ ïîòîêà
- CloseHandle(clockThread);
- printf("\nÏðîãðàììà çàâåðøåíà.\n");
- break;
- default:
- printf("\nÍåâåðíûé âûáîð, ïîïðîáóéòå ñíîâà.\n");
- }
- } while (choice != 5);
- return 0;
- }
|