+-
C++基础练习案例 - 模拟时钟系统 [DOS]

大学时期初学C++,做了些案例练习,想着整理一下,供自己和网友翻阅参考,谢谢支持!有个【模拟时钟系统】做的还可以。 【PS】存在一些小问题,如编写习惯等,文末有简单小结,请自行辨析。算是提供不良模板,引以为戒

//**************************************************************************************//
//					《简易时钟(C++)》(控制台程序)			//
//											//
//	注:还有很多小问题,如键入的域值、动态修改不灵敏、程序不稳定。。。		//
//	    还能扩充很多功能!								//
//	可实现的功能:									//
//		1.能够手动初始化也能按照预设设置参数(可以设置两种时制!)		//
//		2.能够整点报时(用了windows API 函数)(在exe文件的所在目录里		//
//				有相应的音频文件) (同时使用了蜂鸣进行模拟报时,	//
//				转义字符为‘\a’)					//
//		3.能够随时暂停核相应继续时钟跳动					//
//		4.可以重新设置参数 进行时钟运转,可以随时退出程序			//
//		5.可以设置闹钟时刻,时刻一到,播放闹铃!				//
//		6.可以切换两种显示方式							//
//							作者:SHARP-EYE   2014.9.23	//
//**************************************************************************************//

 

头文件编写

Clock.h:

#ifndef clock_h
#define clock_h

#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include<mmsystem.h>				//	windows多媒体调用需要

#pragma comment(lib,"WINMM.LIB")	//	windows多媒体调用需要

using namespace std;

class Clock
{
private:
int hour;		//小时参数
int minute;		//分钟
int second;		//秒钟
int a_h;		//闹钟 时
int a_m;		//闹钟 分
int a_s;		//闹钟 秒
int mm;			//a.m. or p.m.
int temp;		//临时需要
int r;			//判断哪个制式
int t_ap;		//上午/下午 临时变量
int Do;			//整点
int fun;		//动态设置开关量
int pau;		//暂停开关量
int al;			//闹钟开关量

int AmPm();		//上午下午临时需要值

public:

Clock();								//构造函数
void set_clock(int *,int *,int *);		//设置时钟
void revise_clock();	//修改时钟
void show_12_clock();	//显示12时钟
void show_24_clock();	//显示24时钟
void stop_clock();	//停止时钟
void Clock::set_parameter();	//手动输入【时 分 秒】!
bool set_a_or_p();
void init_clock();
void r_start();
void tranaction();
void key();
bool pause_switch();
void pause_clock();
void init_alarm();
bool show_alarm();
bool alarm_key();
void show_alarm_paramter();
//bool display_option();

void time_24_clock();	//绝对时钟!(每一秒 second加1 满60 minute加1 满60 hour加1 满24 归0)
void time_12_clock();

bool Do_music();		//判断是否需要发声!

//void music();

};

#endif

resource.h:

//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by pic.rc
//
#define IDI_ICON1                       101

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        102
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1001
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif

 

Clock类方法实现

#include "clock.h"			//包含自建头文件

//构造函数(初始化 值)
Clock::Clock()
{
hour = 0;
minute = 0;
second = 0;
a_h = a_m = a_s = 99;
temp = 0;
r = 0;
t_ap = 0;
mm = 0;
fun = 0;
pau = 0;
al = 0;
}

//设置 时 分 秒(通过指针传递数值)
void Clock::set_clock(int *ph,int *pm, int *ps)
{
if( *ph > 24)
*ph = 0;
if( *pm > 60)
*pm = 0;
if( *ps > 60)
*ps = 0;

hour = *ph;
minute = *pm;
second = *ps;
}

