1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | #include <iostream.h> #include <string.h> #define MAX 20 class objetassure{ float montant; char type[MAX]; public : objetassure( float mt=0.0, char tp[MAX]= "" ); void affiche(); }; class ordinateur: public virtual objetassure{ int ram; int hardisk; public : ordinateur( int rm=0, int hd=0, float mt=0.0, char tp[MAX]= "" ); void affiche(); }; class bagage: virtual public objetassure{ char type1[MAX]; float poids; public : bagage( char tp1[MAX]= "" , float pd=0, float mt=0.0, char tp[MAX]= "" ); void affiche(); }; class ordinateurportable: public ordinateur, public bagage{ float poids1; float epaisseur; public : ordinateurportable( float pd1=0.0, float epaiss=0.0, int rm=0, int hd=0, char tp1[MAX]= "" , float pd=0.0); //pas obligation de mettre les autres paramètres de objetassure //ici je ne le fais pas mais pour afficher il vaudrait mieux ;-) void affiche(); }; objetassure::objetassure( float mt, char tp[MAX]){ montant=mt; strcpy (type,tp); } void objetassure::affiche(){ cout<< "montant: " <<montant<<endl; cout<< "objet assure type: " <<type<<endl; } ordinateur::ordinateur( int rm, int hd, float mt, char tp[MAX]):objetassure(mt,tp){ ram=rm; hardisk=hd; } void ordinateur::affiche(){ objetassure::affiche(); cout<< "Mémoire type ram : " <<ram<<endl; cout<< "Disque Dur: " <<hardisk<<endl; } bagage::bagage( char tp1[MAX], float pd, float mt, char tp[MAX]):objetassure(mt,tp){ strcpy (type1,tp1); poids=pd; } void bagage::affiche(){ objetassure::affiche(); cout<< "Type de bagage: " <<type1<<endl; cout<< "Poids du bagage: " <<poids<<endl; } ordinateurportable::ordinateurportable( float pd1, float epaiss, int rm, int hd, char tp1[MAX], float pd):ordinateur(rm,hd),bagage(tp1,pd){ poids1=pd1; epaisseur=epaiss; } void ordinateurportable::affiche(){ ordinateur::affiche(); bagage::affiche(); cout<< "ordinateur portable poids: " <<poids1<<endl; cout<< "epaisseur: " <<epaisseur<<endl; } void main(){ int k; ordinateurportable orpor(10,10,256,160, "a main" ,50); //attention a l affichage orpor.affiche(); cin>>k; } |
- Friday
- May 16th, 2025
- Ajouter un cours