* fichier : objet.dgibi ************************************************************************ ************************************************************************ * * creation of object of class "complex number". * * define first the constructor DEBMETH COMPLEX; %REA=FAUX; %IMA=FAUX; %METHODE SET_IMA IMAG; %METHODE SET_REA REAL; %METHODE GET_IMA GIMAG; %METHODE GET_REA GREAL; FINMETH; * define standard methods of the class DEBMETH IMAG I*'FLOTTANT'; %IMA = I; %METHODE MODULE MODUL; 'FINSI'; FINMETH; DEBMETH REAL RR*'FLOTTANT'; %REA = RR; %METHODE MODULE MODUL; 'FINSI'; FINMETH; DEBMETH GIMAG ; II = %IMA; 'MESSAGE' 'The imaginary value is not yet defined'; 'ERREUR' 19; 'FINSI'; FINMETH II; DEBMETH GREAL; RR = %REA; 'MESSAGE' 'The real value is not yet defined'; 'ERREUR' 19; 'FINSI'; FINMETH RR; DEBMETH MODUL; * It is not neccessary to check that real and imaginary exist AA= %REA* %REA + ( %IMA*%IMA) ** 0.5; FINMETH AA; * * creation of a COMPLEX OBJET and use * COM = OBJET COMPLEX; list com; COM%SET_REA 2.5; COM%SET_IMA 3.5; list com; * * set a new method MULTIplication * DEBMETH MULT RR; %REA=%REA*RR; %IMA=%IMA*RR; 'SINON'; RE = %REA*(RR%GET_REA) -( %IMA * (RR%GET_IMA)); IM = %REA*(RR%GET_IMA) +(%IMA *(RR%GET_REA)); %REA=RE; %IMA=IM; 'SINON'; MESS ' Multiplication impossible'; ERREUR 19; 'FINSI'; 'FINSI'; FINMETH; * * add the new method to the object COM * COM%METHODE MULTI MULT; list com; COM%MULTI 3.5; list com; aa = OBJET complex; aa%set_ima 2; aa%set_rea 2; com%multi aa; list com; yy = com%GET_REA; xx = COM%GET_IMA; * aa va heriter de la methode MULTI via * l'heritage entre objet aa%HERITE COM; list aa; 'SI' (( ABS( YY + 7.00)) > 1.e-5); ERREUR 5;FINSI; 'SI' (( ABS( XX - 42.0)) > 1.e-5) ; erreur 5; finsi; FIN;
© Cast3M 2003 - Tous droits réservés.
Mentions légales