Diego vega deber 29 03-11

6
diego vega deber 29-03-11 #include <stdafx.h> #include <conio.h> #include <windows.h>//marcos #include <string.h> #include <iostream> using namespace std;//turbo comentario #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 Tpersona Vauxt; void gotoxy(int x, int y)//turbo suprime { 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': Página 1

Transcript of Diego vega deber 29 03-11

Page 1: Diego vega deber 29 03-11

diego vega deber 29-03-11#include <stdafx.h> #include <conio.h> #include <windows.h>//marcos#include <string.h>#include <iostream> using namespace std;//turbo comentario

#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 Tpersona Vauxt;

void gotoxy(int x, int y)//turbo suprime{ 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':

Página 1

Page 2: Diego vega deber 29 03-11

diego vega deber 29-03-11 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 Ordenar (int PLV){for (int vsx = 0 ; vsx < PLV-1 ; vsx++) { for (int vsy = vsx +1 ; vsy < PLV ; vsy++)

{ if (Vec_per[vsx].codigo > Vec_per[vsy].codigo)

{ Vauxt = Vec_per[vsx];

Vec_per[vsx]=Vec_per[vsy]; Vec_per[vsy] = Vauxt;

} } }}

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 '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));

Página 2

Page 3: Diego vega deber 29 03-11

diego vega deber 29-03-11 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; } // 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) { int vsy=0;

for (int vsf = 0 ; vsf < Plv ; vsf++) { switch(Popcion)

{ case 'I':

gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+0));cin>> Vec_per[vsf].codigo; gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+1));cin>> Vec_per[vsf].nombres;

gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+2));cin>> Vec_per[vsf].direccion;

gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+3));cin>> Vec_per[vsf].telefono;

gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+4));cin>> Vec_per[vsf].edad; break; case 'P':

gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+0));cout<< Vec_per[vsf].codigo; gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+1));cout<< Vec_per[vsf].nombres;

gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+2));cout<< Vec_per[vsf].direccion;

gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+3));cout<< Vec_per[vsf].telefono;

gotoxy(cnt_col_pant,(cnt_fil_pant+vsy+4));cout<< Vec_per[vsf].edad; break; case 'B':

if (Vec_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);

Página 3

Page 4: Diego vega deber 29 03-11

diego vega deber 29-03-11 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: Eliminacion de Registro "; gotoxy(5,12);cout<< "6: Ordenar Vector ";

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(); Linea ('V',cnt_char_ver, Vfilas, Vcolumnas,0,0); Linea ('H',cnt_char_hor, Vfilas, Vcolumnas,0,0);

Matriz(Vfilas, Vcolumnas,'I'); static float media (float datos[]) { int i; int n= datos.length; float suma = 0; for (i=0; i<n; i++) suma = suma + datos[i]; return suma/n; }

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 (getchar() != '\n');getchar();

break;

case 3:

Página 4

Page 5: Diego vega deber 29 03-11

diego vega deber 29-03-11 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'); 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');

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'); Vector (VLV,'B'); 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');

break;

Página 5

Page 6: Diego vega deber 29 03-11

diego vega deber 29-03-11}

}while (getche() != '\n');getche();

break; case 6: Ordenar(VLV);

system("cls"); Vector (VLV,'P');

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

break; case 0:

cout<<"\n";cout<< "\nPulse cualquier tecla para continuar";getche();vsbandera=0;

} } }void main(void) { menu(); }

Página 6