|
|
| (19 revisiones intermedias por el mismo usuario no mostrado) |
| Línea 1: |
Línea 1: |
| − | {{Usuario:ManuelRomero/ProgramacionWeb/Objetos/nav}}
| + | <div id="parrafo"> |
| | ===Calculadora Real/Racional=== | | ===Calculadora Real/Racional=== |
| | + | ;Puedes probar una posible solución |
| | + | https://web.infenlaces.com/dwes/practicas/calculadora/ |
| | + | *clona el esqueleto (con código implementado) |
| | + | <source lang=bash> |
| | + | git clone https://github.com/MAlejandroR/DWES_practica_calculadora.git |
| | + | </source> |
| | + | ============================================================= |
| | + | |
| | + | ;Enunciado |
| | *Se pide que realicemos una aplicación web que resuelva cálculos aritméticos con operadores reales o racionales | | *Se pide que realicemos una aplicación web que resuelva cálculos aritméticos con operadores reales o racionales |
| | *La operación se insertará en una caja de texto | | *La operación se insertará en una caja de texto |
| Línea 11: |
Línea 20: |
| | *El tipo de operación, la deberemos obtener según nos indique un método stático de la clase operación según se indica más abajo. | | *El tipo de operación, la deberemos obtener según nos indique un método stático de la clase operación según se indica más abajo. |
| | *En la pantalla mostraremos un pequeño texto explicativo y una caja de texto donde el usuario podrá interactuar | | *En la pantalla mostraremos un pequeño texto explicativo y una caja de texto donde el usuario podrá interactuar |
| − | [[Archivo:PracticaCalculadoraIndex1.png|700px]] | + | [[Archivo:PracticaCalculadoraIndex1.png|1024px]] |
| | | | |
| − | *En el siguiente enlace se puede ver el funcionamiento esperado en esta prácticas
| + | <br /> |
| − | {{MRM_Recursos de la Web|Title=Pŕactica de la calculadora Real - Racional|
| + | |
| − | http://manuel.infenlaces.com/distancia/dwes/practicas/practica_5_Calculadora/index.php
| + | |
| − | }}
| + | |
| − | *Vamos a aplicar una pequeña css para la pantalla
| + | |
| − | {{Plegable|hide|CSS para práctica de la calculadora|
| + | |
| − | <source lang=css>
| + | |
| − | fieldset{
| + | |
| − | border: 0.25em solid;
| + | |
| − | align : center;
| + | |
| − | position: absolute;
| + | |
| − | left: 55%;
| + | |
| − | top: 20%;
| + | |
| − | margin-left: -115px;
| + | |
| − | margin-top: -80px;
| + | |
| − | padding:10px;
| + | |
| − | background-color: #eee;
| + | |
| − | }
| + | |
| − | fieldset#rtdo{
| + | |
| − | border: 0.25em solid;
| + | |
| − | position: absolute;
| + | |
| − | left: 55%;
| + | |
| − | top: 55%;
| + | |
| − | padding:10px;
| + | |
| − | background-color: #eee;
| + | |
| − | }
| + | |
| − | fieldset#ayuda{
| + | |
| − | border: 0.25em solid;
| + | |
| − | position: absolute;
| + | |
| − | left: 10%;
| + | |
| − | top: 20%;
| + | |
| − | padding:10px;
| + | |
| − | background-color: #eee;
| + | |
| − | }
| + | |
| | | | |
| − | legend{
| |
| − | font-size: 2em;
| |
| − | color: green;
| |
| − | font-weight: bold;
| |
| − | }
| |
| − | input[type=submit] {
| |
| − | padding:5px 15px 10px 10px;
| |
| − | background:#ccc;
| |
| − | border:2;
| |
| − | cursor:pointer;
| |
| − | -webkit-border-radius: 5px;
| |
| − | border-radius: 5px;
| |
| − | margin: 1em;
| |
| − | font-size: 1em;
| |
| − | }
| |
| − | label{
| |
| − | font-weight: bold;
| |
| − | font-size : 1.5em;
| |
| − | margin: 0.65em;
| |
| − |
| |
| − | }
| |
| − | input[type=text]{
| |
| − | font-weight: bold;
| |
| − | font-size : 1.5em;
| |
| − | padding: 1em 1em 1em 1em;
| |
| − | margin: 1em 1em 1em 1em;
| |
| − | }
| |
| − | #texhelp{
| |
| − | font-size : 1.2em;
| |
| − | }
| |
| − | </source>
| |
| − | }}
| |
| | {{MRM_Ejemplo|Title= Operaciones que se pueden insertar| | | {{MRM_Ejemplo|Title= Operaciones que se pueden insertar| |
| | ;9/8+4/7 | | ;9/8+4/7 |
| Línea 86: |
Línea 30: |
| | ;9/5*5.6 (Éste es un caso de error) | | ;9/5*5.6 (Éste es un caso de error) |
| | }} | | }} |
| | + | <br /> |
| | *Al presionar intro aparecerá un texto (en el primer caso 9/8+4/7) | | *Al presionar intro aparecerá un texto (en el primer caso 9/8+4/7) |
| | [[Archivo:PracticaCalculadoraUso1.png|500px]] | | [[Archivo:PracticaCalculadoraUso1.png|500px]] |
| Línea 144: |
Línea 89: |
| | echo "$a+$b=$c"//Me visualizará 5/6+6/4=56/24, o bien simplificado 7/3 | | echo "$a+$b=$c"//Me visualizará 5/6+6/4=56/24, o bien simplificado 7/3 |
| | </source> | | </source> |
| − | *Por defecto todas las operaciones se deben de facilitar con el racional simplificado, salvo que se pase en la operación un segundo parámetro a valor false, en cuyo caso no se simplifica y se da el valor sin simplificar
| |
| − | <!--
| |
| − | {{Plegable|hide|Clase Racional|
| |
| − | <source lang=php>
| |
| − | <?php
| |
| | | | |
| − | class Racional {
| |
| − |
| |
| − | private $num;
| |
| − | private $den;
| |
| − |
| |
| − | /**
| |
| − | *
| |
| − | * @param type $num
| |
| − | * @param type $den
| |
| − | * @description Construimos un objeto de la clase recional en las siguientes situaciones
| |
| − | * //opciones new Racional () =>1/1
| |
| − | //opciones new Racional (5) =>5/1
| |
| − | //opciones new Racional (5,2) =>5/2
| |
| − | //opciones new Racional ("5/2") =>5/2
| |
| − | //opciones new Racional ("5") =>5/1
| |
| − |
| |
| − | //Otra sitiación no se instancia
| |
| − |
| |
| − | */
| |
| − | public function __construct($num, $den) {
| |
| − | if (is_null($den)) {
| |
| − | switch (is_numeric($num)) {
| |
| − | case true:
| |
| − | $this->num = $num;
| |
| − | $this->den = 1;
| |
| − | break;
| |
| − | case false:
| |
| − | if (is_null($num)) {
| |
| − | $this->num = 1;
| |
| − | $this->den = 1;
| |
| − | } else {
| |
| − | $this->num = (int) $num;
| |
| − | //if (strpos($num, "/") == FALSE) {
| |
| − | $this->den = (int) substr($num, strpos($num, "/") + 1);
| |
| − | //} else
| |
| − | // $this->den = 1;
| |
| − | }
| |
| − | break;
| |
| − | }
| |
| − | } else {
| |
| − | $this->num = $num;
| |
| − | $this->den = $den;
| |
| − | }
| |
| − | }
| |
| − |
| |
| − | /**
| |
| − | * @param Racional $op1 segundo operando
| |
| − | * @return \Racional Resultado de sumar al objeto racional actual, el objeto raciona que recibimos como parámetro
| |
| − | */
| |
| − | public function sumar(Racional $op1) {
| |
| − | $num = $this->num * $op1->den + $this->den * $op1->num;
| |
| − | $den = $this->den * $op1->den;
| |
| − | return new Racional($num, $den);
| |
| − | }
| |
| − |
| |
| − | /**
| |
| − | * @param Racional $op1 segundo operando
| |
| − | * @return \Racional Resultado de restar al objeto racional actual, el objeto raciona que recibimos como parámetro
| |
| − | */
| |
| − | public function restar(Racional $op1) {
| |
| − | $num = $this->num * $op1->den - $this->den * $op1->num;
| |
| − | $den = $this->den * $op1->den;
| |
| − | return new Racional($num, $den);
| |
| − | }
| |
| − |
| |
| − | /**
| |
| − | * @param Racional $op1 segundo operando
| |
| − | * @return \Racional Resultado de multiplicar al objeto racional actual, el objeto raciona que recibimos como parámetro
| |
| − | */
| |
| − | public function multiplicar(Racional $op1) {
| |
| − | $num = $this->num * $op1->num;
| |
| − | $den = $this->den * $op1->den;
| |
| − | return new Racional($num, $den);
| |
| − | }
| |
| − | /**
| |
| − | * @param Racional $op1 segundo operando
| |
| − | * @return \Racional Resultado de dividir al objeto racional actual, el objeto raciona que recibimos como parámetro
| |
| − | */
| |
| − | public function dividir(Racional $op1) {
| |
| − | $num = $this->num * $op1->den;
| |
| − | $den = $this->den * $op1->num;
| |
| − | return new Racional($num, $den);
| |
| − | }
| |
| − |
| |
| − | /**
| |
| − | *
| |
| − | * @return type un string del tipo a/b
| |
| − | */
| |
| − | public function __toString() {
| |
| − | return ($this->num . "/" . $this->den);
| |
| − | }
| |
| − | }
| |
| − | </source>
| |
| − | }}
| |
| | ;Operación | | ;Operación |
| | *Como vemos en el diagrama va a tener algún método abstracto, por lo que la vamos a considerar abstracta | | *Como vemos en el diagrama va a tener algún método abstracto, por lo que la vamos a considerar abstracta |
| Línea 253: |
Línea 99: |
| | *'''''Resultado''''' es el resultado de la operación, puede ser real o racional | | *'''''Resultado''''' es el resultado de la operación, puede ser real o racional |
| | *Esta clase descompondrá la operación y generará un resultado | | *Esta clase descompondrá la operación y generará un resultado |
| − | {{Plegable|hide|Clase Operacion|
| |
| − | <source lang=php>
| |
| − | <?php
| |
| − |
| |
| − | abstract class Operacion {
| |
| − |
| |
| − | //put your code here
| |
| − | protected $op1;
| |
| − | protected $op2;
| |
| − | protected $operador;
| |
| − | protected $operacion;
| |
| − | static protected $tipo;
| |
| − |
| |
| − | const RACIONAL = 1;
| |
| − | const REAL = 2;
| |
| − | const ERROR = -1;
| |
| − |
| |
| − | /**
| |
| − | * @param $operacion string que especifica la operación que se desar analizar
| |
| − | * @description Establece de qué tipo es una operación en función de sus argumentos
| |
| − | * * Operacion real numero_real operando numero_real
| |
| − | * * Operacion racional numero_racional operandoRacional numero_racional
| |
| − | * * Operacion racional numero_entero operandoRacional numero_racional
| |
| − | * * Operacion racional numero_racional operandoRacional numero_entero
| |
| − | * * Otro caso se especificará un error
| |
| − | *
| |
| − | * Usamos expresiones regulares para especificarlo
| |
| − | * **/
| |
| − |
| |
| − | public static function tipoOperacion($operacion) {
| |
| − | self::$tipo = Operacion::ERROR;
| |
| − |
| |
| − | $numReal = '[0-9]+(\.[0-9]*)?';
| |
| − | $numEntero = '[0-9]+';
| |
| − | $op = '[\+|\-|\*|\/]';
| |
| − | $numRacional = '[0-9]+\/[0-9]+';
| |
| − | $opRacional = '[\+|\-|\*|\:]';
| |
| − |
| |
| − |
| |
| − | $exp = "/^$numReal$op$numReal$/";
| |
| − | if (preg_match($exp, $operacion)) {
| |
| − | self::$tipo = Operacion::REAL;
| |
| − | } else {
| |
| − | /*Escribe el código que consideres*/
| |
| − |
| |
| − |
| |
| − |
| |
| − | }
| |
| − | return self::$tipo;
| |
| − |
| |
| − | }
| |
| − |
| |
| − | public function __construct($operacion) {
| |
| − | $this->operacion = $operacion;
| |
| − | $this->operador = $this->obtenerOperador($operacion);
| |
| − | $this->op1 = $this->obtenerOperador1($operacion);
| |
| − | $this->op2 = $this->obtenerOperador2($operacion);
| |
| − | }
| |
| − |
| |
| − | private function obtenerOperador1($operacion) {
| |
| − |
| |
| − | /*Escribe el código que consideres*/
| |
| − | }
| |
| − |
| |
| − | private function obtenerOperador2($operacion) {
| |
| − | /*Escribe el código que consideres*/
| |
| − | }
| |
| − |
| |
| − | private function obtenerOperador($operacion) {
| |
| − | /*Escribe el código que consideres*/
| |
| − |
| |
| − | }
| |
| − |
| |
| − |
| |
| − | /**
| |
| − | * Métodos get and set
| |
| − | */
| |
| − |
| |
| − |
| |
| − | public function getOp1() {
| |
| − | return $this->op1;
| |
| − | }
| |
| − |
| |
| − | public function getOp2() {
| |
| − | return $this->op2;
| |
| − | }
| |
| − |
| |
| − | public function getOperador() {
| |
| − | return $this->operador;
| |
| − | }
| |
| − |
| |
| − | public function getTipo() {
| |
| − | return $this->tipo;
| |
| − | }
| |
| − |
| |
| − | public function __toString() {
| |
| − | return "$this->op1$this->operador$this->op2";
| |
| − | }
| |
| − |
| |
| − | /**
| |
| − | *
| |
| − | * @return string que describe las propiedades de una operacion
| |
| − | * Lo devuelve como contenido de una tabla sin especificar la tabla
| |
| − | */
| |
| − | public function describe() {
| |
| − | $operacion = "<tr><th>Operando 1 </th> <th> $this->op1</th></tr>";
| |
| − | $operacion.="<tr><th>Operando 2 </th> <th> $this->op2</th></tr>";
| |
| − | $operacion.="<tr><th>Operación </th> <th> $this->operador</th></tr>";
| |
| − | if (self::$tipo == Operacion::RACIONAL)
| |
| − | $tipo = "Racional";
| |
| − | else
| |
| − | $tipo = "Real";
| |
| − | $operacion.="<tr><th>Tipo de operacion </th> <th> $tipo</th></tr>";
| |
| − | return $operacion;
| |
| − | }
| |
| − |
| |
| − | /**
| |
| − | * método abstracto que se implementará cuando se sepa si una operación es real o racional
| |
| − | */
| |
| − | abstract public function opera();
| |
| − | }
| |
| − |
| |
| − | </source>
| |
| − | }}
| |
| − | ;OpReal
| |
| − | {{Plegable|hide|Clase OperacionReal|
| |
| − | <source lang=php>
| |
| − | <?php
| |
| − |
| |
| − |
| |
| − | /**
| |
| − | * Description of OperacionReal
| |
| − | *
| |
| − | * @author manuel
| |
| − | */
| |
| − | class OperacionReal extends Operacion {
| |
| − |
| |
| − | public function __construct($operacion) {
| |
| − | parent::__construct($operacion);
| |
| − | }
| |
| − |
| |
| − | public function opera() {
| |
| − |
| |
| − | /*Escribe el código que consideres*/
| |
| − |
| |
| − | }
| |
| − |
| |
| − | public function __toString() {
| |
| − | $r = parent::__toString();
| |
| − | $r.= "Resultado =" . $this->opera() . "<br />";
| |
| − | return $r;
| |
| − | }
| |
| − |
| |
| − | public function describe() {
| |
| − | $r = "<table border=1><tr><th>Cocepto</th> <th>Valores</th></tr>";
| |
| − | $r .= parent::describe();
| |
| − | $r.= "<tr><th>Resultado </th><th>" . $this->opera() . "</th></tr>";
| |
| − | $r.= "</table>";
| |
| − | return $r;
| |
| − | }
| |
| − |
| |
| − | //put your code here
| |
| − | }
| |
| − |
| |
| − | </source>
| |
| − | }}
| |
| − |
| |
| − | ;OpRacional
| |
| − | {{Plegable|hide|Clase OpRacional|
| |
| − | <source lang=php>
| |
| − | <?php
| |
| − |
| |
| − | /**
| |
| − | * Description of OperacionRacional
| |
| − | *
| |
| − | * @author manuel
| |
| − | */
| |
| − | class OperacionRacional extends Operacion {
| |
| − |
| |
| − | public function __construct($operacion) {
| |
| − | parent::__construct($operacion);
| |
| − | $this->op1 = new Racional($this->op1);
| |
| − | $this->op2 = new Racional($this->op2);
| |
| − | }
| |
| − |
| |
| − | public function opera() {
| |
| − | /*Escribe el código que consideres*/
| |
| − | }
| |
| − |
| |
| − | public function __toString() {
| |
| − | $r = parent::__toString();
| |
| − | $r.= "=" . $this->opera();
| |
| − | return $r;
| |
| − | }
| |
| − |
| |
| − | public function describe() {
| |
| − | $r = "<table border=1><tr><th>Cocepto</th> <th>Valores</th></tr>";
| |
| − | $r .= parent::describe();
| |
| − | $r.= "<tr><th>Resultado </th><th>" . $this->opera() . "</th></tr>";
| |
| − | $r.= "</table>";
| |
| − | return $r;
| |
| − | }
| |
| − |
| |
| − | }
| |
| − |
| |
| − |
| |
| − | </source>
| |
| − | }}
| |
| − |
| |
| | *A continuación el código del index.php que he usado yo | | *A continuación el código del index.php que he usado yo |
| − | {{Plegable|hide|Código de index.php|
| |
| − | <source lang=php>
| |
| − | <!DOCTYPE html>
| |
| − | <html>
| |
| − | <head>
| |
| − | <meta charset="UTF-8">
| |
| − | <title></title>
| |
| − | <link rel="stylesheet" type="text/css" href="estilo.css" media="screen" />
| |
| − | </head>
| |
| − | <body>
| |
| − | <fieldset id="ayuda">
| |
| − | <legend>Reglas de uso de la calculadora</legend>
| |
| − | <div id=texhelp> La calculadora se usa escribiendo la operación.</div>
| |
| − | <div id=texhelp> La operación será <strong>Operando_1 operación Operando_2</strong>.</div>
| |
| − | <div id=texhelp> Cada operando puede ser número <strong>real o racional.</strong></div>
| |
| − | <div id=texhelp> Real p.e. <strong>5</strong> o <strong>5.12 </strong> Racional p.e <strong> 6/3 </strong>o<strong> 7/1</strong></div>
| |
| − | <div id=texhelp> Los operadores reales permitidos son <strong><font size='5' color='red'> + - * /</font></strong></div>
| |
| − | <div id=texhelp> Los operadores racionales permitidos son <strong><font size='5' color='red'> + - * :</font> </strong></div>
| |
| − | <div id=texhelp> No se deben de dejar espacios en blanco entre operandos y operación</div>
| |
| − | <div id=texhelp> Si un operando es real y el otro racional se considerará operación racional</label></div>
| |
| − | <div id=texhelp> Ejemplo (Real)<strong>5.1+4</strong> (Racional)<strong>5/1:2</strong> (Error)<strong>5.2+5/1</strong> (Error)<strong>52214+</strong> </label></div>
| |
| − |
| |
| − |
| |
| − | </fieldset>
| |
| − | <?php
| |
| − | spl_autoload_register(function($clase) {
| |
| − | require"$clase.php";
| |
| − | });
| |
| − | if ($_POST['enviar']) {
| |
| − | //Leemos la operacion
| |
| − | $operacionCadena = $_POST['operacion'];
| |
| − | switch (Operacion::tipoOperacion($operacionCadena)) {
| |
| − | case Operacion::RACIONAL:
| |
| − | $operacionNum = new OperacionRacional($operacionCadena);
| |
| − | $descripcion = $operacionNum->describe();
| |
| − | break;
| |
| − | case Operacion::REAL:
| |
| − | $operacionNum = new OperacionReal($operacionCadena);
| |
| − | $descripcion = $operacionNum->describe();
| |
| − | break;
| |
| − | case Operacion::ERROR:
| |
| − | $descripcion = " La operación <br /><strong>$operacionCadena</strong><br /> No es una operación válida";
| |
| − | break;
| |
| − | }
| |
| − | echo "<fieldset id=rtdo><legend>Resultado</legend>";
| |
| − | echo ("<label>$descripcion</label>");
| |
| − | echo "</fieldset>";
| |
| − | }
| |
| − | ?>
| |
| − | <fieldset>
| |
| − | <legend>Establece la operación</legend>
| |
| − | <form action="." method="post">
| |
| − | <label for="operacion">Operacion</label>
| |
| − | <input type="text" name="operacion" id="">
| |
| − | <input type="submit" name="enviar" value="Calcular">
| |
| − | <?php
| |
| − | if (isset($_POST['enviar'])) {
| |
| − | echo "<label>$operacionNum</label>";
| |
| − | }
| |
| − | ?>
| |
| − |
| |
| − | </form>
| |
| − | </fieldset>
| |
| − | </body>
| |
| − | </html>
| |
| − |
| |
| − | </source>
| |
| | | | |
| | + | *Para hacer este proyecto facilito un esqueleto con partes ya implementadas para facilitar su desarrollo y comprensión |
| | + | {{MRM_Objetivo| |
| | + | *El objetivo de esta práctica es familiarizarse con la programación orientada a objetos en php |
| | + | *A partir de ahora '''''todos''''' los desarrollos deberán de ser orientados a objetos |
| | + | *Cualquier duda planteadla en el foro |
| | }} | | }} |
| | | | |
| − | ====Código====
| |
| − | {{Plegable|hide|Clase Abstracta Operacion|
| |
| − | <source lang=php>
| |
| − |
| |
| − | abstract class Operacion {
| |
| − |
| |
| − | //put your code here
| |
| − | protected $op1;
| |
| − | protected $op2;
| |
| − | protected $operador;
| |
| − | protected $operacion;
| |
| − | static protected $tipo;
| |
| − |
| |
| − | const RACIONAL = 1;
| |
| − | const REAL = 2;
| |
| − | const ERROR = -1;
| |
| − |
| |
| − | /**
| |
| − | *
| |
| − | * @param string $operacion es una cadena con la operacion
| |
| − | * @return int indica el tipo de operaciion (ver constantes anteriores)
| |
| − | */
| |
| − | public static function tipoOperacion($operacion) {
| |
| − | //Implementa
| |
| − |
| |
| − |
| |
| − | }
| |
| − |
| |
| − |
| |
| − | /**
| |
| − | *
| |
| − | * @param string $operacion La operación a realizar leída de una caja de texto
| |
| − | * inicializa los atributos
| |
| − | */
| |
| − | public function __construct($operacion) {
| |
| − |
| |
| − | }
| |
| − |
| |
| − | private function obtenerOperador1($operacion) {
| |
| − |
| |
| − | }
| |
| − |
| |
| − | private function obtenerOperador2($operacion) {
| |
| − |
| |
| − | }
| |
| − |
| |
| − |
| |
| − | /** Cuidado con el carácter /, puede ser parte del operadorando en el caso racional
| |
| − | en el caso real es un posible opearador
| |
| − | */
| |
| − | private function obtenerOperador($operacion) {
| |
| − |
| |
| − | }
| |
| − |
| |
| − | public function getOp1() {
| |
| − | return $this->op1;
| |
| − | }
| |
| − |
| |
| − | public function getOp2() {
| |
| − | return $this->op2;
| |
| − | }
| |
| − |
| |
| − | public function getOperador() {
| |
| − | return $this->operador;
| |
| − | }
| |
| − |
| |
| − | public function getTipo() {
| |
| − | return $this->tipo;
| |
| − | }
| |
| − |
| |
| − | public function __toString() {
| |
| − | return "<br />$this->op1$this->operador$this->op2 = ";
| |
| − | }
| |
| − |
| |
| − | public function describe() {
| |
| − | $operacion = "<tr><th>Operando 1 </th> <th> $this->op1</th></tr>";
| |
| − | $operacion.="<tr><th>Operando 2 </th> <th> $this->op2</th></tr>";
| |
| − | $operacion.="<tr><th>Operación </th> <th> $this->operador</th></tr>";
| |
| − | if (self::$tipo == Operacion::RACIONAL)
| |
| − | $tipo = "Racional";
| |
| − | else
| |
| − | $tipo = "Real";
| |
| − | $operacion.="<tr><th>Tipo de operacion </th> <th> $tipo</th></tr>";
| |
| − | return $operacion;
| |
| − | }
| |
| − |
| |
| − |
| |
| − | //Este método convierte a la clase en abstracta
| |
| − | //Se DEBE implementar en las clases que hereden de ella
| |
| − | abstract public function opera();
| |
| − | }
| |
| − |
| |
| − | </source>
| |
| − |
| |
| − | }}
| |
| − | {{Plegable|hide|Clase OperacionRacional|
| |
| − | <source lang=php>
| |
| − | <?php
| |
| − |
| |
| − | /**
| |
| − | * Description of OperacionRacional
| |
| − | *
| |
| − | * @author manuel
| |
| − | */
| |
| − | class OperacionRacional extends Operacion {
| |
| − |
| |
| − | /**
| |
| − | inicializa los operandos, ahora ya sabemos que es un Racional ....
| |
| − | */
| |
| − | public function __construct($operacion) {
| |
| − | //Implementa
| |
| − | }
| |
| − |
| |
| − | //Realiza la operacion indicada
| |
| − | public function opera() {
| |
| − | //Implementa
| |
| − | }
| |
| − |
| |
| − | public function __toString() {
| |
| − | //Implementa
| |
| − |
| |
| − | }
| |
| − |
| |
| − |
| |
| − | public function describe() {
| |
| − | $r = "<table border=1><tr><th>Cocepto</th> <th>Valores</th></tr>";
| |
| − | $r .= parent::describe();
| |
| − | $r.= "<tr><th>Resultado </th><th>" . $this->opera() . "</th></tr>";
| |
| − | $rtdo = $this->opera();
| |
| − | $r.= "<tr><th>Resultado simplificado</th><th>" . $rtdo->simplificar() . "</th></tr>";
| |
| − | $r.= "</table>";
| |
| − | return $r;
| |
| − | }
| |
| − | </source>
| |
| − | }}
| |
| − |
| |
| − |
| |
| − |
| |
| − | {{Plegable|hide|Clase OperacionReal|
| |
| − |
| |
| − | <source lang=php>
| |
| − | <?php
| |
| − |
| |
| − | /*
| |
| − | * To change this license header, choose License Headers in Project Properties.
| |
| − | * To change this template file, choose Tools | Templates
| |
| − | * and open the template in the editor.
| |
| − | */
| |
| − |
| |
| − | /**
| |
| − | * Description of OperacionReal
| |
| − | *
| |
| − | * @author manuel
| |
| − | */
| |
| − | class OperacionReal extends Operacion {
| |
| − |
| |
| − | public function __construct($operacion) {
| |
| − | parent::__construct($operacion);
| |
| − | }
| |
| − |
| |
| − | public function opera() {
| |
| − |
| |
| − | switch ($this->operador) {
| |
| − | case '+':
| |
| − | $resultado = $this->op1 + $this->op2;
| |
| − | break;
| |
| − | case '-':
| |
| − | $resultado = $this->op1 - $this->op2;
| |
| − | break;
| |
| − | case '*':
| |
| − | $resultado = $this->op1 * $this->op2;
| |
| − | break;
| |
| − | case '/':
| |
| − | $resultado = $this->op1 / $this->op2;
| |
| − | break;
| |
| − | default :
| |
| − | $resultado = FALSE;
| |
| − | }
| |
| − | return $resultado;
| |
| − | }
| |
| − |
| |
| − | public function __toString() {
| |
| − | $r = parent::__toString();
| |
| − | $r.= $this->opera() . "<br />";
| |
| − | return $r;
| |
| − | }
| |
| − |
| |
| − | public function describe() {
| |
| − | $r = "<table border=1><tr><th>Cocepto</th> <th>Valores</th></tr>";
| |
| − | $r .= parent::describe();
| |
| − | $r.= "<tr><th>Resultado </th><th>" . $this->opera() . "</th></tr>";
| |
| − | $r.= "</table>";
| |
| − | return $r;
| |
| − | }
| |
| − |
| |
| − | //put your code here
| |
| − | }
| |
| − |
| |
| − | </source>
| |
| − |
| |
| − | }}
| |
| − | -->
| |
| | </div> | | </div> |