#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<iomanip.h>
class time1
{
protected:
int hr,min,sec;
public:
time1(int h,int m,int s);
};
class date1
{
protected:
int dt,mon,yr;
public:
date1(int d,int m1,int y);
};
class clock:public time1,public date1
{
char str[3];
public:
clock(int h,int m,int s,int d,int m1,int y);
void showclock();
void inc();
};
time1::time1(int h,int m,int s)
{
hr=h;min=m;sec=s;
}
date1::date1(int d,int m1,int y)
{
dt=d;mon=m1;yr=y;
}
clock::clock(int h,int m,int s,int d,int m1,int y):time1(h,m,s),date1(d,m1,y)
{
}
void clock::showclock()
{
gotoxy(10,10);
cout<<setw(2)<<hr<<":"<<setw(2)<<min<<":"<<setw(2)<<sec<<str;
gotoxy(10,12);
cout<<dt<<":"<<mon<<":"<<yr<<endl;
}
void clock::inc()
{
sec++;
if(sec>=60)
{
sec=0;
min++;
}
if(min>=60)
{
min=0;
hr++;
}
if(hr>=12)
strcpy(str,"PM");
else
strcpy(str,"AM");
}
void main()
{
clrscr();
clock t(11,59,45,29,6,2009);
clrscr();
gotoxy(10,8);
cout<<"Digital Clock";
while(!kbhit())
{
t.showclock();
delay(10);
t.inc();
}
}
Comments
Post a Comment