Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Write a simple timer program- The program will accept a number of seco.docx

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige

Hier ansehen

1 von 2 Anzeige

Write a simple timer program- The program will accept a number of seco.docx

Herunterladen, um offline zu lesen

Write a simple timer program. The program will accept a number of seconds as a command line argument, and steadily count down to 0, decreasing the counter once every second. Echoing should be turned off as the program runs, and should be turned back on once the program exits.
If the user hits Ctrl-C, the timer will pause/unpause. If the user hits Ctrl-\\, the program turns echoing back on then terminates.
Synopsis:
./st seconds
where seconds is an integer indicating the beginning of the countdown.
Sample Usages:
./st 30 causes the timer to count down from 30 to 0
./st prints synopsis
Ctrl-C causes the timer to pause/unpause
Ctrl-\\ causes the program to exit gracefully and ensure that echoing is turned back on.
Hints:
man 3 sleep - use this to make your program wait a second
man 7 signal
spinlock - use this to pause your program. continue can be helpful with this.
if( paused ) continue;
fflush - use this to ensure your output gets to the screen
You may need to turn echoing on, print the seconds, then turn echoing back off.
Solution
Perl prorgram for count down is given below:
#!/usr/bin/perl
use warnings;
use strict;

my $timeCounter = 30;

while($timeCounter > 0){

print(\"$timeCounter\ \");

# count down
$timeCounter--;

# pause program for 1 second
sleep(1);

if($timeCounter == 0){
print(\"Time count zero\ \");
}
}
.

Write a simple timer program. The program will accept a number of seconds as a command line argument, and steadily count down to 0, decreasing the counter once every second. Echoing should be turned off as the program runs, and should be turned back on once the program exits.
If the user hits Ctrl-C, the timer will pause/unpause. If the user hits Ctrl-\\, the program turns echoing back on then terminates.
Synopsis:
./st seconds
where seconds is an integer indicating the beginning of the countdown.
Sample Usages:
./st 30 causes the timer to count down from 30 to 0
./st prints synopsis
Ctrl-C causes the timer to pause/unpause
Ctrl-\\ causes the program to exit gracefully and ensure that echoing is turned back on.
Hints:
man 3 sleep - use this to make your program wait a second
man 7 signal
spinlock - use this to pause your program. continue can be helpful with this.
if( paused ) continue;
fflush - use this to ensure your output gets to the screen
You may need to turn echoing on, print the seconds, then turn echoing back off.
Solution
Perl prorgram for count down is given below:
#!/usr/bin/perl
use warnings;
use strict;

my $timeCounter = 30;

while($timeCounter > 0){

print(\"$timeCounter\ \");

# count down
$timeCounter--;

# pause program for 1 second
sleep(1);

if($timeCounter == 0){
print(\"Time count zero\ \");
}
}
.

Anzeige
Anzeige

Weitere Verwandte Inhalte

Ähnlich wie Write a simple timer program- The program will accept a number of seco.docx (20)

Weitere von lez31palka (20)

Anzeige

Aktuellste (20)

Write a simple timer program- The program will accept a number of seco.docx

  1. 1. Write a simple timer program. The program will accept a number of seconds as a command line argument, and steadily count down to 0, decreasing the counter once every second. Echoing should be turned off as the program runs, and should be turned back on once the program exits. If the user hits Ctrl-C, the timer will pause/unpause. If the user hits Ctrl-, the program turns echoing back on then terminates. Synopsis: ./st seconds where seconds is an integer indicating the beginning of the countdown. Sample Usages: ./st 30 causes the timer to count down from 30 to 0 ./st prints synopsis Ctrl-C causes the timer to pause/unpause Ctrl- causes the program to exit gracefully and ensure that echoing is turned back on. Hints: man 3 sleep - use this to make your program wait a second man 7 signal spinlock - use this to pause your program. continue can be helpful with this. if( paused ) continue; fflush - use this to ensure your output gets to the screen You may need to turn echoing on, print the seconds, then turn echoing back off. Solution
  2. 2. Perl prorgram for count down is given below: #!/usr/bin/perl use warnings; use strict; my $timeCounter = 30; while($timeCounter > 0){ print("$timeCounter "); # count down $timeCounter--; # pause program for 1 second sleep(1); if($timeCounter == 0){ print("Time count zero "); } }

×