#include<iostream>
#include<time.h>
usingnamespace std;
class Time {
public:
Time();
void setalarm(time_t);
void wait(int);
private:
int sec;
time_t current_time;
};
Time::Time()
{
current_time = time(0);
cout<<"Current time is: "<<current_time<<endl;
setalarm(current_time);
}
void Time::setalarm(time_t)
{
cout<<"Please set the alarm time(within 60 seconds):";
int a;
cin>>a;
sec = (a>5 && a<=60) ? a:60;
for (int i = sec; i>0 ; --i)
{
cout<<i<<endl;
wait(1);
}
cout<<"Alarm!!\a";
}
void Time::wait(int seconds)
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
int main()
{
Time A;
system("pause");
}
(1)The program run normally until the word "Alarm!!". It gives no sound("\a") and the PC crahed totally. I would know how to fix the problem. (I directly copy the Wait function from this website).
(2) Despite searching on the net and making multiple tries, I still cannot get Line 18 into a standard calendar (i.e. Year, Month, Date, Hour, Minute, Second). Can someone show me an example of doing this?