秒表源码
❶ C语言时钟源代码
#include<graphics.h> /* 引入graphic.h */
#include<math.h> /* 引入math.h */
#include<dos.h> /* 引入dos.h */
#define pi 3.1415926 /*定义pi=3.14159*/
#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,y2; /*定义……*/
setbkcolor(1); /*设置颜色*/
circle(300,240,200); /*作园*/
circle(300,240,205);
circle(300,240,5);
for(i=0;i<60;i++) /*循环(算时间)*/
{if(i%5==0) l=15;
else l=5;
x1=200*cos(i*6*pi/180)+300;
y1=200*sin(i*6*pi/180)+240;
x2=(200-l)*cos(i*6*pi/180)+300;
y2=(200-l)*sin(i*6*pi/180)+240;
line(x1,y1,x2,y2);
}
}
main()
{
int x,y;
int gd=VGA,gm=2;
unsigned char h,m,s; /*定义*/
struct time t[1];
initgraph(&gd,&gm,"d:\\tc");
init();
setwritemode(1);
gettime(t);
h=t[0].ti_hour;
m=t[0].ti_min;
s=t[0].ti_sec; /*定义时分秒*/
setcolor(7); /*设置颜色*/
d(150,h,30);
setcolor(14);
d(170,m,6);
setcolor(4);
d(190,s,6);
while(!kbhit()) /*获取键盘相应*/
{while(t[0].ti_sec==s)
gettime(t); /*C语言中得到时间的函数*/
sound(400); /*计算时间……*/
delay(70);
sound(200);
delay(30);
nosound();
setcolor(4);
d(190,s,6);
s=t[0].ti_sec;
d(190,s,6);
if (t[0].ti_min!=m)
{
setcolor(14);
d(170,m,6);
m=t[0].ti_min;
d(170,m,6);
}
if (t[0].ti_hour!=h)
{ setcolor(7);
d(150,h,30);
h=t[0].ti_hour;
d(150,h,30);
sound(1000);
delay(240);
nosound();
delay(140);
sound(2000);
delay(240);
nosound();
}
}
getch(); /*设置空格后退出*/
closegraph();
}
http://..com/question/121241211.html
❷ 如何用C语言编程,使出现一个界面几秒后自动跳到另一个界面;求高手解答。
你的界面指什么界面???控制台还是应用程序界面??
给个代码你参考下吧,是秒表计时器程序的代码
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <stdlib.h>
struct tm //定义时间结构体,包括时分秒和10毫秒
{
int hours,minutes,seconds;
int hscd;
}time,tmp,total; //time用以计时显示,tmp用以存储上一阶段时间,total记总时间
int cnt;
FILE* fout;
//每次调用update函数,相当于时间过了10ms
void update(struct tm *t)
{
(*t).hscd++; //10ms单位时间加1
cnt++;
if ((*t).hscd==100) //计时满1s,进位
{
(*t).hscd=0;
(*t).seconds++;
}
if ((*t).seconds==60) //计时满一分,进位
{
(*t).seconds=0;
(*t).minutes++;
}
if ((*t).minutes==60) //计时满一小时,进位
{
(*t).minutes=0;
(*t).hours++;
}
if((*t).hours==24) (*t).hours=0;
//delay();
Sleep(10); //Sleep是windows提供的函数,作用是暂停程序,单位毫秒,所以此处暂停10ms
}
void display(struct tm *t)
{
//此处输出计时结果,\r为回车不换行,既一直在同一行更新时间
printf("%d:",(*t).hours);
printf("%d:",(*t).minutes);
printf("%d:",(*t).seconds);
printf("%d\r",(*t).hscd);
//printf("Now, press ‘e’ key to stop the clock…");
}
void time_init() //初始化时间
{
time.hours=time.minutes=time.seconds=time.hscd=0;
}
void get_total() //计算总时间
{
total.hscd = cnt % 100;
cnt /= 100;
total.seconds = cnt % 60;
cnt /= 60;
total.minutes = cnt % 60;
cnt /= 60;
total.hours = cnt;
}
int main()
{
char m;
time_init();
cnt = 0;
fout = fopen("timeout.txt","w");
printf("按回车键开始计时!\n");
while(1)
{
m = getch();
if(m != ‘\r’) //读入一个输入,如果是回车,那么跳出次循环
printf("输入错误,仅能输入回车键!\n");
else
break;
}
printf("已经开始计时,但是你可以按回车键以分段计时!\n");
while(1)
{
if(kbhit()) //此处检查是否有键盘输入
{
m=getch();
if(m == ‘\r’) //如果等于回车,那么计时结束,跳出循环
break;
else if(m == ‘ ‘) //如果等于空格,显示此次计时,初始化计时器
{
tmp = time; //记录上一段计时器结果
fprintf(fout,"%d:%d:%d:%d\n",tmp.hours,tmp.minutes,tmp.seconds,tmp.hscd); //写入文件
time_init();
printf("\n");
}
else
{
printf("输入错误,仅支持输入回车键或者空格键!\n");
}
}
update(&time); //更新计时器
display(&time); //显示计时器时间
}
tmp = time; //输出最后一次即使结果,写入文件
fprintf(fout,"%d:%d:%d:%d\n",tmp.hours,tmp.minutes,tmp.seconds,tmp.hscd);
get_total(); //计算总的时间,显示,并写入文件
printf("\n总时间:%d:%d:%d:%d\n",total.hours,total.minutes,total.seconds,total.hscd);
fprintf(fout,"统计时间:%d:%d:%d:%d\n",total.hours,total.minutes,total.seconds,total.hscd);
fclose(fout);
printf("已经保存到当前目录下的timeout.txt文件中按任意键结束!");
getch();
}
❸ 用Delphi实现的秒表程序源码
控件 button1 开始计时按钮
button2 置零按钮
edit1 和timer1结合,显示从比赛开始到现在的时间,时刻变化
timer1 用来计时,interval=10
memo1 用来存储每个人的时间的记录
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
Timer1: TTimer;
procere Button1Click(Sender: TObject);
procere Button2Click(Sender: TObject);
procere FormShow(Sender: TObject);
procere Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i:integer;
time:tdatetime;
s:string;
implementation
{$R *.dfm}
procere TForm1.Button1Click(Sender: TObject);//计时开始按钮
begin
if i=0 then
begin
i:=1;
time:=now;
s:='00:00:00 000';
timer1.Enabled :=true;
exit;
end;
s:= FormatDateTime('hh:nn:ss:zzz',now-time);
memo1.Lines.Add(s);
end;
procere TForm1.Button2Click(Sender: TObject); //置零按钮
begin
timer1.Enabled :=false;
s:='00:00:00 000';
memo1.Clear;
edit1.text:='00:00:00 000';
i:=0;//判断是否是开始计时的标志 i=1 是在计时,i=0 没有开始计时
end;
procere TForm1.FormShow(Sender: TObject);
begin
i:=0;
edit1.text:='00:00:00 000';
end;
procere TForm1.Timer1Timer(Sender: TObject);
begin
edit1.Text:=FormatDateTime('hh:nn:ss:zzz',now-time);
end;
end.
测试通过,和秒表的功能一样!