Você está na página 1de 11

#define cnt_max_string 10

#define cnt_char_ver 'x'


#define cnt_char_hor '-'
#define cnt_char_marco '*'
#define cnt_char_limpiar ' '
#define cnt_col_pant 5
#define cnt_fil_pant 2
#define cnt_col_mat 20
#define cnt_fil_mat 20
#define cnt_vec 20
#define cnt_num_campos 5
int VOPCION;
int VLV;
int Vfilas,Vcolumnas,edad,cont;
int vsy;
int Vcodigo;
int Vbusqueda;
int Vfila_B;
struct Tpersona{
int codigo;
char nombres[cnt_max_string];
char direccion[cnt_max_string];
char telefono[cnt_max_string];
int edad;
}
Vec_per[cnt_vec];
struct Tpersona Mat_per [cnt_fil_mat] [cnt_col_mat];
struct Tpersona VAUXT;

/*
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
*/
void Linea (char Ptipo,char Pcaracter,int Pfil, int Pcol,int Pfili,int Pcoli)
{
int vsm,vsmi,vsmf;
int vsl,vsli,vslf;
int vsinc;
switch(Ptipo)
{
case 'V':
vsli=(cnt_col_pant-1); vslf=((cnt_max_string*Pcol)+vsli+Pcol);
vsmi=(cnt_fil_pant-1); vsmf=(((cnt_num_campos+1)*Pfil))+1;
vsinc=cnt_max_string+1;
break;
case 'H':
vsli=(cnt_fil_pant-1); vslf=(((cnt_num_campos+1)*Pfil))+1;
vsmi=(cnt_col_pant-1); vsmf=((cnt_max_string*Pcol)+vsmi+Pcol);
vsinc=cnt_num_campos+1;
break;
case 'X':
vsli=Pcoli; vslf=Pcol; vsmi=Pfili; vsmf=Pfil; vsinc=Pcol-Pcoli;
break;
case 'Y':
vsli=Pfili; vslf=Pfil; vsmi=Pcoli; vsmf=Pcol; vsinc=Pfil-Pfili;
break;
case 'L':
vsli=Pfili; vslf=Pfil; vsmi=Pcoli; vsmf=Pcol; vsinc=1;
break;
}
for (vsl=vsli;vsl<=vslf;vsl+=vsinc)
{
for (vsm=vsmi;vsm<=vsmf;vsm++)
{
switch(Ptipo)
{
case 'V': gotoxy(vsl,vsm); cout<< Pcaracter; break;
case 'H': gotoxy(vsm,vsl); cout<< Pcaracter; break;
case 'X': gotoxy(vsl,vsm); cout<< Pcaracter; break;
case 'Y': gotoxy(vsm,vsl); cout<< Pcaracter; break;
case 'L': gotoxy(vsl,vsm); cout<< Pcaracter; break;
}
}
}
};
void Matriz (int Pfil, int Pcol,int Plv, char Popcion)
{
int vsy=0;
for (int vsf = 0 ; vsf < Pfil ; vsf++)
{
int vsx=0;
for (int vsc = 0 ; vsc < Pcol ; vsc++)
{
switch(Popcion)
{
case 'I':
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+0));
cin>> Mat_per[vsf][vsc].codigo;
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+1));
cin>> Mat_per[vsf] [vsc].nombres;
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+2));
cin>> Mat_per[vsf] [vsc].direccion;
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+3));
cin>> Mat_per[vsf] [vsc].telefono;
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+4));
cin>> Mat_per[vsf] [vsc].edad;
break;
case 'P':
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+0));
cout<< Mat_per[vsf] [vsc].codigo;
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+1));
cout<< Mat_per[vsf] [vsc].nombres;
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+2));
cout<< Mat_per[vsf] [vsc].direccion;
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+3));
cout<< Mat_per[vsf] [vsc].telefono;
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+4));
cout<< Mat_per[vsf] [vsc].edad;
break;
case 'C':

for (int vsf = 0 ; vsf < Pfil ; vsf++)


{
for (int vsc = 0 ; vsc < Pcol ; vsc++)
{
for (int vsk = 0 ; vsk < Plv ; vsk++)
{
Vec_per[vsk].codigo = Mat_per[vsf] [vsc].codigo;
Vec_per[vsk].nombres = Mat_per[vsf] [vsc].nombres;
Vec_per[vsk].direccion = Mat_per[vsf] [vsc].direccion;
Vec_per[vsk].telefono = Mat_per[vsf] [vsc].telefono;
Vec_per[vsk].edad = Mat_per[vsf] [vsc].edad;

}
}
}

break;

} // fin del switch