//手动设置(初始化)函数(含有不正确值键入返回重新等待键入)
void Clock::set_parameter()
{
int a,b,c;
cout<<"请选择制式:【5】--12制 or 【6】--24制:(请输入正确数字)"<<endl;
U:scanf("%d",&r);
if( 5!= r && 6 !=r )
{
cout<<"请重新选择制式:【5】--12制 or 【6】--24制:(请输入正确数字)"<<endl;
r = NULL;
goto U;
}

cout<<"制式设置成功!"<<endl;

if( 5 == r)
{
cout<<"请输入【7】上午/【8】下午:"<<endl;

L:
scanf("%d",&t_ap);

if( 7 != t_ap && 8 !=t_ap)
{
cout<<"请重新输入【7】上午/【8】下午:(请输入正确数字)"<<endl;
t_ap = NULL;
goto L;
}

if( 7 == t_ap)
mm = 0;
if( 8 == t_ap)
{mm = 1;temp = 1;}
cout<<"上午/下午 设置成功!"<<endl;
}

cout<<"请输入时钟[超过域值以0键入]:(格式:(时):(分):(秒)):	【按回车确认】"<<endl;
scanf("%d:%d:%d",&a,&b,&c);

if(0 != t_ap)
{
if( a > 11)
a = 0;
}

Clock::set_clock(&a,&b,&c);

cout<<"时间设置成功!"<<endl;

if(5 == r)
Clock::show_12_clock();
if(6 == r)
Clock::show_24_clock();
}

