/* copyright P. TRAU ULP - IPST janvier 2005 */ #include <iostream.h> #include <string.h> #include "date.cpp" #define LTXT 20 #define Max 200 typedef char texte[LTXT]; /***************************************************************************/ class identite { texte nom,prenom; date naissance; // et son adresse, son num de telephone,... public: date get_date_naissance(void) {return naissance;} void saisie(void); void affiche(void); }; void identite::saisie(void) { cout<<"nom ? ";cin>>nom; cout<<"prenom ? ";cin>>prenom; cout<<"naissance ? ";cin>>naissance; } void identite::affiche(void) { cout<<prenom<<" "<<nom<<", ne(e) "<<naissance; } // Surcharge de l'operateur << ostream& operator << (ostream& f, identite &x) { x.affiche(); return (f); } // Surcharge de l'operateur >> istream& operator >> (istream& e, identite &d) { d.saisie(); return (e); } /***********************************************************************/ class adherent : public identite { date adhesion; public: date get_date_adhesion(void) {return adhesion;} void saisie_adhesion(void); int est_a_jour(void); }; void adherent::saisie_adhesion(void) { cout<<"Date d'adhesion ? ";cin>>adhesion; //cin>> connu pour une date } int adherent::est_a_jour(void) { date actu,limite; actu.maintenant(); limite=adhesion+365; //dans date.cpp on a surchargéeacute; l'addition d'une date et d'un entier if(limite>actu)return 1; else return 0; } // Surcharge de l'operateur << ostream& operator << (ostream& f, adherent &x) { date a; x.affiche(); //c'est l'affiche heritéeacute; de l'identite a=x.get_date_adhesion(); //réeacute;cupéeacute;réeacute; par l'accesseur, puisque adhesion est privéeacute; cout<<". Date d'adhesion : "<<a; return (f); } // Surcharge de l'operateur >> istream& operator >> (istream& e, adherent &d) { d.saisie(); d.saisie_adhesion(); return (e); } /**************************************************************************/ class fichier { int nb; adherent t[Max]; public: void saisie(void); void affiche(void); //affichage de tout void affiche(int); //affichage d'un seul : le i-ièegrave;me void affiche_non_a_jour(void); void affiche_entre_dates(void); }; void fichier::saisie(void) { int i; cout<<"Combien d'adhéeacute;rents ? "; cin>>nb; for(i=0;i<nb;i++) { cout<<"adhéeacute;rent n° "<<i+1<<" : "; cin>>t[i]; } } void fichier::affiche(int i) {cout<<t[i];} //il sait affichier un adhéeacute;rent void fichier::affiche(void) { int i; cout<<"il y a "<<nb<<" adhéeacute;rents.\n"; for(i=0;i<nb;i++) { cout<<i+1<<" : "; affiche(i); cout<<"\n"; } } // Surcharge de l'operateur << ostream& operator << (ostream& f, fichier &x) {x.affiche();return (f);} // Surcharge de l'operateur >> istream& operator >> (istream& e, fichier &d) {d.saisie();return (e);} void fichier::affiche_non_a_jour(void) { int i; for(i=0;i<nb;i++) if(!(t[i].est_a_jour()))cout<<t[i]<<" n'est pas àagrave; jour !\n"; } void fichier::affiche_entre_dates(void) { int i; date d1,d2,d; cout<<"date mini ? "; cin>>d1; cout<<"gate maxi ? "; cin>>d2; for(i=0;i<nb;i++) { d=t[i].get_date_adhesion(); if(d>=d1 && d<=d2) cout<<t[i]<<" est dans ces limites\n"; } } /*************************************************************************************/ // Programme de test int main(void) { fichier t; t.saisie(); cout<<"---- test affichage complet\n"; t.affiche(); cout<<"---- test affichage non àagrave; jour\n"; t.affiche_non_a_jour(); cout<<"---- test affichage entre deux dates\n"; t.affiche_entre_dates(); }
(c) P. TRAU IPST - ULP 12/01/2005