vsx+=cnt_max_string+1;
} // fin del for vsc
vsy+=cnt_num_campos+1;
} // fin del for vsf
}// fin del void matriz
void ordenar_vec(int Plv, struct Tpersona PVec_per[])
{
for (int x = 0 ;x < Plv-1 ; x++)
{
for ( int y=x+1 ; y< Plv ; y++)
{
if( PVec_per[x].codigo>PVec_per[y].codigo)
{
VAUXT = PVec_per[x];
PVec_per[x] = PVec_per[y];
PVec_per[y] = VAUXT;
}
}
}
}
//
/* void matrizvector(int Pfil, int Pcol, int Plv, struct Tpersona PVec_per[
])

int vsy=0;
for (int vsf = 0 ; vsf < Pfil ; vsf++)
{
int vsx=0;
for (int vsc = 0 ; vsc < Pcol ; vsc++)
{
for (int vsk = 0 ; vsk < Plv ; vsk++)
{
PVec_per[vsk].codigo = Mat_per[vsf] [vsc].codigo;
PVec_per[vsk].nombres = Mat_per[vsf] [vsc].nombres;
PVec_per[vsk].direccion = Mat_per[vsf] [vsc].direccion;
PVec_per[vsk].telefono = Mat_per[vsf] [vsc].telefono;
PVec_per[vsk].edad = Mat_per[vsf] [vsc].edad;

}
}
}

*/
void Vector (int Plv, char Popcion, struct Tpersona PVec_per[])
{
int vsy=0;
for (int vsf = 0 ; vsf < Plv ; vsf++)
{
switch(Popcion)
{
case 'I':
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+0));cin>> PVec_per[vsf].codigo;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+1));cin>> PVec_per[vsf].nombres;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+2));cin>> PVec_per[vsf].direccion
;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+3));cin>> PVec_per[vsf].telefono;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+4));cin>> PVec_per[vsf].edad;
break;
case 'P':
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+0));cout<< PVec_per[vsf].codigo;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+1));cout<< PVec_per[vsf].nombres;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+2));cout<< PVec_per[vsf].direccion
;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+3));cout<< PVec_per[vsf].telefono;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+4));cout<< PVec_per[vsf].edad;
break;
case 'B':
if (PVec_per[vsf].codigo == Vcodigo)
{
Vbusqueda=1;
Vfila_B=vsf;
}
break;

} // fin del switch


vsy+=cnt_num_campos+1;
} // fin del for vsf
}// fin del void vector

