HomeDigital clock coding in c++ Digital clock coding in c++ byHimanshu Sharma •July 22, 2021 0 Digital Clock #include #include #include #include #include using namespace std; char d0[5][3] = { 178,178,178, 178,' ',178, 178,' ',178, 178,' ',178, 178,178,178 }; char d1[5][3] = { ' ',' ',178, ' ',' ',178, ' ',' ',178, ' ',' ',178, ' ',' ',178 }; char d2[5][3] = { 178,178,178, ' ',' ',178, 178,178,178, 178,' ',' ', 178,178,178 }; char d3[5][3] = { 178,178,178, ' ',' ',178, 178,178,178, ' ',' ',178, 178,178,178 }; char d4[5][3] = { 178,' ',178, 178,' ',178, 178,178,178, ' ',' ',178, ' ',' ',178 }; char d5[5][3] = { 178,178,178, 178,' ',' ', 178,178,178, ' ',' ',178, 178,178,178 }; char d6[5][3] = { 178,178,178, 178,' ',' ', 178,178,178, 178,' ',178, 178,178,178 }; char d7[5][3] = { 178,178,178, ' ',' ',178, ' ',' ',178, ' ',' ',178, ' ',' ',178 }; char d8[5][3] = { 178,178,178, 178,' ',178, 178,178,178, 178,' ',178, 178,178,178 }; char d9[5][3] = { 178,178,178, 178,' ',178, 178,178,178, ' ',' ',178, ' ',' ',178 }; char sep[5][3] = { ' ',' ',' ', ' ',178,' ', ' ',' ',' ', ' ',178,' ', ' ',' ',' ' }; HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); COORD CursorPosition; void gotoxy(int x, int y){ CursorPosition.X = x; CursorPosition.Y = y; SetConsoleCursorPosition(console, CursorPosition); } void setcursor(bool visible, DWORD size) { if(size == 0) size = 20; CONSOLE_CURSOR_INFO lpCursor; lpCursor.bVisible = visible; lpCursor.dwSize = size; SetConsoleCursorInfo(console,&lpCursor); } void printDigit(int no, int x, int y ){ for(int i=0; i<5; i++){ for(int j=0; j<3; j++){ switch(no){ case 0: gotoxy(x+j, y+i); cout<tm_hour; int min = lotm->tm_min; int sec = lotm->tm_sec; int gap = 5; int posX; int posY = 8; while(1){ system("cls"); drawBorder(9,4); posX = 15; if(kbhit()){ char ch = getch(); if(ch==27){ break; } } if( hour < 10 ){ printDigit(0, posX, posY); printDigit(hour, posX+=gap, posY); } else{ printDigit(hour/10, posX, posY); printDigit(hour%10, posX+=gap, posY); } printDigit(10, posX+=gap, posY); if( min < 10 ){ printDigit(0, posX+=gap, posY); printDigit(min, posX+=gap, posY); } else{ printDigit(min/10, posX+=gap, posY); printDigit(min%10, posX+=gap, posY); } printDigit(10, posX+=gap, posY); if( sec < 10 ){ printDigit(0, posX+=gap, posY); printDigit(sec, posX+=gap, posY); } else{ printDigit(sec/10, posX+=gap, posY); printDigit(sec%10, posX+=gap, posY); } //50 millisecond processing time is deducted, you can change it... Sleep(950); sec++; if( sec>=60 ){ sec = 0; min++; } if( min>=60 ){ min = 0; hour++; } if( hour>=24 ){ sec = 0; min = 0; hour = 0; } } return 0; } Thank You Tags: Digital clock coding in c++ Facebook Twitter