write some pseudocode to implement an alarm clock. Your application should set t
ID: 3883477 • Letter: W
Question
write some pseudocode to implement an alarm clock. Your application should set the alarm clock to go off and beep one time in 4 seconds; if the user does not respond and press the key to turn it off, then the alarm should go off and beep two times in another 8 seconds. Continuing the pattern, the alarm should go off in 16 seconds (beep 3 times), 32 seconds (beep 4 times), and 64 seconds (beep 5 times), if no response is received. After five times, the program should terminate. To make a beep, you can print a -g character to stdout. To insert a -g character into a printf statement using the vim editor, for instance, you can use the escape character -v, followed by -g. Alternatively, your code can just print the word "BEEP" if the lab is full and you don't want to annoy the people
Explanation / Answer
HI,
here is a sample code for an alarm clock as stated above
#include <stdio.h>
#include<math.h>
#include <unistd.h>
#include <conio.h>
void beep(int n)
{
int i;
for(i=0;i<n;i++) // beep i no of times
printf("BEEP, please enter a key to turn OFF ");
}
int main(void) {
int i;
char c;
for(i=1;i<=5;i++)
{
sleep(pow(2,i+1)); // sleep for 2 power i+1 seconds
beep(i); //beep
if(_getch()) //check if a key is entered, if yes then break
break;
}
return 0;
}
Thumbs up if this was helpful, otherwise let me know in comments.Good Day.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.