void menu()
{
// system("cls");
clrscr();
int vsbandera;
char vseliminar;
vsbandera=1;
while (vsbandera!=0)
{
// system("cls");
clrscr();
//Linea ('L',cnt_char_limpiar,24,79,0,0);
Linea ('X',cnt_char_marco,23,79,0,0);
Linea ('Y',cnt_char_marco, 23, 79,0,0);
gotoxy(5,5);
cout<< " Programa ejemplo del uso de estructuras con vectores y matrices
";
gotoxy(5,6);
cout<< "**************************************************************\n
";
gotoxy(5,7); cout<< "1: Ingreso de MATRIZ DE (N x N) ";
gotoxy(5,8); cout<< "2: Reporte de MATRIZ DE (N x N) ";
gotoxy(5,9); cout<< "3: Ingreso de VECTOR DE (N) ";
gotoxy(5,10);cout<< "4: Reporte de VECTOR DE (N) ";
gotoxy(5,11);cout<< "5: Ordenar vector ";
gotoxy(5,12);cout<< "6: Buscar vector ";
gotoxy(5,13);cout<< "7: Modificar vector ";
gotoxy(5,14);cout<< "8: Eliminación de Registr ";
gotoxy(5,15);cout<< "9: Cambiar matriz a Vector ";
gotoxy(5,16);cout<< "8: calcular mayores de edad matriz vector ";
gotoxy(5,17);cout<<" DIGITE 0 PARA SALIR ";
gotoxy(5,18);
cout<< "**************************************************************";
gotoxy(5,19);cout<<"Opcion: < >";
gotoxy(14,19);cin>> VOPCION;
switch (VOPCION)
{
case 1:
// system("cls");
clrscr();
Linea ('X',cnt_char_marco,25,79,0,0);
Linea ('Y',cnt_char_marco, 25, 79,0,0);
Linea ('X',cnt_char_marco,cnt_fil_pant+3,40,cnt_fil_pant-1,cnt_col_pant-1);
Linea ('Y',cnt_char_marco, cnt_fil_pant+3, 40,cnt_fil_pant-1,cnt_col_pant-1);
gotoxy(cnt_col_pant,cnt_fil_pant);
cout<< "Ingreso datos de una matriz ";
gotoxy(cnt_col_pant,cnt_fil_pant+1);
cout<< "Inserte filas de la matriz : ";
cin>> Vfilas;
gotoxy(cnt_col_pant,cnt_fil_pant+2);
cout<< "Inserte columnas de la matriz: ";
cin>> Vcolumnas;
VLV=Vfilas*Vcolumnas;
// system("cls");
clrscr();
Linea ('V',cnt_char_ver, Vfilas, Vcolumnas,0,0);
Linea ('H',cnt_char_hor, Vfilas, Vcolumnas,0,0);
Matriz(Vfilas, Vcolumnas,VLV,'I');
break;
case 2:
// system("cls");
clrscr();
Linea ('V',cnt_char_ver, Vfilas, Vcolumnas,0,0);
Linea ('H',cnt_char_hor, Vfilas, Vcolumnas,0,0);
Matriz(Vfilas, Vcolumnas,VLV,'P');
while (getchar() != '\n');
getchar();
break;
case 3:
//system("cls");
clrscr();
Linea ('X',cnt_char_marco,25,79,0,0);
Linea ('Y',cnt_char_marco, 25, 79,0,0);
Linea ('X',cnt_char_marco,cnt_fil_pant+3,40,cnt_fil_pant-1,cnt_col_pant-1);
Linea ('Y',cnt_char_marco, cnt_fil_pant+3, 40,cnt_fil_pant-1,cnt_col_pant-1);
gotoxy(cnt_col_pant,cnt_fil_pant);
cout<< "Ingreso de datos en un Vector ";
gotoxy(cnt_col_pant,cnt_fil_pant+1);
cout<< "Ingrese Longitud del Vector: ";
cin>>VLV;
//system("cls");
clrscr();
Linea ('V',cnt_char_ver, VLV,1,0,0);
Linea ('H',cnt_char_hor, VLV,1,0,0);
Vector (VLV,'I',Vec_per);
break;
case 4:
// system("cls");
clrscr();
Linea ('V',cnt_char_ver, VLV,1,0,0);
Linea ('H',cnt_char_hor, VLV,1,0,0);
Vector (VLV,'P',Vec_per);
while (getchar() != '\n');
getchar();
break;
case 5:
//system("cls");
clrscr();
Linea ('V',cnt_char_ver, VLV,1,0,0);
Linea ('H',cnt_char_hor, VLV,1,0,0);
ordenar_vec(VLV,Vec_per);
Vector (VLV,'P',Vec_per);
while (getchar() != '\n');
getchar();
break;
case 6:
// cout<< Vfila_B;
//int vsy=0;
//system("cls");
clrscr();
Vbusqueda=0;
Linea ('X',cnt_char_marco,25,79,0,0);
Linea ('Y',cnt_char_marco, 25, 79,0,0);
Linea ('X',cnt_char_marco,cnt_fil_pant+3,40,cnt_fil_pant-1,cnt_col_pant-1);
Linea ('Y',cnt_char_marco, cnt_fil_pant+3, 40,cnt_fil_pant-1,cnt_col_pant-1);
gotoxy(cnt_col_pant,cnt_fil_pant); cout<< "Busqueda en un Vector ";
gotoxy(cnt_col_pant,cnt_fil_pant+1); cout<< "Ingrese codigo: ";
cin>>Vcodigo;
//system("cls");
clrscr();
Linea ('V',cnt_char_ver, VLV,1,0,0);
Linea ('H',cnt_char_hor, VLV,1,0,0);
Vector (VLV,'B',Vec_per);
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+0));cout<< Vec_per[Vfila_B].codig
o;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+1));cout<< Vec_per[Vfila_B].nombr
es;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+2));cout<< Vec_per[Vfila_B].direc
cion;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+3));cout<< Vec_per[Vfila_B].telef
ono;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+4));cout<< Vec_per[Vfila_B].edad;
while (getchar() != '\n');
getchar();

break;
case 7:
// cout<< Vfila_B;
//int vsy=0;
//system("cls");
clrscr();
Vbusqueda=0;
Linea ('X',cnt_char_marco,25,79,0,0);
Linea ('Y',cnt_char_marco, 25, 79,0,0);
Linea ('X',cnt_char_marco,cnt_fil_pant+3,40,cnt_fil_pant-1,cnt_col_pant-1);
Linea ('Y',cnt_char_marco, cnt_fil_pant+3, 40,cnt_fil_pant-1,cnt_col_pant-1);
gotoxy(cnt_col_pant,cnt_fil_pant); cout<< "Busqueda de Vector a modificar";
gotoxy(cnt_col_pant,cnt_fil_pant+1); cout<< "Ingrese codigo: ";
cin>>Vcodigo;
//system("cls");
clrscr();
Linea ('V',cnt_char_ver, VLV,1,0,0);
Linea ('H',cnt_char_hor, VLV,1,0,0);
Vector (VLV,'B',Vec_per);
if (Vbusqueda==1)
{
Linea ('X',cnt_char_marco,cnt_fil_pant+14,60,cnt_fil_pant-1,cnt_col_pant-1);
Linea ('Y',cnt_char_marco, cnt_fil_pant+14,60,cnt_fil_pant-1,cnt_col_pant-1);
gotoxy(cnt_col_pant+15,cnt_fil_pant+3);
cout<< "Desea modificar el registro S/N : ";
cin>>vseliminar;
switch (vseliminar)
{
case 'S':case's':

gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+1));cin>> Vec_per[Vfila_B].nombre
s;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+2));cin>> Vec_per[Vfila_B].direcc
ion;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+3));cin>> Vec_per[Vfila_B].telefo
no;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+4));cin>> Vec_per[Vfila_B].edad;

