Professional Documents
Culture Documents
1)
#include "vector.h"
2)
#include "vector.h"
using namespace std;
void productoescalar(float [],int,float [],float []);
int main()
{
int n,res;
float v1[LIM],v2[LIM],v3[LIM];
do
{
n=numdatos("la cantidad de datos para los vectores es: ");
cout <<"los datos para el vector A son: "<<endl;
ingresovector(v1,n);
cout <<"los datos para el vector B son: "<<endl;
ingresovector(v2,n);
productoescalar(v1,n,v2,v3);
reportevector(v3,n);
}while(bucle(res));
}
3)
#include "vector.h"
4)
#include <C:\Documents and Settings\Home\Escritorio\laboratorio 5\vector.h>
using namespace std;
void suma(float [],float [], int ,float []);
int main()
{
int n, res;
float v1[LIM],v2[LIM],r[LIM];
do
{
n=numdatos("La cantidad para los vectores es: ");
cout <<"datos para el vector A: "<<endl;
ingresovector(v1,n);
cout <<"datos para el vector B: "<<endl;
ingresovector(v2,n);
suma(v1,v2,n,r);
reportevector(r,n);
}while(bucle(res));
}
void suma(float v1[],float v2[], int n,float r[])
{
int i;
for (i=0;i<n;i++)
{
r[i]=v1[i] + v2[i];
}
}
5)
#include <C:\Documents and Settings\Home\Escritorio\laboratorio 5\vector.h>
v[k]=v[i];
k++;
}
}
n=k;
}
6)
#include <C:\Documents and Settings\Home\Escritorio\laboratorio 5\vector.h>
}while(bucle(res));
}
void diferencia(float v1[],float v2[],int n1,int n2)
{
int i,k,p;
cout <<"Los numeros de A que no estan en B son: ";
for(i=0;i<n1;i++)
{
p=0;
for(k=0;k<n2;k++)
{
if(v1[i]==v2[k])p++;
}
if(p==0)cout<<v1[i]<<" ";
}
}
7)
#include <C:\Documents and Settings\Home\Escritorio\laboratorio 5\vector.h>
using namespace std;
void aprobados(float [],int,float &,float &);
void reporte(float, float);
void ingresonota(float[],int);
int main()
{
int n,res;
float v[LIM],ap,ds;
do{
8)
#include <C:\Documents and Settings\Home\Escritorio\laboratorio 5\vector.h>
int main()
{
int n,res;
float nue,v[LIM];
do{
n=numdatos("cuantos elementos tendra el vector: ");
ingresovector(v,n);
ingresonuevo(nue);
cout <<"El elemento "<<nue<<" se repite "<<conteo(v,n,nue)<<" veces."<<endl;
}while(bucle(res));
return 0;
}
void ingresonuevo(float &nue)
{
cout<<"Ingresa un nuevo elemento: ";
cin >>nue;
}
9)
#include <C:\Documents and Settings\Home\Escritorio\laboratorio 5\vector.h>
int main()
{
int n,res;
float v1[LIM],v2[LIM];
do{
n=numdatos("cuantos elementos tendra los vectores: ");
cout<<"primer vector: "<<endl;
ingresovector(v1,n);
cout <<"segundo vector: "<<endl;
ingresovector(v2,n);
comparacion(v1,v2,n);
}while(bucle(res));
return 0;
}
void comparacion(float v1[],float v2[],int n)
{
int i,k=0;
for (i=0;i<n;i++)if(v1[i]==v2[i])k++;
if(k==n)cout<< "son iguales";
else cout<<"Son diferentes";
}
10)
#include <C:\Documents and Settings\Home\Escritorio\laboratorio 5\vector.h>
using namespace std;
float mediana(float [],int );
int main()
{
int n, res;
float v[LIM];
do
{
n=numdatos("La cantidad de datos a ingresar es: ");
ingresovector(v,n);
cout <<"La mediana del conjunto de datos es: "<<mediana(v,n);
}while(bucle(res));
}
float mediana(float v[],int n)
{
float me;
if(n%2)
{
me=v[n/2];
}else
{
me=(v[n/2] + v[n/2-1])/2;
}
return me;
}
11)
#include "vector.h"
using namespace std;
float pponderado(float [],float [],int);
void ingreso_dyp(float [],float [],int );
int main()
{
int n, res;
float can[LIM],pes[LIM];
do
{
n=numdatos("La cantidad de datos a ingresar es: ");
ingreso_dyp(can,pes,n);
cout<<"El promedio ponderado es: "<<pponderado(can,pes,n)<<endl;
}while(bucle(res));
}
void ingreso_dyp(float can[],float pes[],int n)
{
int i;
for(i=0;i<n;i++)
{
do{
cout <<"cantidad "<<i+1<<" :";
cin >>can[i];
}while(can[i]<0);
do{
cout <<"peso "<<i+1<<" :";
cin>>pes[i];
}while(pes[i]<0);
cout<<endl;
}
}
12)
#include <iostream>
int main()
{
int n, res;
float nota[LIM];
char nombre[LIM][20];
do
{
n=numdatos("La cantidad de alumnos es: ");
cout <<"datos para el vector A: "<<endl;
ingresodatos(nombre,nota,n);
reportevector(r,n);
}while(bucle(res));
}
void ingresodatos(char nb[],float nt,int n)
{
for(i=0;i<n;i++)
{
cout<<"alumno "<<i+1<<" : "<<endl;
cout <<"nombre: ";
cin >>nb[i];
do
{
cout<<"nota: ";
cin >>nt[i];
}while(nt[i]<0 || nt[i]>20);
}
}
13)
#include "vector.h"
using namespace std;
void ingresodatos(string [],float [],int n);
float tallapromedio(float talla[],int n);
string jugadormasalto(string [],float [],int);
void reporte(float ,string );
int main()
{
int n, res;
float talla[LIM],p;
string nombre[LIM],nb;
do
{
n=11;
cout <<"datos para del equipo: "<<endl;
ingresodatos(nombre,talla,n);
p=tallapromedio(talla,n);
nb=jugadormasalto(nombre,talla,n);
reporte(p,nb);
}while(bucle(res));
}
void ingresodatos(string nb[],float talla[],int n)
{
int i;
for(i=0;i<n;i++)
{
cout<<"jugador "<<i+1<<" : "<<endl;
cout <<"nombre: ";
cin >>nb[i];
do
{
cout<<"talla(cm): ";
cin >>talla[i];
}while(talla[i]<0 || talla[i]>250);
}
}
float tallapromedio(float talla[],int n)
{
int i;
float s=0;
for(i=0;i<n;i++)
{
s=s+talla[i];
}
return s/n;
}
string jugadormasalto(string nombre[],float talla[],int n)
{
int i,p,k;
float ma;
ma=talla[0];
for(i=0;i<n;i++)
{
if(ma<talla[i])
{
p=i;
}
}
cout <<"entonces el juagador mas alto es: "<<nombre[p]<<endl;
return nombre[p];
}
void reporte(float p,string nb)
{
cout <<"El promedio de tallas es: "<<p<<endl;
cout<<"El jugador mas alto es: "<<nb;
}
16)
#include <C:\Documents and Settings\Home\Escritorio\laboratorio 5\vector.h>
18)
#include <C:\Documents and Settings\Home\Escritorio\laboratorio 5\vector.h>