adarshakb
07-21-2009, 11:29 AM
here is my prg
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
class dmy
{
private:
int d,m,y;
public:
dmy()
{
d=m=y=0;
};
dmy(int dd,int mm,int yy)
{
d=dd;m=mm;y=yy;
};
int getDate()
{
return d;
};
int getMonth()
{
return m;
};
int getYear()
{
return y;
};
void disp()
{
cout<<"\n"<<d<<"/"<<m<<"/"<<y;
};
};
class date
{
private:
char d[9];
public:
date()
{
strcpy(d,"1/1/2000");
}
date(char *p)
{
if(strlen(p)>9)
{
cout<<"Wrong Input";
return;
}
strcpy(d,p);
}
date(dmy x)
{
int d,m,y;
d=x.getDate();
m=x.getMonth();
y=x.getYear();
char tmp[4];
char ans[9];
itoa(d,tmp,10);
strcpy(ans,tmp);
strcat(ans,"/");
itoa(m,tmp,10);
strcat(ans,tmp);
strcat(ans,"/");
itoa(y,tmp,10);
strcat(ans,tmp);
strcpy(this->d,ans);
}
void disp()
{
cout<<"\n"<<d;
}
};
void main()
{
date a;
dmy b(21,06,1990);
a=b;
a.disp();
}
and another one
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
class date
{
private:
char d[9];
public:
date()
{
strcpy(d,"01/01/0000");
}
date(char *p)
{
if(strlen(p)>9)
{
cout<<"Bad input";
return;
}
strcpy(d,p);
}
void disp()
{
cout<<"\n"<<d;
}
};
class dmy
{
private:
int d,m,y;
public:
dmy()
{
d=m=y=0;
}
dmy(int dd,int mm,int yy)
{
d=dd;m=mm;y=yy;
}
void disp()
{
cout<<"\n"<<d<<"/"<<m<<"/"<<y;
}
operator date()
{
char tmp[4];char ans[9];
itoa(d,tmp,10);
strcpy(ans,tmp);
strcat(ans,"/");
itoa(m,tmp,10);
strcat(ans,tmp);
strcat(ans,"/");
itoa(y,tmp,10);
strcat(ans,tmp);
return date(ans);
}
};
void main()
{
dmy a(21,06,1990);
date b=a;
b.disp();
}
in the output i see some special char.. so if any are free correct this:D within 4-5hrs
lol i am busy now so dint get time to correct it... np if no one replies :thumbsup:
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
class dmy
{
private:
int d,m,y;
public:
dmy()
{
d=m=y=0;
};
dmy(int dd,int mm,int yy)
{
d=dd;m=mm;y=yy;
};
int getDate()
{
return d;
};
int getMonth()
{
return m;
};
int getYear()
{
return y;
};
void disp()
{
cout<<"\n"<<d<<"/"<<m<<"/"<<y;
};
};
class date
{
private:
char d[9];
public:
date()
{
strcpy(d,"1/1/2000");
}
date(char *p)
{
if(strlen(p)>9)
{
cout<<"Wrong Input";
return;
}
strcpy(d,p);
}
date(dmy x)
{
int d,m,y;
d=x.getDate();
m=x.getMonth();
y=x.getYear();
char tmp[4];
char ans[9];
itoa(d,tmp,10);
strcpy(ans,tmp);
strcat(ans,"/");
itoa(m,tmp,10);
strcat(ans,tmp);
strcat(ans,"/");
itoa(y,tmp,10);
strcat(ans,tmp);
strcpy(this->d,ans);
}
void disp()
{
cout<<"\n"<<d;
}
};
void main()
{
date a;
dmy b(21,06,1990);
a=b;
a.disp();
}
and another one
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
class date
{
private:
char d[9];
public:
date()
{
strcpy(d,"01/01/0000");
}
date(char *p)
{
if(strlen(p)>9)
{
cout<<"Bad input";
return;
}
strcpy(d,p);
}
void disp()
{
cout<<"\n"<<d;
}
};
class dmy
{
private:
int d,m,y;
public:
dmy()
{
d=m=y=0;
}
dmy(int dd,int mm,int yy)
{
d=dd;m=mm;y=yy;
}
void disp()
{
cout<<"\n"<<d<<"/"<<m<<"/"<<y;
}
operator date()
{
char tmp[4];char ans[9];
itoa(d,tmp,10);
strcpy(ans,tmp);
strcat(ans,"/");
itoa(m,tmp,10);
strcat(ans,tmp);
strcat(ans,"/");
itoa(y,tmp,10);
strcat(ans,tmp);
return date(ans);
}
};
void main()
{
dmy a(21,06,1990);
date b=a;
b.disp();
}
in the output i see some special char.. so if any are free correct this:D within 4-5hrs
lol i am busy now so dint get time to correct it... np if no one replies :thumbsup: