本文目錄一覽:
用C語言怎麼編輯一個鬧鐘?
呵呵,寫了一個玩玩:
#include stdio.h
#include windows.h
#include winbase.h
int main(int argc, char *argv[])
{
SYSTEMTIME time;
SYSTEMTIME clock;
GetLocalTime(time);
printf(“當前時間為:%2d:%2d:%2d\n”,time.wHour,time.wMinute,time.wSecond);
printf(“請設定鬧鐘時間:\n”);
printf(“時:”);
scanf(“%2d”,clock.wHour);
printf(“分:”);
scanf(“%2d”,clock.wMinute);
while(1)
{
Sleep(1000);
GetLocalTime(time);
if((time.wHour==clock.wHour)(time.wMinute==clock.wMinute))
{
printf(“\a\a\a時間到!!!”);
break;
}
}
return 0;
}
C語言 鬧鐘程序
用C語言實現的鬧鐘程序
#include
#include
#include
#include
#include
void
main()
{
int
gd=DETECT,gm;
int
x=320,y=240,r=200,i,h,m,s,thetamin,thetasec;
struct
time
t;
char
n[12][3]={“3″,”2″,”1″,”12″,”11″,”10″,”9″,”8″,”7″,”6″,”5″,”4”};
initgraph(gd,gm,”g:\\tc\\bgi”);//圖形驅動器路徑,根據自己的系統更換。
circle(x,y,210);
setcolor(4);
settextstyle(4,0,5);
for(i=0;i12;i++)
{
if(i!=3)
outtextxy(x+(r-14)*cos(M_PI/6*i)-10,y-(r-14)*sin(M_PI/6*i)-26,n[i]);
else
outtextxy(x+(r-14)*cos(M_PI/6*i)-20,y-(r-14)*sin(M_PI/6*i)-26,n[i]);
}
gettime(t);
printf(“The
current
time
is:
%2d:%02d:%02d.%02d\n”,t.ti_hour,
t.ti_min,
t.ti_sec,
t.ti_hund);
while(!kbhit())
{
setcolor(5);
setfillstyle(1,5);
circle(x,y,10);
floodfill(x,y,5);
gettime(t);
if(t.ti_min!=m)
{
setcolor(0);
line(x,y,x+(r-60)*cos(thetamin*(M_PI/180)),y-(r-60)*sin(thetamin*(M_PI/180
)));
circle(x+(r-80)*cos(thetamin*(M_PI/180)),y-(r-80)*sin(thetamin*(M_PI/180))
,10);
line(x,y,x+(r-110)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-110)*sin(M_PI/6*h
-((m/2)*(M_PI/180))));
circle(x+(r-130)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-130)*sin(M_PI/6*h-(
(m/2)*(M_PI/180))),10);
}
if(t.ti_hour12)
t.ti_hour=t.ti_hour-12;
if(t.ti_hour4)
h=abs(t.ti_hour-3);
elsen
bsp;
h=15-t.ti_hour;
m=t.ti_min;
if(t.ti_min=15)
thetamin=(15-t.ti_min)*6;
else
thetamin=450-t.ti_min*6;
if(t.ti_sec=15)
thetasec=(15-t.ti_sec)*6;
else
thetasec=450-t.ti_sec*6;
setcolor(4);
line(x,y,x+(r-110)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-110)*sin(M_PI/6*h
-((m/2)*(M_PI/180))));
circle(x+(r-130)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-130)*sin(M_PI/6*h-(
(m/2)*(M_PI/180))),10);
line(x,y,x+(r-60)*cos(thetamin*(M_PI/180)),y-(r-60)*sin(thetamin*(M_PI/180
)));
circle(x+(r-80)*cos(thetamin*(M_PI/180)),y-(r-80)*sin(thetamin*(M_PI/180))
,10);
setcolor(15);
line(x,y,x+(r-70)*cos(thetasec*(M_PI/180)),y-(r-70)*sin(thetasec*(M_PI/180
)));
delay(1000);
setcolor(0);
line(x,y,x+(r-70)*cos(thetasec*(M_PI/180)),y-(r-70)*sin(thetasec*(M_PI/180
)));
}
}
該程序已在Turbo
C++3.0中通過編譯.
怎麼用c語言編寫鬧鐘程序,期末作業求大神
最簡單的方法,先讓用戶輸入時間,然後使用結構體保存起來,然後用一個循環,while、for都可以,然後在循環中取得當前的時間,使用取得的時間與用戶設定的時間進行比較,
如果沒到時間,那麼就繼續循環。
如果到時間了,發音,然後退出循環。
稍微複雜一些的方法,使用Timer、啟動線程的方法。
C語言編鬧鐘程序
程序員聯合開發網上有:
非常漂亮。
///////////////////////
大兄弟你點那個文件名,就自動打開了,不要下載的。
給你我打開TransparentWnd.cpp,內容太多,貼子顯示不了,就一部分;
////////////////////
ktclock.rar TransparentWnd.cpp
//****************
//* TransparentWindow.CPP
//*
//* A transparent window class.
//*
//* Based on the idea of Jason Wylie ,Franz Polzer,Luo yun bin
//* e9225140@student.tuwien.ac.at
//* (C) 2002 by 王鵬
//*
//* Write to me: mailwp@21cn.com
//
#include “stdafx.h”
#include “TransparentWnd.h”
#include “Dib.h”
#include “resource.h”
#include
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define WM_LIBEN WM_USER+994
CString GetCurPath()
{
TCHAR exeFullPath[MAX_PATH];
CString strPath;
GetModuleFileName(NULL,exeFullPath,MAX_PATH);
strPath.Format(“%s”, exeFullPath);
strPath = strPath.Left(strPath.ReverseFind(‘\\’));
return strPath;
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/279642.html