//秒表.h #pragma once namespace 模拟秒表 { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// <summary> /// 秒表 摘要 /// </summary> public ref class 秒表 : public System::Windows::Forms::Form { public: 秒表(void) { InitializeComponent(); // //TODO: 在此处添加构造函数代码 // } protected: /// <summary> /// 清理所有正在使用的资源。 /// </summary> ~秒表() { if (components) { delete components; } } private: /// <summary> /// 必需的设计器变量。 /// </summary> System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> void InitializeComponent(void) { this->components = gcnew System::ComponentModel::Container(); this->Size = System::Drawing::Size(300,300); this->Text = L"秒表"; this->Padding = System::Windows::Forms::Padding(0); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; } #pragma endregion }; } #include <iostream> #include <time.h> #include <Windows.h> #include<stdio.h> #include<stdlib.h> using namespace std; int rounds=1; class times { private: long minute,sec,pminute,psec,origntime,inittime; long mm,pmm; public: times() { minute=0;origntime=0;pminute=0; } void outtime() { Transferptime(inittime-origntime);Transfertime(inittime); printf("%2dm%2ds%3dms %2dm%2ds%3dms",minute,sec,mm,pminute,psec,pmm); printf(" 第%2d次",rounds++); origntime=inittime; } void Transfertime(int t) { if(t>1000) {sec=t/1000;mm=t%1000; if(sec>60) {minute=sec/60;sec=sec%60;}} else {minute=sec=0;mm=t;} } void Transferptime(int t) { if(t>=1000) {psec=t/1000;pmm=t%1000; if(psec>60) {pminute=psec/60;psec=psec%60;}} else {pminute=0;psec=0;pmm=t;} } void correcttime() { inittime=clock(); } }; void InitMyset() { system("mode con: cols=40 lines=40"); system("title 少杰的秒表 版权所有@翻版必究!"); system("color 80"); } int main() { char a; InitMyset(); printf("按回车键开始:/n 截止时间 距上次时间/n"); printf("%2dm%2ds%3dms %2dm%2ds%3dms",0,0,0,0,0,0); times h; while(1) { while((a=getchar())=='/n') { cout<<unitbuf; h.correcttime(); h.outtime(); } } }