C++ Programming Blog

 
 
 
# include <iostream.h>
# include <conio.h>
# include <stdlib.h>

class date
{
    int mm,dd,yy;
    public:
    date()
    {
    }
    date(char dt[])
    {
        dd=getdt(dt,0);
        mm=getdt(dt,3);
        yy=getdt(dt,6);
    }

    int getdt(char *,int);
    void display();
};

main()
{
date d1;
char dt[10];
clrscr();
cout<<\"ENTER THE DATE IN DD/MM/YY FORMAT:->\";
cin>>dt;
d1=date(dt);
d1.display();
}

int date::getdt(char dt[],int i)
{
    char temp[2];
    temp[0]=dt[i];
    temp[1]=dt[i+1];
    temp[2]=\'\\0\';
    return atoi (temp);
}
void date::display()
{
    cout<<\"DAY= \"<<dd<<endl;
    cout<<\"\\nMONTH= \"<<mm<<endl;
    cout<<\"\\nYEAR= \"<<yy<<endl;
}

 
 
Didn't find what you were looking for? Find more on PROGRAM OF BASIC TO CLASS CONVERSION