编写一个时钟程序

编写一个时钟程序,第1张

时钟源租则渗程序(C语言)#include<graphics.h>#include<math.h>#include<stdio.h>弊脊#include<dos.h>#define pi 3.1415926#define X(a,b,c) x=a*cos(b*c*pi/180-pi/盯毁2)+300#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240#define d(a,b,c) X(a,b,c)Y(a,b,c)line(300,240,x,y)void init(){int i,l,x1,x2,y1,y2setbkcolor(3)outtextxy(224, 234, "9")outtextxy(375,234,"3")outtextxy(295,165,"12")outtextxy(299,305,"6")circle(300,240,100)circle(300,240,105)circle(300,240,5)for(i=0i<60i++){if(i%5==0) l=15else l=5x1=100*cos(i*6*pi/180)+300y1=100*sin(i*6*pi/180)+240x2=(100-l)*cos(i*6*pi/180)+300y2=(100-l)*sin(i*6*pi/180)+240line(x1,y1,x2,y2)}} main(){int x,y,iint gd=VGA,gm=2unsigned char h,m,sstruct time t[1]initgraph(&gd,&gm,"d:\\tc")init()setwritemode(1)gettime(t)h=t[0].ti_hourm=t[0].ti_mins=t[0].ti_secsetcolor(10)d(60,h,30)setcolor(14)d(80,m,6)setcolor(4)d(100,s,6)while(!kbhit()){while(t[0].ti_sec==s)gettime(t)sound(400)delay(70)sound(200)delay(30)nosound()setcolor(4)d(100,s,6)s=t[0].ti_secd(100,s,6)if (t[0].ti_min!=m){setcolor(14)d(80,m,6)m=t[0].ti_mind(80,m,6)}if (t[0].ti_hour!=h){ setcolor(7)d(60,h,30)h=t[0].ti_hourd(60,h,30)sound(1000)delay(240)nosound()delay(140)sound(2000)delay(240)nosound()}}getch()closegraph()}

谢谢楼主采纳、愿您六一儿童节快乐!!

程序代码如下:

#include<iostream>

#include<windows.h>

using namespace std

class Clock{

public:

Clock(short h=0,short m=0,short s=0):h(h),m(m),s(s){

}

void displayTime()

private:

short h

short m

short s

}void Clock::displayTime(){

while(true){

cout<<h<<':'<<m<<':'<<s<<" "

Sleep(1000)

cout<<'\r'

if(!(s=++s%60))

if(!(m=++m%60))

h=++h%24

}

} int main()

{

Clock A(23,59,55)

A.displayTime()

return 0

}

扩展资料:

定义一个日期类,包括年、月、日三个成员变量,显示日期的方法如下数乱:裂毕余肆滚

publicclassDemo{

publicstaticvoidmain(String[]args){

Datedate1=newDate(1994,5,22)

date1.showInfo()

Datedate2=newDate()

date2.year=1995

date2.month=6

date2.day=29

date2.showInfo()

}

}

//日期类:

publicclassDate{

intyear

intmonth

intday

//构造方法

publicDate(intyear,intmonth,intday){

this.year=year

this.month=month

this.day=day

}

publicDate(){

}

publicvoidshowInfo(){

System.out.println(year+"年"+month+"月"+day+"日")

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12489394.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存