//设置为12制式的显示函数
void Clock::show_12_clock()
{
if(1 == fun)
{
if(0 == mm)
{
if(hour >=10 && minute >=10 && second < 10)
cout<<"a.m."<<"【"<<hour<<":"<<minute<<":"<<"0"<<second<<"】"<<" @可调"<<endl; //显示时钟:a.m.【12:00:00】
else if(hour >=10 && minute <10 && second >= 10)
cout<<"a.m."<<"【"<<hour<<":"<<"0"<<minute<<":"<<second<<"】"<<" @可调"<<endl;
else if(hour <10 && minute >10 && second >=10)
cout<<"a.m."<<"【"<<"0"<<hour<<":"<<minute<<":"<<second<<"】"<<" @可调"<<endl;
else if(hour <10 && minute <10 && second >=10)
cout<<"a.m."<<"【"<<"0"<<hour<<":"<<"0"<<minute<<":"<<second<<"】"<<" @可调"<<endl;
else if(hour <10 && minute >=10 && second <10)
cout<<"a.m."<<"【"<<"0"<<hour<<":"<<minute<<":"<<"0"<<second<<"】"<<" @可调"<<endl;
else if(hour >=10 && minute <10 && second <10)
cout<<"a.m."<<"【"<<hour<<":"<<"0"<<minute<<":"<<"0"<<second<<"】"<<" @可调"<<endl;
else if(hour <10 && minute <10 && second <10)
cout<<"a.m."<<"【"<<"0"<<hour<<":"<<"0"<<minute<<":"<<"0"<<second<<"】"<<" @可调"<<endl;
else
cout<<"a.m."<<"【"<<hour<<":"<<minute<<":"<<second<<"】"<<" @可调"<<endl;
}
if(1 == mm)
{
if(hour >=10 && minute >=10 && second < 10)
cout<<"p.m."<<"【"<<hour<<":"<<minute<<":"<<"0"<<second<<"】"<<" @可调"<<endl; //显示时钟:p.m.【12:00:00】
else if(hour >=10 && minute <10 && second >= 10)
cout<<"p.m."<<"【"<<hour<<":"<<"0"<<minute<<":"<<second<<"】"<<" @可调"<<endl;
else if(hour <10 && minute >10 && second >=10)
cout<<"p.m."<<"【"<<"0"<<hour<<":"<<minute<<":"<<second<<"】"<<" @可调"<<endl;
else if(hour <10 && minute <10 && second >=10)
cout<<"p.m."<<"【"<<"0"<<hour<<":"<<"0"<<minute<<":"<<second<<"】"<<" @可调"<<endl;
else if(hour <10 && minute >=10 && second <10)
cout<<"p.m."<<"【"<<"0"<<hour<<":"<<minute<<":"<<"0"<<second<<"】"<<" @可调"<<endl;
else if(hour >=10 && minute <10 && second <10)
cout<<"p.m."<<"【"<<hour<<":"<<"0"<<minute<<":"<<"0"<<second<<"】"<<" @可调"<<endl;
else if(hour <10 && minute <10 && second <10)
cout<<"p.m."<<"【"<<"0"<<hour<<":"<<"0"<<minute<<":"<<"0"<<second<<"】"<<" @可调"<<endl;
else
cout<<"p.m."<<"【"<<hour<<":"<<minute<<":"<<second<<"】"<<" @可调"<<endl;
}
}
else
{

if(0 == mm)
{
if(hour >=10 && minute >=10 && second < 10)
cout<<"a.m."<<"【"<<hour<<":"<<minute<<":"<<"0"<<second<<"】"<<endl; //显示时钟:a.m.【12:00:00】
else if(hour >=10 && minute <10 && second >= 10)
cout<<"a.m."<<"【"<<hour<<":"<<"0"<<minute<<":"<<second<<"】"<<endl;
else if(hour <10 && minute >10 && second >=10)
cout<<"a.m."<<"【"<<"0"<<hour<<":"<<minute<<":"<<second<<"】"<<endl;
else if(hour <10 && minute <10 && second >=10)
cout<<"a.m."<<"【"<<"0"<<hour<<":"<<"0"<<minute<<":"<<second<<"】"<<endl;
else if(hour <10 && minute >=10 && second <10)
cout<<"a.m."<<"【"<<"0"<<hour<<":"<<minute<<":"<<"0"<<second<<"】"<<endl;
else if(hour >=10 && minute <10 && second <10)
cout<<"a.m."<<"【"<<hour<<":"<<"0"<<minute<<":"<<"0"<<second<<"】"<<endl;
else if(hour <10 && minute <10 && second <10)
cout<<"a.m."<<"【"<<"0"<<hour<<":"<<"0"<<minute<<":"<<"0"<<second<<"】"<<endl;
else
cout<<"a.m."<<"【"<<hour<<":"<<minute<<":"<<second<<"】"<<endl;
}
if(1 == mm)
{
if(hour >=10 && minute >=10 && second < 10)
cout<<"p.m."<<"【"<<hour<<":"<<minute<<":"<<"0"<<second<<"】"<<endl; //显示时钟:p.m.【12:00:00】
else if(hour >=10 && minute <10 && second >= 10)
cout<<"p.m."<<"【"<<hour<<":"<<"0"<<minute<<":"<<second<<"】"<<endl;
else if(hour <10 && minute >10 && second >=10)
cout<<"p.m."<<"【"<<"0"<<hour<<":"<<minute<<":"<<second<<"】"<<endl;
else if(hour <10 && minute <10 && second >=10)
cout<<"p.m."<<"【"<<"0"<<hour<<":"<<"0"<<minute<<":"<<second<<"】"<<endl;
else if(hour <10 && minute >=10 && second <10)
cout<<"p.m."<<"【"<<"0"<<hour<<":"<<minute<<":"<<"0"<<second<<"】"<<endl;
else if(hour >=10 && minute <10 && second <10)
cout<<"p.m."<<"【"<<hour<<":"<<"0"<<minute<<":"<<"0"<<second<<"】"<<endl;
else if(hour <10 && minute <10 && second <10)
cout<<"p.m."<<"【"<<"0"<<hour<<":"<<"0"<<minute<<":"<<"0"<<second<<"】"<<endl;
else
cout<<"p.m."<<"【"<<hour<<":"<<minute<<":"<<second<<"】"<<endl;
}
}
}

