Vous êtes sur la page 1sur 3

#include<iostream.

h>
#include<conio.h>
#include<string.h>
class date {
public :
int j;
int m;
int a;

date(){ j=1; m=1; a=2011;}


};

class article
{
private :
char nom[20];
char prenom[15];
date d_pr ;
public:
article()
{
strcpy(nom,"toto");
strcpy(prenom, "titi");
d_pr.j=13;
d_pr.m=5;
d_pr.a=2011;
}

void saisie()
{ cout<<"\ndonner nom prenom : ";
cin>>nom>>prenom;
cout<<"\ndonner date jou mois an :";
cin>>d_pr.j>>d_pr.m>>d_pr.a;
}
void affiche()
{ cout<<"\n-------- Affichage ----------\n";
cout<<"\nNom : "<<nom;
cout<<"\nPrenom : "<<prenom;
cout<<"\nDate Peremption : "<<d_pr.j<<" / "<<d_pr.m<<" / "<<d_pr.a<<endl;
}
friend int operator <=(article &, article &);
};
int operator <=(article &x, article &y)
{ if((x.d_pr.a)<=(y.d_pr.a))
{ if((x.d_pr.m)<=(y.d_pr.m))
{ if((x.d_pr.j)<=(y.d_pr.j))
return(1);
else return (0);
}
else return (0);
}
else return (0);
}

int main()
{ int rep;
char p[4];
article x1;
article x2;
do{ x1.saisie();
x2.saisie();
x1.affiche();
x2.affiche();
rep= (x1<= x2) ? 1 :0;
if( rep==1)
{cout<<"\n\n\n l article qui expire en premier est : " ;x1.affiche();}
else
{cout<<"\n\n\n l article qui expire en premier est : " ; x2.affiche();}
cout<<"\n\nvoulez vous recommencer oui/non? ";
cin>>p;
}while(strcmp(p,"oui")==0);

getch();
return 0;
}