C++ Programming Blog

 
 
 

Image

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



 //------------------------------  date  ---------------------------------//


 class date
    {
       private:
        char str[9];

       public:
        date()
           {
              str[0]=\'\\0\';
           }

        date(char *s)
           {
              strcpy(str,s);
           }

        void show_date()
           {
              cout<<\"\\t Date is = \"<<str<<endl;
           }
    };


 //------------------------------  dmy  ----------------------------------//


 class dmy
    {
       private:
        int day;
        int month;
        int year;

       public:
        dmy()
           {
              day=month=year=0;
           }

        dmy(int,int,int);

        void show_date()
           {
              cout<<\"\\t Date is : \"<<day<<\":\"<<month<<\":\"<<year<<endl;
           }

        operator date();
    };



 //------------------------  Function Definitions  -----------------------//





 //------------------------------  date   --------------------------------//




 //---------------------------  dmy(int,int,int)  ------------------------//


 dmy::dmy(int d,int m,int y)
    {
       day=d;
       month=m;
       year=y;
    }


 //---------------------------  date( )  ---------------------------------//


 dmy::operator date()
    {
       char temp[3]={\'\\0\'};
       char str[9]={\'\\0\'};

       itoa(day,str,10);
       strcat(str,\"/\");
       itoa(month,temp,10);
       strcat(str,temp);
       strcat(str,\"/\");
       itoa(year,temp,10);
       strcat(str,temp);

       return date(str);
    }


 main()
    {
       clrscr();

       date d_1;

       dmy d_2(6,10,81);

       d_1=d_2;

       cout<<\"\\n Value of d_1 is : \"<<endl;
       d_1.show_date();

       cout<<\"\\n Value of d_2 is : \"<<endl;
       d_2.show_date();

       getch();
       return 0;
    }

 
 
Didn't find what you were looking for? Find more on Program to illusrate data conversion user defined data types using functions