jueves, 20 de marzo de 2025

01.- Programación II - Parcial Nro. 1 - Actividad 20 de Marzo de 2025 - Solución del Profesor

  





Programa Nro. 1 (Pitágoras) en C++

/* programa para determinar la longitud máxima de la cabilla para poder pasar
entre dos pasillos de diferente ancho en "L" - Modelo 2 Parcial Nro. 1 
Semestre 2023-II - Basado en Teorema de Pitágoras.

Elaborado por el profesor Carlos Ferrer - Oct 2024
Rev. 0
*/

// Bibliotecas requeridas


#include<iostream>
#include<math.h>
#include<locale.h>

using namespace std;

main()


{

 double a,b; // Lados desconocidos de los dos triángulos de la solución
 double Q; // Angulo de los triángulos
 double L; //Longitud de la cabilla
 double L1,L2; //Segmentos de la cabilla
 double P1=0,P2=0; //Ancho de los pasillos 1 y 2 
  
setlocale(LC_ALL,"spanish"); 


while (P1<6 or P1>12)
     {
     cout<<"Ingrese ancho del pasillo Nro. 1 (mts) = ";
     cin>>P1;
     }

while (P2<6 or P2>12)
     {
     cout<<"Ingrese ancho del pasillo Nro. 2 (mts) = ";
     cin>>P2;
     }


 // Determinamos la distancia a del triangulo

a= cbrt (P1*pow(P2,2));

 // Determinamos L2

L2=sqrt(pow(P2,2)+pow(a,2));

//Determinamos L1

L1=P1*L2/a;

// Determinamos theta

Q=asin(a/L2);


// PRESENTAMOS LOS RESULTADOS

 cout<<endl<<"La longitud máxima de la cabilla en (mts) = "<<L1+L2<<endl;
 cout<<endl<<"El angulo Theta en radianes = "<<Q<<endl;
 cout<<"El angulo Theta en grados (Degree) = "<<Q*180/M_PI<<endl<<endl;

 cout<<"CON ESTAS CANTIDADES SE OBTIENE LA CABILLA DE MAXIMA LONGITUD QUE PUEDE"<<endl; 
 cout<<"PASAR POR LOS PASILLOS SIN AFECTAR LAS PAREDES!!!"<<endl<<endl;

 system("pause");

}


Programa Nro. 1 (Pitágoras) en Python

# programa para determinar la longitud máxima de la cabilla para poder pasar
# entre dos pasillos de diferente ancho en "L" - Modelo 2 Parcial Nro. 1
# Semestre 2023-II - Basado en Teorema de Pitágoras.

#Elaborado por el profesor Carlos Ferrer - Oct 2024
#Rev. 0

# Bibliotecas requeridas

import math

# Lados desconocidos de los dos triángulos de la solución
a, b = 0, 0
# Angulo de los triángulos
Q = 0
# Longitud de la cabilla
L = 0
# Segmentos de la cabilla
L1, L2 = 0, 0
# Ancho de los pasillos 1 y 2
P1, P2 = 0, 0

while P1 < 6 or P1 > 12:
    P1 = float(input("Ingrese ancho del pasillo Nro. 1 (mts) = "))

while P2 < 6 or P2 > 12:
    P2 = float(input("Ingrese ancho del pasillo Nro. 2 (mts) = "))

# Determinamos la distancia a del triangulo
a = (P1 * P2 ** 2) ** (1/3)
# Determinamos L2
L2 = math.sqrt(P2 ** 2 + a ** 2)
# Determinamos L1
L1 = P1 * L2 / a
# Determinamos Theta
Q = math.asin(a / L2)

# PRESENTAMOS LOS RESULTADOS
print(f"\nLa longitud máxima de la cabilla en (mts) = {L1 + L2}")
print(f"\nEl angulo Theta en radianes = {Q}")
print(f"El angulo Theta en grados (Degree) = {Q * 180 / math.pi}\n\n")

