(1) 实习题目:
模拟时钟中断的产生及设计一个对时钟中断事件进行处理的模拟程序。
(2) 程序中使用的数据结构及符号说明。
time_t tval1; 时间变量
struct tm * star; 时间指针
localtime(& tval1); 定时函数
srand(time(0));
random=rand()%2; 产生 0 和 1 的随机数
处理一条时钟中断用时 2s
(3) 打印一份源程序并附上注释。
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(){
cout<<"---对时钟中断事件进行处理的模拟程序---"<<endl;
time_t tval1; //时间变量
struct tm * star;//时间指针
tval1 = time(NULL);
star = localtime(& tval1);//定时函数
int Syear = star ->tm_year + 1900;
int Smonth = star ->tm_mon + 1;
int Sday = star ->tm_mday;
int Shour = star ->tm_hour;
int Smin = star ->tm_min;
int Ssec = star ->tm_sec;
/*开始时间、年月日、时分秒*/
int Fyear,Fmonth,Fday,Fhour,Fmin,Fsec;
int Timer;//计时器
int Alarm_Clock,AClock;//定时闹钟
int Counter(0);//计数器
int Random;
int i;
//输出起始时间
cout<<"起始时间为:
"<<Syear<<"年"<<Smonth<<"月"<<Sday<<"日"<<Shour<<"时"<<Smin<<"分"<<
Ssec<<"秒"<<endl;
cout<<"计时器置零"<<endl;
Timer = 0;
cout<<"请设置定时闹钟"<<endl;
cin>>Alarm_Clock;
AClock = Alarm_Clock;
评论2
最新资源