top of page

Semana 13

# include <iostream>
# include <math.h>
# include <cstdlib>
using namespace std;
int opcion=0, i, SUMA; 
int A[10], C[20];
char B[256];
float Prom, Xm, Desvs, Z, Var;
void ASIGNAR();
void MOSTRAR();
void PROMEDIO();
void ASCII();
void LLENAR ();
void DESVIACION();
void VARIANZA();

int main(){
do{
cout << "    MENU DE FUNCIONES "<< endl;
cout << " ----------------------------"<< endl;
cout << "  [1] ASIGNAR VALORES AL VECTOR A[]"<< endl;
cout << "  [2] MOSTRAR VALORES AL VECTOR A[]"<< endl;
cout << "  [3] PROMEDIO DE LOS ELEMENTOS DEL VECTOR A[] "<< endl;
cout << "  [4] IMPRIMIR T GUARDAR LOS CODIGOS ASCCI B[] "<< endl;
cout << "  [5] LLENAR DE ELEMENTOS CON RAND() C[] "<< endl;
cout << "  [6] VARIANZA EN C[] "<< endl;
cout << "  [7] DESVIACION ESTANDAR EN C[] "<< endl;
cout << "\n  INGRESE UNA OPCION <> 0 : "; cin>>opcion;
cout << " ----------------------------"<< endl;
switch (opcion){
   case 1:{
       cout << "  [1] ASIGNAR VALORES AL VECTOR A[]"<< endl;
       cout << " ----------------------------"<< endl;
       ASIGNAR();
       cout << " ----------------------------"<< endl;
       break;
   }
   case 2:{
       cout << "  [2] MOSTRAR VALORES AL VECTOR A[]"<< endl;
       cout << " ----------------------------"<< endl;
       MOSTRAR();
       cout << "\n ----------------------------"<< endl;
       break;
   }
   case 3:{
       cout << "  [3] PROMEDIO DE LOS ELEMENTOS DEL VECTOR A[] "<< endl;
       cout << " ----------------------------"<< endl;
       PROMEDIO();
          cout << " ----------------------------"<< endl;
       break;
   }
   case 4:{
       cout << "  [4] IMPRIMIR T GUARDAR LOS CODIGOS ASCCI B[] "<< endl;
       cout << " ----------------------------"<< endl;
       ASCII();
       cout << " ----------------------------"<< endl;
       break;
   }
   case 5:{
       cout << "  [5] LLENAR DE ELEMENTOS CON RAND() C[] "<< endl;
       cout << " ----------------------------"<< endl;
       LLENAR ();
       cout << " ----------------------------"<< endl;
       break;
   }
   case 6:{
       cout << "  [6] VARIANZA EN C[] "<< endl;
       cout << " ----------------------------"<< endl;
       VARIANZA();
       cout << " ----------------------------"<< endl;
       break;
   }
   case 7:{
       cout << "  [7] DESVIACION ESTANDAR EN C[] "<< endl;
       cout << " ----------------------------"<< endl;
       DESVIACION();
       cout << " ----------------------------"<< endl;
       break;
   }
       
}    
} while (opcion!=0);
   cout<<rand();    
}
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<<"] = ";
       cout<<A[i]<<endl;    
   }
}
void PROMEDIO()
{
   SUMA=0;
   for(i=1; i<=10; i++)
   {
       SUMA = SUMA + A[i];
       Prom = SUMA/i;
       cout<<"La suma de los "<<i<<" elementos es A["<<i<<"] = ";
       cout<<SUMA<<" y el promedio es prom = "<<Prom<<endl;
   }
}
void ASCII()
{
   for(i=1; i<=256; i++)
   {
       cout<<" B["<<i<<"] = ";
       cout<<char(i)<<endl;
       B[i]=char(i);
   }
   cout<<endl<<B[161]<<endl;
}
void LLENAR ()
{
   for(i=1; i<=10; i++)
   {
       C[i] = rand()%51;    
   }
   for(i=1; i<=10; i++)
   {
       cout<<" C["<<i<<"] = "<<C[i]<<endl;
   }
}
void VARIANZA()
{
   for(i=1; i<=10; i++)
   {
       SUMA = SUMA + C[i];
   }
   Xm = SUMA/(i);
   for(i=1; i<=10; i++)
   {
       Z = C[i] - Xm;
       SUMA = SUMA + pow(Z,2);
       Var= sqrt(SUMA/(10-1));
   }
   cout<<"La media es: Xm = "<<Xm<<endl;
   cout<<"La varianza es Var = "<<Var<<endl;
}
void DESVIACION()
{
   for(i=1; i<=10; i++)
   {
       SUMA = SUMA + C[i];
   }
   Xm = SUMA/(i);
   for(i=1; i<=10; i++)
   {
       Z = C[i] - Xm;
       SUMA = SUMA + pow(Z,2);
       Desvs= sqrt(SUMA/(10-1));
   }
   cout<<"La media es: Xm = "<<Xm<<endl;
   cout<<"La desviacion estandar poblacional es Desvs = "<<Desvs<<endl;
}

bottom of page