Ask a Teacher



can u give an example of a program in c++ which checks system date and activates on particular date???


I.This program can be used to set the system date or to change the current system date

#include <stdio.h>

#include <process.h>

#include <dos.h>

int main(void)

{

struct date reset;

struct date save_date;

getdate(&save_date);

printf(“Original date:\n”);

system(“date”);

reset.da_year = 2001;

reset.da_day = 1;

reset.da_mon = 1;

setdate(&reset);

printf(“Date after setting:\n”);

system(“date”);

setdate(&save_date);

printf(“Back to original date:\n”);

system(“date”);

return 0;

}

 

II.This program reads the current system time and displays it in the form HH:MM:SS

#include <stdio.h>

#include <dos.h>

int main(void)

{

struct time t;

gettime(&t);

printf(“The current time is: %2d:%02d:%02d\n”, t.ti_hour, t.ti_min, t.ti_sec);

return 0;

}

III.This program will get or read the current system date from the system. It displays Year, Month and Day.

 #include <dos.h>

#include <stdio.h>

int main(void)

{

struct date d;

getdate(&d);

printf(“The current year is: %d\n”, d.da_year);

printf(“The current day is: %d\n”, d.da_day);

printf(“The current month is: %d\n”, d.da_mon);

return 0;

}



comments powered by Disqus