PDA

View Full Version : Lazy to correct error... lol



adarshakb
07-21-2009, 12:29 PM
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:

tomws
07-21-2009, 03:10 PM
You're right: you are lazy. Maybe your prof will discover your laziness and reward you with a failing grade.

Millenia
07-21-2009, 03:45 PM
This isn't a place to have programs made for you simply because you are lazy. Either post a paid request in the Marketplace (http://codingforums.com/forumdisplay.php?f=64), or start a new thread where you can work out you're problems with the help of others.

Also see rule 1.5 in the Forum Rules (http://www.codingforums.com/rules.htm).


Now, you may ask for advice or help on a specific aspect of your assignment that you're having trouble with. Use common sense as far as what's acceptable in terms of soliciting help with homework assignments.