Es que no se exactamente que es lo que piden, ya que pone que normailize un vector y que la primera componente sea 1.0, asi que si, quiza sea como dice MAFUS
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menútypedef double tArray[MAX_TAM];
typedef struct {
tArray vector;
int tamV;
} tVector;
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
/**CONSTANTES Y TYPEDEFS**/
const int MAX_M = 20;
const int MAX_V = 100;
typedef struct {
int codigo;
string nombre;
}tMueble;
typedef tMueble losMuebles[MAX_M];
typedef struct {
losMuebles muebles;
int tamLM;
}tListaM;
typedef struct {
int anyo;
int mes;
int dia;
}tFecha;
typedef struct {
int codigo;
tFecha fecha;
int unidades;
}tVenta;
typedef tVenta lasVentas[MAX_V];
typedef struct {
lasVentas ventas;
int tamLV;
}tListaV;
/**DESARROLLO DE LAS FUNCIONES**/
void inicializarListaM(tListaM& listaM) {
listaM.tamLM = 0;
}
void inicializarListaV(tListaV& listaV) {
listaV.tamLV = 0;
}
void anyadirMueble(tListaM& listaM, const tMueble& elMueble) {
listaM.muebles[listaM.tamLM] = elMueble;
listaM.tamLM++;
}
void anyadirVenta(tListaV& listaV, const tVenta& laVenta) {
listaV.ventas[listaV.tamLV] = laVenta;
listaV.tamLV++;
}
void leerFecha(ifstream& fichV, tFecha& laFecha) {
char sepa;
fichV >> laFecha.anyo;
fichV.get(sepa);
fichV >> laFecha.mes;
fichV.get(sepa);
fichV>> laFecha.dia;
}
void leerMueble(ifstream& fichM, tMueble& elMueble) {
string nombre;
char aux;
fichM >> elMueble.codigo;
fichM.get(aux);
getline(fichM, elMueble.nombre);
}
void leerVenta(ifstream& fichV, tVenta& laVenta) {
char aux;
fichV >> laVenta.codigo;
leerFecha(fichV, laVenta.fecha);
fichV >> laVenta.unidades;
}
void leerMuebles(ifstream& fichM, tListaM& listaM) {
tMueble elMueble;
leerMueble(fichM, elMueble);
while (elMueble.codigo != -1) {
anyadirMueble(listaM, elMueble);
leerMueble(fichM, elMueble);
}
fichM.close();
}
void leerVentas(ifstream& fichV, tListaV& listaV) {
tVenta laVenta;
leerVenta(fichV, laVenta);
while (laVenta.codigo != -1) {
anyadirVenta(listaV, laVenta);
leerVenta(fichV, laVenta);
}
fichV.close();
}
void mostrarMuebles(const tListaM& listaM) {
for (int i = 0; i < listaM.tamLM; i++) {
cout << listaM.muebles[i].codigo <<" "<< listaM.muebles[i].nombre << endl;
}
}
void mostrarFecha(const tListaV& listaV) {
int i;
i = 0;
cout << listaV.ventas[i].fecha.anyo << "/"<< listaV.ventas[i].fecha.mes << "/" << listaV.ventas[i].fecha.dia;
}
void mostrarVentas(const tListaV& listaV) {
for (int i = 0; i < listaV.tamLV; i++) {
mostrarFecha(listaV);
cout << setw(5) << listaV.ventas[i].codigo << setw(5) << listaV.ventas[i].unidades << endl;
}
}
void mezcla(tListaM& listaM, tListaV& listaV) {
int posM;
int posV;
posM = 0;
posV = 0;
while (posV < listaV.tamLV) {
if (listaM.muebles[posM].codigo != listaV.ventas[posV].codigo) {
cout << "ERROR" << endl;
posM++;
}
else {
cout << listaM.muebles[posM].nombre << " " << listaV.ventas[posV].unidades << " unidades" << endl;
posV++;
}
}
}
int main(int argc, char** args) {
setlocale(LC_ALL, "spanish");
ifstream fichM;
fichM.open("muebles.txt");
ifstream fichV;
fichV.open("ventas.txt");
tListaV listaV;
tListaM listaM;
inicializarListaM(listaM);
leerMuebles(fichM, listaM);
inicializarListaV(listaV);
leerVentas(fichV, listaV);
mostrarMuebles(listaM);
mostrarVentas(listaV);
mezcla(listaM, listaV);
system("pause");
return 0;
}
const int MAX_M = 20;
const int MAX_V = 100;
typedef struct {
int codigo;
string nombre;
}tMueble;
typedef tMueble losMuebles[MAX_M];
typedef struct {
losMuebles muebles;
int tamLM;
}tListaM;
typedef struct {
int anyo;
int mes;
int dia;
}tFecha;
typedef struct {
int codigo;
tFecha fecha;
int unidades;
}tVenta;
typedef tVenta lasVentas[MAX_V];
typedef struct {
lasVentas ventas;
int tamLV;
}tListaV;
#define N 4
int A[N]={7,3,25,4};
int B[N];
void Recorre();
int Mayor();
void main(){
Recorre (A, B, N);
}
void Recorre (int A[], int B[], int M){
for(int j=0; j<M-1; j++){
B[j] = Mayor(A[j],A[j+1]);
}
}
int Mayor(int X, int Y){
if(X>Y)
return X;
else
return Y;
}
int i, max, ind;
int max(int A[], int longA){
max=0;
ind=0;
for(i=0; i<longA; i++){
if(A[i]>max){
max=A[i];
ind=i;
}
}
return(ind);
}