//设置为24制式的显示函数
void Clock::show_24_clock()
{
if(1 == fun)
{
if(hour >=10 && minute >=10 && second < 10)
cout<<"【"<<hour<<":"<<minute<<":"<<"0"<<second<<"】"<<" @可调"<<endl; //显示时钟:【12:00:00】
else if(hour >=10 && minute <10 && second >= 10)
cout<<"【"<<hour<<":"<<"0"<<minute<<":"<<second<<"】"<<" @可调"<<endl;
else if(hour <10 && minute >10 && second >=10)
cout<<"【"<<"0"<<hour<<":"<<minute<<":"<<second<<"】"<<" @可调"<<endl;
else if(hour <10 && minute <10 && second >=10)
cout<<"【"<<"0"<<hour<<":"<<"0"<<minute<<":"<<second<<"】"<<" @可调"<<endl;
else if(hour <10 && minute >=10 && second <10)
cout<<"【"<<"0"<<hour<<":"<<minute<<":"<<"0"<<second<<"】"<<" @可调"<<endl;
else if(hour >=10 && minute <10 && second <10)
cout<<"【"<<hour<<":"<<"0"<<minute<<":"<<"0"<<second<<"】"<<" @可调"<<endl;
else if(hour <10 && minute <10 && second <10)
cout<<"【"<<"0"<<hour<<":"<<"0"<<minute<<":"<<"0"<<second<<"】"<<" @可调"<<endl;
else
cout<<"【"<<hour<<":"<<minute<<":"<<second<<"】"<<" @可调"<<endl;
}
else
{
if(hour >=10 && minute >=10 && second < 10)
cout<<"【"<<hour<<":"<<minute<<":"<<"0"<<second<<"】"<<endl; //显示时钟:【12:00:00】
else if(hour >=10 && minute <10 && second >= 10)
cout<<"【"<<hour<<":"<<"0"<<minute<<":"<<second<<"】"<<endl;
else if(hour <10 && minute >10 && second >=10)
cout<<"【"<<"0"<<hour<<":"<<minute<<":"<<second<<"】"<<endl;
else if(hour <10 && minute <10 && second >=10)
cout<<"【"<<"0"<<hour<<":"<<"0"<<minute<<":"<<second<<"】"<<endl;
else if(hour <10 && minute >=10 && second <10)
cout<<"【"<<"0"<<hour<<":"<<minute<<":"<<"0"<<second<<"】"<<endl;
else if(hour >=10 && minute <10 && second <10)
cout<<"【"<<hour<<":"<<"0"<<minute<<":"<<"0"<<second<<"】"<<endl;
else if(hour <10 && minute <10 && second <10)
cout<<"【"<<"0"<<hour<<":"<<"0"<<minute<<":"<<"0"<<second<<"】"<<endl;
else
cout<<"【"<<hour<<":"<<minute<<":"<<second<<"】"<<endl;
}

}

//停止时钟函数
void Clock::stop_clock()
{
;
}

//绝对时间【24制式】
void Clock::time_24_clock()
{
if( second < 59)
{
Sleep(1000);
second++;
}
else
{
second = 0;

if(minute < 59 && second ==0)
{
Sleep(1000);
minute++;
}
else
{
minute = 0;
second = 0;

if( hour < 23 && minute ==0 && second ==0)
{
Sleep(1000);
hour++;
//cout<<"\a";
}
else
{	Sleep(1000);
hour = 0;
minute = 0;
second = 0;
//cout<<"\a";
}
}
}

}

//绝对时间【12制式】
void Clock::time_12_clock()
{
if( second < 59)
{
Sleep(1000);
second++;
}
else
{
second = 0;
//minute++;
if(minute < 59 && second ==0)
{
Sleep(1000);
minute++;
}
else
{
minute = 0;
second = 0;
//hour++;
if( hour < 11 && minute ==0 && second ==0)
{
Sleep(1000);
hour++;
//cout<<"\a";
}
else
{
Sleep(1000);
hour = 0;
minute = 0;
second = 0;
//cout<<"\a";
mm = AmPm();
}
}
}
}