// system("cls");
Linea ('V',cnt_char_ver, VLV,1,0,0);
Linea ('H',cnt_char_hor, VLV,1,0,0);
break;
}
}

while (getchar() != '\n');


getchar();
break;

case 8:
//system("cls");
clrscr();
Vbusqueda=0;
Linea ('X',cnt_char_marco,25,79,0,0);
Linea ('Y',cnt_char_marco, 25, 79,0,0);
Linea ('X',cnt_char_marco,cnt_fil_pant+3,40,cnt_fil_pant-1,cnt_col_pant-1);
Linea ('Y',cnt_char_marco, cnt_fil_pant+3, 40,cnt_fil_pant-1,cnt_col_pant-1);
gotoxy(cnt_col_pant,cnt_fil_pant); cout<< "Busqueda en un Vector ";
gotoxy(cnt_col_pant,cnt_fil_pant+1); cout<< "Ingrese codigo: ";
cin>>Vcodigo;
//system("cls");
clrscr();
Linea ('V',cnt_char_ver, VLV,1,0,0);
Linea ('H',cnt_char_hor, VLV,1,0,0);
Vector (VLV,'P',Vec_per);
Vector (VLV,'B',Vec_per);
if (Vbusqueda==1)
{
Linea ('X',cnt_char_marco,cnt_fil_pant+14,60,cnt_fil_pant-1,cnt_col_pant-1);
Linea ('Y',cnt_char_marco, cnt_fil_pant+14,60,cnt_fil_pant-1,cnt_col_pant-1);
gotoxy(cnt_col_pant+15,cnt_fil_pant+3);
cout<< "Desea eliminar el registro S/N : ";
cin>>vseliminar;
switch (vseliminar)
{
case 'S':case's':
cout<< Vfila_B;
Vec_per[Vfila_B].codigo=0;
strcpy(Vec_per[Vfila_B].nombres,"");
strcpy(Vec_per[Vfila_B].direccion,"");
strcpy(Vec_per[Vfila_B].telefono,"");
Vec_per[Vfila_B].edad=0;
// system("cls");
Linea ('V',cnt_char_ver, VLV,1,0,0);
Linea ('H',cnt_char_hor, VLV,1,0,0);
Vector (VLV,'P',Vec_per);
break;
}
}
while (getchar() != '\n');
getchar();
break;
case 9:
clrscr();

Matriz(Vfilas, Vcolumnas,VLV,'C');
while (getchar() != '\n');
getchar();
break;
case 10:
cont=0;
clrscr();
Vbusqueda=0;
Linea ('X',cnt_char_marco,25,79,0,0);
Linea ('Y',cnt_char_marco, 25, 79,0,0);
Linea ('X',cnt_char_marco,cnt_fil_pant+3,40,cnt_fil_pant-1,cnt_col_pant-1);
Linea ('Y',cnt_char_marco, cnt_fil_pant+3, 40,cnt_fil_pant-1,cnt_col_pant-1);
gotoxy(cnt_col_pant,cnt_fil_pant); cout<< "M= matriz ----- V=vector";
gotoxy(cnt_col_pant,cnt_fil_pant+1); cout<< "Ingrese codigo: ";
cin>>Vcodigo;
//system("cls");
clrscr();
switch (Vcodigo)
{
case 'M':case'm':

for (int vsf = 0 ; vsf < Pfil ; vsf++)


{
for (int vsc = 0 ; vsc < Pcol ; vsc++)
{
if (Mat_per[vsf][vsc].edad>18)
{
cont=cont+1
}
}
cout<< " Los mayores de edad son:"<<cont;
break;
case 'V':case'v':
for (int vsf = 0 ; vsf < Plv ; vsf++)
{
if (Vec_per[vsf].edad>18)
{
cont=cont+1
}
}
cout<< " Los mayores de edad son:"<<cont;
break;
}
}

while (getchar() != '\n');


getchar();

break;
case 0:
cout<<"\n";
cout<< "\nPulse cualquier tecla para continuar";
getchar();
vsbandera=0;
}
}
}
void main(void)
{ menu(); }

Você também pode gostar