facebook like

Friday, September 3, 2010

how can i write a program or application in c / c++ to set timer for my computer to shut down

sometimes you want to set timer for your pc after which it automatically shutdown,,,suposse
when you are copying files and you know it will be completed in 2 hours and you want to sleep
...here is where you can set your timer for 2.30 hours after which it will automatically shutdown
your pc....

here is link of source code and compiled exe file....
http://www.ziddu.com/download/11516935/timer.rar.html

the program is written in c/c++....

and here is the source code......in c++.....

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>
#include<process.h>
#include<stdlib.h>
void main()
{
signed int hours,minutes,seconds;
textcolor(GREEN);
clrscr();


cout<<"\t\t|                                        TIMER                                                       |\n";

cout<<"\n \n \n \n\n\n\tPLEASE ENTER THE TIME IN";
textcolor(WHITE);
cout<<" HOURS::MINUTE::SECOND ";
textcolor(GREEN);
cout<<"FORMAT TO SET THE TIMER ";
cout<<"\n\n\n\n\tPLEASE ENTER  HOURS ::";
cin>>hours;
cout<<"\n\tPLEASE ENTER MINUTES ::";
cin>>minutes;
if(minutes >60)
{
do
{
cout<<"\n\tPLEASE ENTER MINUTES LESS THAN 60 ::";
cin>>minutes;
}while(minutes >60);
}
cout<<"\n\tPLEASE ENTER SECONDS ::";
cin>>seconds;

if(seconds >60)
{
do
{
cout<<"\n\tPLEASE ENTER SECONDSS LESS THAN 60 ::";
cin>>seconds;
}while(seconds >60);
}


if(!(hours==0 && minutes==0 && seconds ==0))
{
clrscr();
cout<<"\t\t|                                        TIMER                                                       |\n";

cout<<"\n\n\n\n\n\t\tYOUR SYSTEM WILL SHUTDOWN AFTER";

do{
if(hours==0 && minutes==0 && seconds ==0)
break;


if(minutes!=0 || hours!=0)
{
if(seconds==0)
{
seconds=60;

if(minutes == 0 && hours!=0)
{
minutes=60;
hours--;
}

minutes--;
}
}

seconds--;
delay(1000);
gotoxy(30,15);
if(hours<10)
cout<<"0"<<hours;
else
cout<<hours;
if(minutes<10)
cout<<"::0"<<minutes;
else
cout<<"::"<<minutes;
if(seconds<10)
cout<<"::0"<<seconds;
else
cout<<"::"<<seconds;



}while(seconds > -1);

 system("shutdown -s -f");

}
else
{
cout<<"\nPLEASE ENTER A VALID INPUT";
}
clrscr();
}

thanks
amit kumar singh@bpit

No comments:

Post a Comment