Anda di halaman 1dari 8

//#include <stdafx.

h>
#include <conio.h>
#include <windows.h>
#include <string.h>
#include <iostream.h>
//using namespace std;
#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;
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 Totra {
char modelo[cnt_max_string];
char fabricacion[cnt_max_string];
char color[cnt_max_string];
int anio;
}vec_otra[cnt_vec];
struct Totra Mat_otra [cnt_fil_mat] [cnt_col_mat];
/*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, 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 'A':
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+1));
cin>> Mat_otra[vsf] [vsc].modelo;
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+2));
cin>> Mat_otra[vsf] [vsc].fabricacion;
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+3));
cin>> Mat_otra[vsf] [vsc].color;
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+4));
cin>> Mat_otra[vsf] [vsc].anio;
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 'PO':
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+1));
cout<< Mat_otra[vsf] [vsc].modelo;
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+2));
cout<< Mat_otra[vsf] [vsc].fabricacion;
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+3));
cout<< Mat_otra[vsf] [vsc].color;
gotoxy(cnt_col_pant+vsx,(cnt_fil_pant+vsy+4));
cout<< Mat_otra[vsf] [vsc].anio;
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 Vector (int Plv, char Popcion,struct Tpersona Pvec_per[],struct Totra Pvec_
otra[])
{
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].direcc
ion;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+3));cin>> Pvec_per[vsf].telefo
no;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+4));cin>> Pvec_per[vsf].e
dad;
break;
case 'A':
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+1));cin>> Pvec_otra[vsf].modelo;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+2));cin>> Pvec_otra[vsf].fabri
cacion;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+3));cin>> Pvec_otra[vsf].color
;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+4));cin>> Pvec_otra[vsf].anio;
break;
case 'P':
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+0));cout<< Pvec_per[vsf].codig
o;
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].direc
cion;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+3));cout<< Pvec_per[vsf].telef
ono;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+4));cout<< Pvec_per[vsf].edad;
break;
case 'C':
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+1));cout<< Pvec_otra[vsf].modelo
;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+2));cout<< Pvec_otra[vsf].fabr
icacion;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+3));cout<< Pvec_otra[vsf].colo
r;
gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+4));cout<< Pvec_otra[vsf].anio
;
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: Eliminación de Registr ";
gotoxy(5,12); cout<< "6: Ingreso MATRIZ 2 DE (N x N) ";
gotoxy(5,13);cout<<" DIGITE 0 PARA SALIR ";

gotoxy(5,14);
cout<< "**************************************************************";
gotoxy(5,15);cout<<"Opcion: < >";
gotoxy(14,15);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;
// system("cls");
clrscr();
gotoxy(30,2); cout<<"codigo";
gotoxy(30,3); cout<<"Nombre";
gotoxy(30,4); cout<<"Direccion";
gotoxy(30,5); cout<<"Telefono";
gotoxy(30,6); cout<<"Edad";
Linea ('V',cnt_char_ver, Vfilas, Vcolumnas,0,0);
Linea ('H',cnt_char_hor, Vfilas, Vcolumnas,0,0);
Matriz(Vfilas, Vcolumnas,'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,'P');
while (getche() != '\n');
getche();
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,vec_otra);
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,vec_otra);
while (getche() != '\n');
getche();
break;
case 5:
// 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,vec_otra);
Vector (VLV,'B',vec_per,vec_otra);
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':
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,vec_otra);
break;
}
}
while (getche() != '\n');
getche();
break;
case 6:
// 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 matriz 2 ";
gotoxy(cnt_col_pant,cnt_fil_pant+1);
cout<< "Inserte filas de la matriz 2 : ";
cin>> Vfilas;
gotoxy(cnt_col_pant,cnt_fil_pant+2);
cout<< "Inserte columnas de la matriz 2 : ";
cin>> Vcolumnas;
// system("cls");
clrscr();
gotoxy(30,3); cout<<"Modelo";
gotoxy(30,4); cout<<"Fabricacion";
gotoxy(30,5); cout<<"Color";
gotoxy(30,6); cout<<"Anio";
Linea ('V',cnt_char_ver, Vfilas, Vcolumnas,0,0);
Linea ('H',cnt_char_hor, Vfilas, Vcolumnas,0,0);
Matriz(Vfilas, Vcolumnas,'A');
break;

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

Anda mungkin juga menyukai