Télécharger objet.dgibi

Retour à la liste

Numérotation des lignes :

  1. * fichier : objet.dgibi
  2. ************************************************************************
  3. ************************************************************************
  4. *
  5. * creation of object of class "complex number".
  6. *
  7. * define first the constructor
  8. DEBMETH COMPLEX;
  9. %REA=FAUX;
  10. %IMA=FAUX;
  11. %METHODE SET_IMA IMAG;
  12. %METHODE SET_REA REAL;
  13. %METHODE GET_IMA GIMAG;
  14. %METHODE GET_REA GREAL;
  15. FINMETH;
  16.  
  17.  
  18.  
  19.  
  20. * define standard methods of the class
  21. DEBMETH IMAG I*'FLOTTANT';
  22. %IMA = I;
  23. 'SI' ('EGA' ('TYPE' %REA ) 'FLOTTANT');
  24. %METHODE MODULE MODUL;
  25. 'FINSI';
  26. FINMETH;
  27.  
  28.  
  29. DEBMETH REAL RR*'FLOTTANT';
  30. %REA = RR;
  31. 'SI' ('EGA' ('TYPE' %IMA ) 'FLOTTANT');
  32. %METHODE MODULE MODUL;
  33. 'FINSI';
  34. FINMETH;
  35.  
  36.  
  37. DEBMETH GIMAG ;
  38. II = %IMA;
  39. 'SI' ( 'NEG' ( 'TYPE' II) 'FLOTTANT');
  40. 'MESSAGE' 'The imaginary value is not yet defined';
  41. 'ERREUR' 19;
  42. 'FINSI';
  43. FINMETH II;
  44.  
  45. DEBMETH GREAL;
  46. RR = %REA;
  47. 'SI' ( 'NEG' ( 'TYPE' RR) 'FLOTTANT');
  48. 'MESSAGE' 'The real value is not yet defined';
  49. 'ERREUR' 19;
  50. 'FINSI';
  51. FINMETH RR;
  52.  
  53.  
  54. DEBMETH MODUL;
  55. * It is not neccessary to check that real and imaginary exist
  56. AA= %REA* %REA + ( %IMA*%IMA) ** 0.5;
  57. FINMETH AA;
  58.  
  59. *
  60. * creation of a COMPLEX OBJET and use
  61. *
  62. COM = OBJET COMPLEX;
  63.  
  64. list com;
  65. COM%SET_REA 2.5;
  66. UU=COM%GET_REA; MESS ' real value ' uu;
  67.  
  68.  
  69. COM%SET_IMA 3.5;
  70. list com;
  71.  
  72.  
  73. ZZ = COM%MODULE ; list ZZ;
  74.  
  75. *
  76. * set a new method MULTIplication
  77. *
  78. DEBMETH MULT RR;
  79. 'SI' (( 'EGA' ('TYPE' RR ) 'ENTIER ') 'OU'
  80. ( 'EGA' ('TYPE' RR ) 'FLOTTANT'));
  81. %REA=%REA*RR; %IMA=%IMA*RR;
  82. 'SINON';
  83. 'SI' ( 'EGA' ('TYPE' RR ) 'OBJET ') ;
  84. RE = %REA*(RR%GET_REA) -( %IMA * (RR%GET_IMA));
  85. IM = %REA*(RR%GET_IMA) +(%IMA *(RR%GET_REA));
  86. %REA=RE; %IMA=IM;
  87. 'SINON';
  88. MESS ' Multiplication impossible';
  89. ERREUR 19;
  90. 'FINSI';
  91. 'FINSI';
  92. FINMETH;
  93. *
  94. * add the new method to the object COM
  95. *
  96. COM%METHODE MULTI MULT;
  97. list com;
  98.  
  99. COM%MULTI 3.5;
  100. list com;
  101. aa = OBJET complex;
  102. aa%set_ima 2;
  103. aa%set_rea 2;
  104. com%multi aa;
  105. list com;
  106. yy = com%GET_REA; xx = COM%GET_IMA;
  107.  
  108. * aa va heriter de la methode MULTI via
  109. * l'heritage entre objet
  110.  
  111. aa%HERITE COM;
  112. list aa;
  113.  
  114.  
  115.  
  116. 'SI' (( ABS( YY + 7.00)) > 1.e-5); ERREUR 5;FINSI;
  117. 'SI' (( ABS( XX - 42.0)) > 1.e-5) ; erreur 5; finsi;
  118. FIN;
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  

© Cast3M 2003 - Tous droits réservés.
Mentions légales