CB100

Notas, resueltos y tps de la materia Algoritmos y Estructuras de Datos
Index Commits Files Refs README
commit 0b13700371068845480f30bc5381360c631d2aaa
parent 18d8493e6c87c41733d3543c3d8438bd69597180
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Mon, 20 May 2024 15:45:54 -0300

add `guias/4/ej16.cpp`

Diffstat:
Aguias/4/ej16.cpp | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 95 insertions(+), 0 deletions(-)
diff --git a/guias/4/ej16.cpp b/guias/4/ej16.cpp
@@ -0,0 +1,95 @@
+#include <iostream>
+
+class Rectangle {
+private:
+    float base;
+    float height;
+
+public:
+    /**
+     * post: inicializa el rectangulo con sus atributos a `0.0f`
+     */
+    Rectangle() {
+        this->base = 0.0f;
+        this->height = 0.0f;
+    }
+
+    /**
+     * post: inicializa el rectangulo con `base` y `altura`
+     */
+    Rectangle(float base, float height) {
+        this->base = base;
+        this->height = height;
+    }
+
+    /**
+     * post: libera la memoria
+     */
+    virtual ~Rectangle() {}
+
+    /**
+     * pre: el rectangulo debe estar inicializado
+     * post: cambia la base del rectangulo por `base`
+     */
+    void setBase(float base) {
+        this->base = base;
+    }
+
+    /**
+     * pre: el rectangulo debe estar inicializado
+     * post: cambia la altura del rectangulo por `height`
+     */
+    void setHeight(float height) {
+        this->height = height;
+    }
+
+    /**
+     * pre: el rectangulo debe estar inicializado
+     * post: devuelve la base del rectangulo
+     */
+    float getBase() {
+        return this->base;
+    }
+
+    /**
+     * pre: el rectangulo debe estar inicializado
+     * post: devuelve la altura del rectangulo
+     */
+    float getHeight() {
+        return this->height;
+    }
+
+    /**
+     * pre: el rectangulo debe estar inicializado
+     * post: devuelve el perimetro del rectangulo
+     */
+    float getPerimeter() {
+        return 2*(this->base + this->height);
+    }
+
+    /**
+     * pre: el rectangulo debe estar inicializado
+     * post: devuelve el area del rectangulo
+     */
+    float getArea() {
+        return this->base * this->height;
+    }
+
+    /**
+     * pre:  el rectangulo debe estar inicializada
+     * post: imprime la base y altura del rectangulo en formato (b,h)
+     */
+    void print() {
+        std::cout << "(" << this->base << ", " << this->height << ")\n";
+    }
+};
+
+int main (void) {
+    Rectangle r(2,2);
+    r.print();
+    std::cout << "Perimetro = " << r.getPerimeter() << std::endl;
+    std::cout << "Area = " << r.getArea() << std::endl;
+    std::cout << "Base = " << r.getBase() << std::endl;
+    std::cout << "Altura = " << r.getHeight() << std::endl;
+    return 0;
+}