AIM:
To write a java
program for real-time program for implementing an alarm clock shall be
developed
ALGORITHM:
Step 1:
Start the program
Step 2:
Display init is used for initialization, and shall be
called from the main function of the program.
Step 3:
Before
the processes are created.
Step 4:
Display
time displays the current time, and shall be called by the clock process
Step 5:
Display
alarm time shows the current alarm time, and shall be called when a new alarm
time is set.
Step 6:
Erase
alarm time erases the displayed alarm time, and shall be called when the user
acknowledges an alarm
Step 7:
Display
alarm text is used to show an alarm activation, and shall be called when the
user shall be informed that the alarm has been activated
Step 8:
When the
alarm is activated the first time, and when the alarm is activated repeatedly
(which is every 10 seconds, according to the above stated requirements).
Step 9:
End of
programs
PROGRAM
#include<stdio.h>
#include<conio.h>
#include<dos.h>
struct clk
{
int hh,mm,ss;
}c1,c2;
void clock(int *h1,int *m1,int *s1)
{
*s1=*s1+1;
if(*s1==60)
{
*s1=0; *m1=*m1+1;
if(*m1==60)
{
*m1=0;*h1=*h1+1;
if(*h1==24)
*h1=0;
}
}
}
void timer(int *h,int *m,int *s)
{
if((*s)!=0)
{
*s=*s-1;
}
else if((*s)==0)
{
if(*m!=0)
{
*s=59;*m=*m-1;
}
else if(*m==0)
{
if(*h!=0)
{
*m=59;*h=*h-1;
}
}
}
}
void alarm()
{
int i;
while(!kbhit())
{
for(i=0;i<2;i++)
{
sound(5000);
delay(100);
nosound();
delay(200);
}
delay(500);
}
}
void main()
{
char ch;
struct time t;
clrscr();
printf("\nPress:-\n\tA: for alarm Clock\n\tT: for
Timer\n");
printf("\Enter your Choice:");
ch=getche();
switch (ch)
{
case 'A':
case 'a':
{
printf("\n\n\n24 hr Format(HH:MM:SS)");
gettime(&t);
c1.hh=t.ti_hour; c1.mm=t.ti_min; c1.ss=t.ti_sec;
printf("\nEnter alarm time : ");
scanf("%d:%d:%d",&c2.hh,&c2.mm,&c2.ss);
if(c2.hh>24||c2.mm>60||c2.ss>60)
{
printf("\n\n\tERROR: Invalid time.\n\tRestart the
program.");
delay(2500);exit(0);
}
while((c1.ss!=c2.ss)||(c1.hh!=c2.hh)||(c1.mm!=c2.mm))
{
clrscr();
printf("\n\nAlarm time:
%02d:%02d:%02d\n",c2.hh,c2.mm,c2.ss);
printf("\nCurrent Time:
%02d:%02d:%02d",c1.hh,c1.mm,c1.ss);
clock(&c1.hh,&c1.mm,&c1.ss);
delay(1000);
};
clrscr();printf("\n\n\n\n\t\t\t\tAlarm time
reached\n\n\t\t\t\tPress any to Exit.");
alarm();
exit(0);
}
break;
case 'T':
case 't':
{
printf("\n\n\nEnter time for timer (HH:MM:SS): ");
scanf("%d:%d:%d",&c1.hh,&c1.mm,&c1.ss);
while(c1.hh>0||c1.mm>0||c1.ss>0)
{
clrscr();
printf("The Current Time:\n");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t");
printf("%02d:%02d:%02d",c1.hh,c1.mm,c1.ss);
timer(&c1.hh,&c1.mm,&c1.ss);
delay(1000);
}
clrscr();
printf("\n");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t");
printf("00:00:00");
alarm();
exit(0);
}
break;
default:
{
printf("\n\tInvalid Input\n\n\tPlease restart the
program");
delay(2500);exit(0);
}
}
}
No comments:
Post a Comment