Timer计时器(测试版)Pre 0.3 通道开放通知
更新改动
- 对整个程序进行了“模块化”处理。
- 增加了倒计时结束时的声音与文字。
- 增加了对“错误”输入的错误判定。
Timer计时器 Pre 0.3
内测程序
#include<bits/stdc++.h>
#include<windows.h>
#define clear() system("cls")//清空整个屏幕
using namespace std;
int hour,minute,second;
void input ()
{//输入
cout<<"请输入计时时间:(时分秒)\n";
cout<<"小时:";
cin>>hour;
// cout<<"\n";
cout<<"分钟:";
cin>>minute;
// cout<<"\n";
cout<<"秒:";
cin>>second;
// cout<<"\n";
clear();//先清空一下
}
bool valid ()
{//判断是否合法
return 0<=hour&&0<=minute&&minute<60&&0<=second&&second<60;
}
void Ending ()
{//结尾处理
cout<<"计时已经结束,请重置程序!\n";
for (int i=1;i<=10;++i)
{
Sleep(450);//短暂休息,可根据情况进行调整
cout<<"\a";//蜂鸣
}
}
void Take_time ()
{//计时功能
int sum_seconds=hour*3600+minute*60+second;//总秒数
for (int t=sum_seconds;t>0;--t)
{//循环
Sleep(1000);//休眠1秒
cout<<t/3600<<":"<<(t%3600)/60<<":"<<t%60<<endl;//时:分:秒
cout<<"\a";//蜂鸣器
clear();//清空屏幕
}
}
int main ()
{
input();//输入
if (!valid())
{//特判不合法情况
cout<<"您输入的数据有误,请重启程序重新输入!\n \a \a \a \a \a";
return 0;
}
Take_time();//计时
Ending();//结尾处理
return 0;
}
void Take_time () {//计时功能 int sum_seconds=hour*3600+minute*60+second;//总秒数 for (int t=sum_seconds;t>0;--t) {//循环 Sleep(1000);//休眠1秒 cout<<t/3600<<":"<<(t%3600)/60<<":"<<t%60<<endl;//时:分:秒 cout<<"\a";//蜂鸣器 clear();//清空屏幕 } }
这个部分要改成这样:
void Take_time () { //计时功能 int sum_seconds = hour * 3600 + minute * 60 + second; //总秒数 for (int t = sum_seconds; t > 0; --t) { //循环 cout << t / 3600 << ":" << (t % 3600) / 60 << ":" << t % 60 << endl; //时:分:秒 cout << "\a"; //蜂鸣器 Sleep(1000);//休眠1秒 clear();//清空屏幕 } }
我也是把我四年级搞得程序找了出来(其实说考古才对)#include <unistd.h> #include <ctime> #include <conio.h> #include <iostream> #include <stdio.h> #include <cstring> #include <string> #include <fstream> #include <bits/stdc++.h> #include <windows.h> #include <time.h> using namespace std; void color(int a) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), a); } void x(const string c) { size_t len = c.size(); for (int i = 0; i < c.size(); i++) { cout << c[i]; usleep(10000); } } void xx(const string c) { size_t len = c.size(); for (int i = 0; i < c.size(); i++) { cout << c[i]; usleep(10000); } } int main() { int N = 3; color(N); x("请"); x("输"); x("入"); x("倒"); x("计"); x("时"); x("时"); x("间"); x("。"); x("分"); x("别"); x("按"); x("时"); x("、"); x("分"); x("、"); x("秒"); x("顺"); x("序"); x("输"); x("入"); x("。"); x("注"); x(":"); x("不"); x("要"); x("输"); x("入"); x("非"); x("数"); x("字"); x("字"); x("符"); x("。"); x("作"); x("者"); x("N"); x("O"); x("."); x("1"); x("-"); x("F"); x("i"); x("n"); x("n"); cout << endl; int shi, fen, miao; x("时"); x(":"); cin >> shi; x("分"); x(":"); cin >> fen; x("秒"); x(":"); int x1 = 0; cin >> miao; miao++; system("cls"); while (1) { string a, b, c; x1++; if (x1 == 100000000) x1 = 1; color(x1); miao--; if (miao == -1) { miao = 59; fen--; } if (fen == -1) { fen = 59; shi--; } if (shi <= 0 && fen <= 0 && miao <= 0) { while (1) printf ("时间到"); } usleep(916500); system("cls"); cout << "------------------------------------------------------------------------------" << endl; cout << "|★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★|" << endl; cout << endl; cout << "|☆☆☆☆☆☆☆☆☆☆☆☆☆☆ ☆☆☆☆☆☆☆☆☆☆☆☆☆☆|" << endl; cout << endl; cout << "|★★★★★★★★★★★★★★ 倒计时: ★★★★★★★★★★★★★★|" << endl; cout << endl; cout << "|☆☆☆☆☆☆☆☆☆☆☆☆☆☆ ☆☆☆☆☆☆☆☆☆☆☆☆☆☆|" << endl; cout << endl; cout << "|★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★|" << endl; cout << endl; cout << "|☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆|" << endl; cout << endl; cout << "|★★★★★★★★★★★★★★ ★★★★★★★★★★★★★★|" << endl; cout << endl; cout << "|☆☆☆☆☆☆☆☆☆☆☆☆☆☆ "; if (shi >= 10) cout << shi << ":"; else cout << 0 << shi << ":"; if (fen >= 10) cout << fen << ":"; else cout << 0 << fen << ":"; if (miao >= 10) cout << miao; else cout << 0 << miao; cout << " ☆☆☆☆☆☆☆☆☆☆☆☆☆☆|" << endl; cout << endl; cout << "|★★★★★★★★★★★★★★ ★★★★★★★★★★★★★★|" << endl; cout << endl; cout << "|☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆|" << endl; cout << endl; cout << "------------------------------------------------------------------------------" << endl; } return 0; }
拿来把你谢谢我会“借鉴”一下