print("CON ESTAS CANTIDADES SE OBTIENE LA CABILLA DE MAXIMA LONGITUD QUE PUEDE")
print("PASAR POR LOS PASILLOS SIN AFECTAR LAS PAREDES!!!\n\n")

input("Presione enter para continuar...")



Programa Nro. 2 (Trigonometría)

/* programa para determinar la longitud máxima de la cabilla para poder pasar
entre dos pasillos de diferente ancho en "L" - Modelo 2 Parcial Nro. 1 
Semestre 2023-II - Basado en Teorema de trigonometría.

Elaborado por el profesor Carlos Ferrer - Oct 2024
Rev. 0
*/

// Bibliotecas requeridas

#include<iostream>
#include<math.h>
#include<locale.h>
using namespace std;

main()


{

 double Q; // Angulo de los triángulos
 double L; //Longitud de la cabilla
 double P1=0,P2=0; //Ancho de los pasillos 1 y 2 
  
 setlocale(LC_ALL,"spanish"); 


while (P1<=6 or P1>12)
  {
  cout<<"Ingrese ancho del pasillo Nro. 1 (mts) = ";
  cin>>P1;
  }

while (P2<=6 or P2>12)
  {
  cout<<"Ingrese ancho del pasillo Nro. 2 (mts) = ";
  cin>>P2;
  }

// Determinamos theta

Q=atan(cbrt(P1/P2));


 // Determinamos L

L=P1/sin(Q)+P2/cos(Q);


// PRESENTAMOS LOS RESULTADOS

 cout<<endl<<"La longitud máxima de la cabilla en (mts) = "<<L<<endl;
 cout<<endl<<"El angulo Theta en radianes = "<<Q<<endl;
 cout<<"El angulo Theta en grados (Degree) = "<<Q*180/M_PI<<endl<<endl;

 cout<<"CON ESTAS CANTIDADES SE OBTIENE LA CABILLA DE MAXIMA LONGITUD QUE PUEDE"<<endl; 
 cout<<"PASAR POR LOS PASILLOS SIN AFECTAR LAS PAREDES!!!"<<endl<<endl;

 system("pause");

}

Programa Nro. 2 (Trigonometría) en Python

# Programa para determinar la longitud máxima de la cabilla para poder pasar
# entre dos pasillos de diferente ancho en "L" - Modelo 2 Parcial Nro. 1
# Semestre 2023-II - Basado en Teorema de trigonometría.

# Elaborado por el profesor Carlos Ferrer - Oct 2024
# Rev. 0


# Bibliotecas requeridas

import math

# Angulo de los triángulos
Q = 0
#Longitud de la cabilla
L = 0
#Ancho de los pasillos 1 y 2
P1 = 0
P2 = 0

while P1 <= 6 or P1 > 12:
    P1 = float(input("Ingrese ancho del pasillo Nro. 1 (mts) = "))

while P2 <= 6 or P2 > 12:
    P2 = float(input("Ingrese ancho del pasillo Nro. 2 (mts) = "))

# Determinamos theta
Q = math.atan(P1**(1/3) / P2**(1/3))
# Determinamos L
L = P1/math.sin(Q) + P2/math.cos(Q)


# Presentamos resultados
print(f"\nLa longitud máxima de la cabilla en (mts) = {L}")
print(f"\nEl angulo Theta en radianes = {Q}")
print(f"El angulo Theta en grados (Degree) = {Q*180/math.pi}\n\n")

print("CON ESTAS CANTIDADES SE OBTIENE LA CABILLA DE MAXIMA LONGITUD QUE PUEDE")
print("PASAR POR LOS PASILLOS SIN AFECTAR LAS PAREDES!!!\n\n")

input("Presione Enter para continuar..")


Programa Nro. 3 (Iteración del ángulo θ)