//上午 下午显示 交替
int Clock::AmPm()
{
if(1 == temp)
{
temp = 0;
return 0;
}
else
{
temp = 1;
return 1;
}
}

//设置为12制式或24制式的辅助函数
bool Clock::set_a_or_p()
{
if(5 == r)
return true;
if(6 == r)
return false;
}

void Clock::r_start()
{
hour = 0;
minute = 0;
second = 0;
a_h = a_m = a_s = 99;
temp = 0;
r = 0;
t_ap = 0;
mm = 0;
fun = 0;
pau = 0;
al = 0;
}

//设置为默认的初始化函数
void Clock::init_clock()
{
int a = NULL;;
cout<<"初始化样式:【1】a.m.[00:00:00]	【2】p.m.[11:58:20]	【3】[23:59:40]"<<endl;
cout<<"请输入样式代码:"<<endl;
K:cin>>a;
if(1!= a && 2 !=a && 3!=a)
{
cout<<"请重新输入样式代码:"<<endl;
a = NULL;
goto K;
}
else if(1 == a)
{
hour = 0;
minute = 0;
second = 0;
temp = 0;
r = 5;
t_ap = 7;
mm = 0;
fun = 0;
pau = 0;
al = 0;
}
else if(2 == a)
{
hour = 11;
minute = 58;
second = 20;
temp = 0;
r = 5;
t_ap = 8;
mm = 1;
fun = 0;
pau = 0;
al = 0;
}
else if(3 == a)
{
hour = 23;
minute = 59;
second = 40;
temp = 0;
r = 6;
t_ap = 7;
mm = 0;
fun = 0;
pau = 0;
al = 0;
}

}

//是否发出整点报时!
bool Clock::Do_music()
{
if( 0 == second && 0 == minute )
return true;
else
return false;
}

void Clock::key()
{
if(1 == fun)
{
fun = 0;
}
else
{
fun = 1;
}
return;
}

void Clock::tranaction()
{

if(1 ==fun)
{
//cout<<"小时="<<hour<<"分="<<minute<<"秒="<<second<<endl;
char c = 0;
if (kbhit())
c = getch();

if(0 != t_ap)
{
if('t' == c)
{
if( hour >11)
hour =0;
hour++;
}

if('y' == c)
{
if( minute >59)
minute =0;
minute++;
}
if('u' == c)
{
if( second >59)
second =0;
second++;
}

///////////////////////////////////////

if('g' == c)
{
if( hour < 0)
hour = 11;
hour--;
}

if('h' == c)
{
if( minute < 0)
minute = 59;
minute--;
}
if('j' == c)
{
if( second < 0)
second = 59;
second--;
second--;
}
}
else
{
if('t' == c)
{
if( hour >23)
hour =0;
hour++;
}

if('y' == c)
{
if( minute >59)
minute =0;
minute++;
}
if('u' == c)
{
if( second >59)
second =0;
second++;
}

///////////////////////////////////////

if('g' == c)
{
if( hour < 0)
hour = 23;
hour--;
}

if('h' == c)
{
if( minute < 0)
minute = 59;
minute--;
}
if('j' == c)
{
if( second < 0)
second = 59;
second--;
second--;
}
}

}

}

void Clock::pause_clock()
{
if(1 == pau)
{
pau = 0;
}
else
{
pau = 1;
}
return;
}

bool Clock::pause_switch()
{
if(0 == pau)
return true;
if(1 == pau)
return false;
}

void Clock::init_alarm()
{
cout<<"请设置$闹钟$时刻点[超过域值以0键入]:(格式:(时):(分):(秒)):注:不区分制式!!【按回车确认】"<<endl;
scanf("%d:%d:%d",&a_h,&a_m,&a_s);

if(a_h >23)
a_h = 0;
if(a_m >59)
a_m = 0;
if(a_s >59)
a_s = 0;

cout<<"设置成功!  [时]--"<<a_h<<"[分]--"<<a_m<<"[秒]--"<<a_s<<"】"<<endl;
Clock::show_alarm();

}

