In C++, Design, implement and test a countdown timer class named Timer. This cla
ID: 3680077 • Letter: I
Question
In C++, Design, implement and test a countdown timer class named Timer. This class mimics a real-world timer by counting off seconds, starting from the initial value. When the timer reaches zero, it beeps (by sending the alert character, ‘’ to the standard output device). Some appropriate operations might be the following: ---- Create a timer instantiating it to a specified number of seconds ---- Start the timer -----Reset the timer to some value When the Start operation is invoked, it should repeatedly decrement and output the current value of the timer approximately every second. To delay the program for one second use a For loop whose body does absolutely nothing : that is its body is the null statement. Experiment with the number of loop iterations to achieve as close to a one-second delay as you can. Display the timer value at the same position in the center of the screen. Each output should overwrite the previous value displayed like a real-world timer.
Explanation / Answer
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
using namespace std;
int main()
{
int m, s,h;
cout << "A COUNTDOWN TIMER " << endl;
cout << "enter time in hours here" << endl;
cin >> h;
cout << "enter time in minutes here " << endl;
cin >> m;
cout << "enter im in seconds here" << endl;
cin >> s;
cout << "Press any key to start" << endl;
cout << " A COUNTDOWN TIMER" << endl;
cout << "time remaining" << endl;
cout << "hours : " << h << "mins : " << m << " secs : " << s << endl;
for (int hour = h; hour >= 0; hour--)
{
for (int min = m; min >= 0 ; min--)
{
if ( min == 0 && h > 0)
m = 59;
for (int sec = s; sec >= 0; sec--)
{
if ( sec == 0 )
s = 59;
Sleep(1000);
system("clear");
cout << hour << " :hours " << min << " :mins " << sec << " :secs" << endl;
}
}
}
Sleep(1000);
cout << "THE END" << endl;
return 0;