Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in c++ 2010 express, I have a countdown timer where you input the number of seconds to start counting down from and then beeps when

in c++ 2010 express, I have a countdown timer where you input the number of seconds to start counting down from and then beeps when it gets to zero, but not sure how to get each output to overwrite the previous value displayed like a real-world timer. How can I get the countdown timer to open in a new window. Here is the code:

#include "stdafx.h" #include using namespace std;

class Timer { public: // declaration of functions void reduce(int time); int reset(int time); };

// definition of functions int Timer::reset(int time) { return time; }

void reduce_1() { int i; for(i=0;i<=1000000000 ; i++) { // empty for loop as asked in the question to keep null to reduce the time by 1 second } }

void Timer :: reduce (int time) { for(int i =time;i>0 ;i--) { cout<<"Time left is : "< reduce_1(); } cout << '\a' << endl; }

int main() // start main { Timer T1; // making an object of the class Timer

// decalre seconds variable int s; char choice; cout << "Countdown Timer Program " << endl; // ask user for input to start the timer countdown cout << "Enter time in seconds: " << endl; cin >> s; cout << "Press any key to start" << endl; cout << "Countdown Timer Program" << endl; cout << "time remaining" << endl; cout << "secs : " << s << endl;

// now here we have taken the time as input that is in s // so we will call the reduce function of the class Timer T1.reduce(s); // this will run for s seconds // end the program cout, beep sound is played

// here the program has ended and we will now ask whether // it wants to reset the timer cout<<"If it wants to reset the timer : y or n"< cin>> choice ; if(choice == 'y') { cin>>s; // we'll take the input again for how much time the timer has to run int time = T1.reset(s); T1.reduce(time); } else { //nothing has to be done }

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

=+j Describe the various support services delivered by IHR.

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago