CB100

Notas, resueltos y tps de la materia Algoritmos y Estructuras de Datos
Index Commits Files Refs README
commit 460d8a0670ea536fac934023aa60deb48fa38fa0
parent c0b3fe19466aaa3dc405a3f49f8ae7d562c18692
Author: mjkloeckner <martinjkloeckner@gmail.com>
Date:   Thu, 14 Mar 2024 19:16:28 -0300

Bulk add solution for ej 5 to 10

Diffstat:
Asolutions/ej05.cpp | 22++++++++++++++++++++++
Asolutions/ej06.cpp | 15+++++++++++++++
Asolutions/ej07.cpp | 17+++++++++++++++++
Asolutions/ej08.cpp | 13+++++++++++++
Asolutions/ej09.cpp | 18++++++++++++++++++
Asolutions/ej10.cpp | 37+++++++++++++++++++++++++++++++++++++
6 files changed, 122 insertions(+), 0 deletions(-)
diff --git a/solutions/ej05.cpp b/solutions/ej05.cpp
@@ -0,0 +1,22 @@
+#include <iostream>
+#include <cmath>
+
+int main (void) {
+    double b, h, hipotenusa;
+
+    std::cout << "* Calculadora de Triangulos *" << std::endl;
+    std::cout << "Ingrese base del triangulo> " << std::flush;
+
+    std::cin >> b;
+    std::cout << "\033[1A\033[0KIngrese altura del triangulo> ";
+    std::cin >> h;
+
+    hipotenusa = std::sqrt(std::pow(b,2)+std::pow(h,2));
+
+    std::cout << "\033[1A\033[0K    b = " << b << std::endl
+        << "    h = " << h << std::endl
+        << "perim = " << b+h+hipotenusa << std::endl
+        << "    s = " << (b*h)/2 << std::endl;
+
+    return 0;
+}
diff --git a/solutions/ej06.cpp b/solutions/ej06.cpp
@@ -0,0 +1,15 @@
+#include <iostream>
+
+int main (void) {
+    long input;
+
+    std::cout << "Ingrese un número> " << std::flush;
+    std::cin >> input;
+
+    std::cout << "\033[1A\033[0KUsted ingreso `" << input << "`" << std::endl
+        << "El numero ingresado es "
+        << ((input == 0) ? "IGUAL" : ((input > 0) ? "MAYOR" : "MENOR"))
+        << " a CERO" << std::endl;
+
+    return 0;
+}
diff --git a/solutions/ej07.cpp b/solutions/ej07.cpp
@@ -0,0 +1,17 @@
+#include <iostream>
+
+int main (void) {
+    long a, b;
+
+    std::cout << "Ingrese un número> " << std::flush;
+    std::cin >> a;
+    std::cout << "\033[1A\033[0KIngrese otro número> " << std::flush;
+    std::cin >> b;
+
+    std::cout << "\033[1A\033[0KUsted ingreso `" << a << "` y `" 
+        << b << "`" << std::endl;
+
+    std::cout << a << (a > b ? " > " : " < ") << b << std::endl;
+
+    return 0;
+}
diff --git a/solutions/ej08.cpp b/solutions/ej08.cpp
@@ -0,0 +1,13 @@
+#include <iostream>
+
+int main (void) {
+    long input;
+
+    std::cout << "Ingrese un número> " << std::flush;
+    std::cin >> input;
+    std::cout << "\033[1A\033[0KUsted ingreso `" << input << "`" << std::endl
+        << "El cual es un numero " << ((input % 2) ? "IMPAR" : "PAR")
+        << std::endl;
+
+    return 0;
+}
diff --git a/solutions/ej09.cpp b/solutions/ej09.cpp
@@ -0,0 +1,18 @@
+#include <iostream>
+
+int main (void) {
+    long a, b;
+
+    std::cout << "Ingrese un número> " << std::flush;
+    std::cin >> a;
+    std::cout << "\033[1A\033[0KIngrese otro número> " << std::flush;
+    std::cin >> b;
+
+    std::cout << "\033[1A\033[0KUsted ingreso `" << a << "` y `" 
+        << b << "`" << std::endl;
+
+    std::cout << a << (a % b ? " NO es DIVISIBLE por " : " es DIVISIBLE por ")
+        << b << std::endl;
+
+    return 0;
+}
diff --git a/solutions/ej10.cpp b/solutions/ej10.cpp
@@ -0,0 +1,37 @@
+#include <iostream>
+
+int main (void) {
+    char op;
+    double a, b, res;
+
+    std::cout << "Ingrese un número> " << std::flush;
+    std::cin >> a;
+    std::cout << "\033[1A\033[0KIngrese otro número> " << std::flush;
+    std::cin >> b;
+    std::cout << "\033[1A\033[0KIngrese operación a realizar [+, -, *, /]> "
+        << std::flush;
+    std::cin >> op;
+
+    switch(op) {
+        case '+':
+            res = a + b;
+            break;
+        case '-':
+            res = a - b;
+            break;
+        case '*':
+            res = a * b;
+            break;
+        case '/':
+            res = a / b;
+            break;
+        default:
+            std::cout << "Operación inválida\n";
+            return -1;
+    }
+
+    std::cout << "\033[1A\033[0K`" << a << "` " << op << " `" 
+        << b << "` = " << res << std::endl;
+
+    return 0;
+}