程序代码如下:
#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+"日")
}
}
#include<math.h>#include<dos.h>
#include<graphics.h>
#include<conio.h>
#include<time.h>
#define PI 3.141592653589793
int h,m,s,i,l,mon,y,d
struct time t
struct date data
draw()
{
gettime(&t)//取得时间信息到t
s=t.ti_sec//秒
h=t.ti_hour//时
m=t.ti_min//分
getdate(&data)//取得日期信息到data
y=data.da_year//年
mon=data.da_mon//月
d=data.da_day//日
setcolor(11)
circle(300,200,152)
setcolor(3)
circle(300,200,157)
//画出60个分钟消岩刻度
for(i=0i<60i+=1)
{
if(i%5==0) l=140
else l=145
line(300+150*sin(i*PI/30),200-150*cos(i*PI/30),
300+l*sin(i*PI/30),200-l*cos(i*PI/30))
}
//画秒针
setcolor(19)
line(300,200,300+140*sin(s*PI/30),200-140*cos(s*PI/30))
//画分针
setcolor(3)
line(300,200,300+110*sin(m*PI/30),200-110*cos(m*PI/30))
//画时针
setcolor(11)
line(300,200,300+90*sin(((float)h+(float)m/60)*PI/6),200-90*cos(((float)h+(float)m/60)*PI/6))
//标注空启钟盘上的"3"斗桥如、"6"、"9"、"12"
settextstyle(3,0,2)
outtextxy(430,190,"3")
outtextxy(295,320,"6")
outtextxy(160,190,"9")
outtextxy(293,60,"12")
}
main()
{
int gd=DETECT,gm
initgraph(&gd,&gm,"")//初始化屏幕模式
setbkcolor(8)
while(!kbhit()) //若有键盘输入则跳出(结束程序)
{
draw()//绘制钟
settextstyle(3,0,5)
setcolor(9)
outtextxy(60,170,"my clock")
gotoxy(35,17)
//打印出数字形式的时间(hh:mm:ss)
if(h<10) printf("0")printf("%d:",h)
if(m<10) printf("0")printf("%d:",m)
if(s<10) printf("0")printf("%d",s)
gotoxy(33,18)
printf("%d:",y)
//打印出日期(mm:dd)
if(mon<10) printf("0")printf("%d:",mon)
if(d<10) printf("0")printf("%d",d)
sound(200)//让喇叭以200HZ叫一声
delay(70)//延时0.07秒,即是声音延续0.07秒
nosound()//停止声音
sleep(1)//停止一秒
cleardevice()//清屏
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)