top of page

SEMANA 13. VECTORES

#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int opcion, i, SUMA;
void ASIGNAR(), MOSTRAR(), SUMAR(), CODIGOS(), calcularFrecuenciaResonancia(), calcularAmplitud(), calcularElongacion();
int A[10];
char B[256];
int tiempo, tiempos;

int main()
{
   do
   {
       cout<< " MENU DE VECTORES  \n ";
           cout<< " ------------------ \n ";
           cout<< " 1.- ASIGNAR DATOS A UN VECTOR   \n ";
          cout<< " 2.- MOSTRAS DATOS DE UN VECTOR  \n ";
          cout<< " 3.- SUMA DE LOS ELEMENTOS \n ";
           cout<< " 4.- LISTADO DE CODIGOS ASCII \n ";
           cout<< " 5.- PROBLEMA CASO A calcular Frecuencia de Resonancia \n ";
           cout<< " 6.- PROBLEMA CASO B calcular Amplitud \n ";
           cout<< " 7.- PROBLEMA CASO C calcular Elongacion \n ";
   
           cout<< "INGRESE UNA OPCION <> 0: "; cin>>opcion;
   //switch (opcion)    
   switch(opcion)
   {
        case 1:
            {
                cout << "Asignar datos a un vector \n";
                cout << "------------------------- \n";
                ASIGNAR();
                cout<<endl;
       }; break;
       
   case 2:
            {
             cout << "2.- Mostrar datos de un vector \n";
             cout << "-------------------- \n";
       MOSTRAR();
            cout<<endl;
       }; break;
   
   case 3:
            {
            cout<<endl;
            cout << "3. Suma de los elementos \n";
            cout << "------------------------- \n";
            SUMAR();
            cout << endl;
       }; break;
   case 4:
            {
           cout<<endl;
            cout<< " 4.- LISTADO DE CODIGOS ASCII \n ";
            CODIGOS();
       }; break;
       
   case 5:
       {
       cout<<endl;
            cout<< " 5.- PROBLEMA CASO A calcular Frecuencia de Resonancia \n ";
            calcularFrecuenciaResonancia();    
       }; break;
       
   case 6:
       {
       cout<<endl;
            cout<< " 6.- PROBLEMA CASO B calcular Amplitud \n";
            calcularAmplitud();
       }; break;
       
   case 7:
       {
       cout<<endl;
            cout<< " 7.- PROBLEMA CASO C calcular Elongacion \n";
            calcularElongacion();
       }; break;
   }// fin sitch
   }while (opcion!=0); //Fin de do while
}// fin del ptrograma


void ASIGNAR()
{
   for(i=1;i<=10;i++)
   {
       cout << "A["<<i<<"] = " ;cin >> A[i];
   }
}

void MOSTRAR()
{
   for(i=1;i<=10;i++)
   {
       cout << "A["<<i<<"] = "<<A[i]<<endl;
   }
}

void SUMAR()
{
   for(i=1;i<=10;i++)
   {
       SUMA = SUMA + A[i];
   }
   cout << "La suma de los elementos del vector A[]= "<<SUMA<<endl;
}

void CODIGOS()
{
   for(i=1;i<=256;i++)
   {
       B[i] = char(i);
       cout << "B["<<i<<"] = "<<B[i]<<endl;
   }
   cout<<endl;
   cout<<char(161);
   
   cout<<"Listado de abecedario \n";
   for(i=65;i<=90;i++)
   {
       cout<<"B["<<i<<"] = "<<B[i]<<endl;
   }
}

void calcularFrecuenciaResonancia()
{
    double k, m;
    cout << "Ingresa la constante de resorte (k): ";
    cin >> k;
    cout << "Ingresa la masa (m): ";
    cin >> m;

    double frecuencia = sqrt(k / m);
    cout << "La frecuencia de resonancia simple es: " << frecuencia << " Hz" << endl;
}
   
   
void calcularAmplitud()
{
   double energiaTotal, k;
    cout << "Ingresa la energía total del sistema (Joules): ";
    cin >> energiaTotal;
    cout << "Ingresa la constante de resorte (k): ";
    cin >> k;

    double amplitud = sqrt(2 * energiaTotal / k);
    cout << "La amplitud del MAS es: " << amplitud << " metros" << endl;

}

void calcularElongacion() 
{
    double amplitud, fase;
    cout << "Ingresa la amplitud del MAS (metros): ";
    cin >> amplitud;
    cout << "Ingresa la fase inicial (en radianes): ";
    cin >> fase;

    int numTiempos;
    cout << "¿Cuántos tiempos deseas calcular? ";
    cin >> numTiempos;

    vector<double> tiempos(numTiempos); // Vector para almacenar los tiempos

    for (int i = 0; i < numTiempos; ++i) {
        cout << "Ingresa el tiempo " << i + 1 << " (segundos): ";
        cin >> tiempos[i];
    }

    cout << "Resultados de elongación:" << endl;
     for (int i = 0; i <= 10; i++)
   {
       double tiempo = tiempos[i];
        double elongacion = amplitud * cos(2 * M_PI * tiempo + fase);
        cout << "En el tiempo t = " << tiempo << " segundos: " << elongacion << " metros" << endl;
    }
}

 

LENGUAJE DE PROGRAMACIÃ’N

©2023 por LENGUAJE DE PROGRAMACIÒN. Creado con Wix.com

bottom of page