bool Clock::alarm_key()
{
if(1 == al)
return true;
else
return false;
}

bool Clock::show_alarm()
{
if(a_h == hour && a_m == minute && a_s == second)
al = 1;
else
al = 0;
return true;
}

void Clock::show_alarm_paramter()
{
cout<<"当前闹钟 [时]--"<<a_h<<"[分]--"<<a_m<<"[秒]--"<<a_s<<"】"<<endl;
}
/*
bool Clock::display_option()
{
;
}*/

/*
void Clock::music()
{
mciSendString(TEXT("open res\\513.wav alias mysong"),NULL,0,NULL);
mciSendString(TEXT("play MySong"),NULL,0,NULL);
return;
}
*/

 

主函数

#include "clock.h"

int main()
{	Clock Clock1;

//Clock1.music();

cout<<"--------------------------------------------------------------"<<endl;
cout<<"***************************@自动化@***************************"<<endl;
cout<<"******************---《简易时钟(C++)》---*******************"<<endl;
cout<<"******************作者:SHARPEYE 2014.9.23********************"<<endl;
cout<<"************欢迎使用    时钟开始后 想退出按【Esc】************"<<endl;
cout<<"*************时钟开始后想重新开始 请按【r】或【R】************"<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<"@功能简介@--此时钟可以手动设置时制,时刻点,以及可以整点报时!"<<endl;
cout<<"@---------------详细功能请按【6】----------------------------@"<<endl;
cout<<"--------------------------------------------------------------"<<endl;
cout<<endl<<endl;

R:	Clock1.r_start();		//初始化

cout<<"【欢迎使用!】"<<endl<<endl;
W:	cout<<"请按任意键继续"<<endl;

_getch();

system("cls");

cout<<"请按照说明键入数字,回车执行!"<<endl;

cout<<"键入 【1】 回车:手动初始化 时钟!"<<endl;
cout<<"键入 【2】 回车:默认初始化 时钟!"<<endl;
cout<<"键入 【9】 回车:设置闹钟时刻!"<<endl;
cout<<"键入 【6】 回车:……详细功能说明……"<<endl;

char a;
a = NULL;

I:scanf("%c",&a);

if( a>= 48 && a<=57 )
{
if(49 == a)
{
Clock1.set_parameter();
}
else if(50 == a)
{
Clock1.init_clock();
}
else if(48 == a)
{
cout<<"键入 【1】 回车:手动初始化 时钟!"<<endl;
cout<<"键入 【2】 回车:默认初始化 时钟!"<<endl;
cout<<"键入 【9】 回车:设置闹钟时刻!"<<endl;
cout<<"键入 【6】 回车:……详细功能说明……"<<endl;
a = NULL;
goto I;
}

else if(54 == a)
{
cout<<endl<<endl<<"*****************************详细功能说明**********************************"<<endl;
cout<<"可实现的功能:1.能够手动初始化也能按照预设设置参数(可以设置两种时制!)"<<endl;
cout<<"              2.能够整点报时(用了windows API 函数)(在exe文件的所在目录里"<<endl;
cout<<"                有相应的音频文件) (同时使用了蜂鸣进行模拟报时,"<<endl;
cout<<"                转义字符为‘\a\\a’)"<<endl;
cout<<"              3.能够随时暂停和相应继续时钟跳动"<<endl;
cout<<"              4.可以重新设置参数 进行时钟运转,可以随时退出程序"<<endl;
cout<<"              5.可以设置闹钟时刻,时刻一到,播放闹铃!"<<endl;
cout<<"---------------------------------------------------------------------------"<<endl;
cout<<"附加功能(在时钟运转时):  @1   键入【r】或【R】[终止当前运行,重新初始化]"<<endl;
cout<<"                            @2   键入【a】和【A】[开启/关闭   动态调节开关]"<<endl;
cout<<"                                     【t】小时数+1    【g】小时数-1 "<<endl;
cout<<"                                     【y】分钟数+1    【h】分钟数-1 "<<endl;
cout<<"                                     【u】秒钟数+1    【j】秒钟数-1 "<<endl;
cout<<"                            @3   键入【m】[查看当前闹钟的设置参数[时 分 秒]]"<<endl;
cout<<"                            @4   键入【p】[暂停当前运行,再次键入继续运行]"<<endl;
cout<<"                            @5   键入【`】[#清屏#]"<<endl;
cout<<"                            @5   键入【x】[两种显示方式切换]"<<endl;
cout<<"***************************************************************************"<<endl;
a = NULL;
goto W;
}
else if(57 ==a)
{
Clock1.init_alarm();
a = NULL;
goto W;
}
else
{
cout<<"请重新按说明输入:		"<<"看说明请按【0】"<<endl;
a = NULL;
goto I;
}
}
else
{
cout<<"请重新按说明输入:		"<<"看说明请按【0】"<<endl;
a = NULL;
goto I;
}

int Op = 0;			//显示方式开关量
int opt = 0;		//显示方式开关量2

int w1 = 0;
int w2 = 0;

cout<<endl<<endl<<"初始化成功!"<<endl;
cout<<"------------------"<<endl;
cout<<"-----时钟开始-----"<<endl;
cout<<"------------------"<<endl;

while(1)
{
if( Clock1.pause_switch())
{
if( Clock1.set_a_or_p())
{
Clock1.show_12_clock();
Clock1.time_12_clock();
}
else
{
Clock1.show_24_clock();
Clock1.time_24_clock();
}
if(Clock1.Do_music())
{
cout<<"\a";
mciSendString(TEXT("open res\\513.wav alias mysong"),NULL,0,NULL);
mciSendString(TEXT("play MySong from 0"),NULL,0,NULL);
}
if(Clock1.alarm_key())
{
mciSendString(TEXT("open res\\alarm.wav alias mysong1"),NULL,0,NULL);
mciSendString(TEXT("play mysong1 from 0"),NULL,0,NULL);
}

Clock1.tranaction();
Clock1.show_alarm();

if( 0 != opt)
{
system("cls");
}
}

char c = 0;
if (kbhit())
c = getch();

if(114 == c)
{
mciSendString(L"close mysong", NULL, 0, NULL);
mciSendString(L"close mysong1", NULL, 0, NULL);
goto R;
}

if(82 == c)
{
mciSendString(L"close mysong", NULL, 0, NULL);
mciSendString(L"close mysong1", NULL, 0, NULL);
goto R;
}

if('a' == c)
{
cout<<"动态设置开启"<<endl;
if(0 == w1)
{
w1 = 1;
Clock1.key();
}

}
if('A' == c)
{
cout<<"动态设置关闭"<<endl;
if(1 == w1)
{
w1 =0;
Clock1.key();
}

}
if('m'== c)
{
Clock1.show_alarm_paramter();
}

if('p' == c)
{
Clock1.pause_clock();
if(Clock1.pause_switch())
cout<<"继续!"<<endl;
else
cout<<"暂停!"<<endl;
}
if('`' == c)
{
system("cls");
}

if('x' == c)
{
if(Op == 0)
{
Op = 1;
opt = 1;
}

else
{
Op = 0;
opt = 0;
}

}

if(27 == c)
break;

}

return 0;
}

 

运行结果

运行起来的实际画面:

PS

功能挺多的,不过bug也挺多~~ 当年的野心还挺大,哈哈~

现在看来有很多低级错误和习惯问题,比如类成员变量没有前缀

m_
;方法名首字母没有大写,也没有依照匈牙利命名法和驼峰命名法;部分重复调用函数没有封装等等。