/* programa para determinar la longitud máxima de la cabilla para poder pasar
entre dos pasillos de diferente ancho en "L" - Modelo 2 Parcial Nro. 1 
Semestre 2023-II - Basado en Iteración del angulo

Elaborado por el profesor Carlos Ferrer - Oct 2024
Rev. 0
*/

// Bibliotecas requeridas

#include<iostream>
#include<math.h>
#include<locale.h>
using namespace std;

main()


{

 double Q; // Angulo de los triángulos
 double L,L_Anterior; //Longitud de la cabilla y Longitud de la iteración anterior
 double P1=0; //ancho pasillo 1
 double P2=0; //ancho pasillo 2
   
 setlocale(LC_ALL,"spanish"); 


while (P1<=6 or P1>12)
  {
  cout<<"Ingrese ancho del pasillo Nro. 1 (mts) = ";
  cin>>P1;
  }

while (P2<=6 or P2>12)
  {
  cout<<"Ingrese ancho del pasillo Nro. 2 (mts) = ";
  cin>>P2;
  }

// Determinamos theta y L

Q=0.000001;
L_Anterior=P1/sin(Q)+P2/cos(Q);
while(Q<90)
{
Q=Q+0.000001;
L=P1/sin(Q)+P2/cos(Q);
if (L_Anterior<L)
{
L=L_Anterior;
break;
}
else
{
L_Anterior=L;
}
}

// PRESENTAMOS LOS RESULTADOS

 cout<<endl<<"La longitud máxima de la cabilla en (mts) = "<<L<<endl;
 cout<<endl<<"El angulo Theta en radianes = "<<Q<<endl;
 cout<<"El angulo Theta en grados (Degree) = "<<Q*180/M_PI<<endl<<endl;

 cout<<"CON ESTAS CANTIDADES SE OBTIENE LA CABILLA DE MAXIMA LONGITUD QUE PUEDE"<<endl; 
 cout<<"PASAR POR LOS PASILLOS SIN AFECTAR LAS PAREDES!!!"<<endl<<endl;

 system("pause");

}




Programa Nro. 3 (Iteración del ángulo θ) en Python

# programa para determinar la longitud máxima de la cabilla para poder pasar
# entre dos pasillos de diferente ancho en "L" - Modelo 2 Parcial Nro. 1
# Semestre 2023-II - Basado en Iteración del angulo
# Elaborado por el profesor Carlos Ferrer - Oct 2024
# Rev. 0

# Biblioteca requerida
import math

# Angulo de los triángulos
Q = 0.000001
# Longitud de la cabilla y Longitud de la iteración anterior
L_Anterior = 0
# ancho pasillo 1
P1 = 0
# ancho pasillo 2
P2 = 0

while P1 <= 6 or P1 > 12:
    P1 = float(input("Ingrese ancho del pasillo Nro. 1 (mts) = "))

while P2 <= 6 or P2 > 12:
    P2 = float(input("Ingrese ancho del pasillo Nro. 2 (mts) = "))

# Determinamos L para Q=0.000001
L_Anterior = P1 / math.sin(Q) + P2 / math.cos(Q)

# Determinamos theta y L  definitivas iterando
while Q < 90:
    Q =Q+0.000001
    L = P1 / math.sin(Q) + P2 / math.cos(Q)
    if L_Anterior < L:
        L = L_Anterior
        break
    else:
        L_Anterior = L

# PRESENTAMOS LOS RESULTADOS

print(f"\nLa longitud máxima de la cabilla en (mts) = {L}")
print(f"\nEl angulo Theta en radianes = {Q}")
print(f"El angulo Theta en grados (Degree) = {Q * 180 / math.pi}\n\n")

print("CON ESTAS CANTIDADES SE OBTIENE LA CABILLA DE MAXIMA LONGITUD QUE PUEDE")
print("PASAR POR LOS PASILLOS SIN AFECTAR LAS PAREDES!!!\n\n")

input("Presione Enter para continuar...")



EXITOS!!

No hay comentarios.:

Publicar un comentario