[ Foro de C++ ]

me pidieron arreglar esto pero ya me perdi

24-Feb-2022 20:27
Invitado (yoo)
0 Respuestas

#include <time.h>
include <stdio.h>
#include <cono.h>
#include <string.h>
#include <sdlib.h>
#include <ctype.h>
#include <dos.h>
#define size 120

struct dire
{
char nombre [30];
char direccion[40];
char tel[11]
char ciudad [20];
char especialidad [20];
char estado[10];
char control[10];
char email[16];
}
dato [size;
char menu (void);
void ver(int,int);
void cua(int,int,int,int);
void llenar(void);
void buscar(void);
void inicia(void);
void guardar(void);
void cargar(void);
void ventana(int,int,int,int,int,int);
void lista (void);
void borrar(void);
void modificar(void);
int regis=0;
file *fp;
void main ()
{
char op;
clrscr();
textbackground(7);
//texmode(c80);
for(;;)
{
op=toupper(menu());
switch(op)
{
case '1':llenar();
break;
case '2':borrar();
break;
case '3':ver(0,0);
break;
case '4':modificar();
break;
case '5':lista();
break;
case '6':guardar();
break;
case 7':cargar();
break;
ase '8':buscar();
break;
case '9':exit(0);
break;
}
}
}

//---------------------------------------------------------------------
//devolver una seleccion del menu


char menu (void)
{
char opcion;
textbackground(1),clrscr(); textcolor(6);
ventana(16,7,61,22,0,2);
ventana(15,8,60,23,4,1);
textcolor(1);
gotoxy(25,9);cprintf("    m     e     n     u    ");
gotoxy(25,12);cprintf("1.- ALTAS");
gotoxy(25,13);cprintf("2.- BAJAS");
gotoxy(25,14);cprintf("3.- CONSULTAS");
gotoxy(25,15);cprintf("4.- MODIFICACIONES");
gotoxy(25,16);cprintf("5.- LISTA");
gotoxy(25,17);cprintf("6.- GUARDAR");
gotoxy(25,18);cprintf("7.- CARGAR");
gotoxy(25,19);cprintf("8.- BUSCAR");
gotoxy(25,20);cprintf("9.- EXIT");
TEXTCOLOR (8);
gotoxy(31,12);cprintf("1.");gotoxy(31,13);cprintf("2.");
gotoxy(31,14);cprintf("3.");gotoxy(31,15);cprintf("4.");
gotoxy(31,16);cprintf("5.");gotoxy(31,17);cprintf("6.");
gotoxy(31,18);cprintf("7.");gotoxy(31,19);cprintf("8.");
gotoxy(31,20);cprintf("9.");textcolor(4)
gotoxy(31,22);cprintf("Elija una opcion:");
opcion=getch();
textcolor(1);
return(opcion);
}


//---------------------------------------------------------------------
//inicializa el array


void inicia (void)
{
register int i;
for (i>0; i<size; i+)
*dato[i].nombre='\0';
}


//---------------------------------------------------------------------
// introducir datos


void llenar(void)
{
register int i;
char opc, ar[41];
do
{
cua(5,3,75,24);
for (i=0; i<size; i++)
if(!*dato[i].nombre)
break;
if (i=size)
{
gotoxy(20,10);cprintf("La base esta completa");
return;
}
textcolor(2);
regis++; //textcolor (6);
gotoxy(14,6);cprintf("REGISTRO No. %d",regis);
gotoxy(14,8);cprintf("NOMBRE: ");
ar[0]=3
strcpy(dato[i].nombre, cgets(ar));
gotoxy (14,10);cprintf("DIRECCION: ");
ar[0]=40;
strcpy(dato[i].direccion, cgets(ar));
gotoxy (14,12);cprintf("TELEFONO");
ar[0]=11;
strcpy(dato[i].telefono, cgets(ar));
gotoxy (14,14);cprintf("CIUDAD");
ar[0]=20;
strcpy(dato[i].CIUdad, cgets(ar));
gotoxy (14,16);cprintf("ESTADO");
ar[0]=10;
strcpy(dato[i]estado, cgets(ar));
gotoxy (14,18);cprintf("EMAIL");
ar[0]=16;
strcpy(dato[i].email, cgets(ar));
textcolor(15);
gotoxy(14,21);cprintf("otro registro (s/n):");
opc=getch();
while (toupper (opc)!='N');
}


//---------------------------------------------------------------------
// eliminar registros completos


void borrar ()
{
int num, ban=0,l;
char e,opc;
int i,var;
do
{
clrcr();
cua(5,3,75,24); textcolor(128);
gotoxy(18,10);cprintf("QUE REGISTRO DESEA BORRAR: ");
scanf("%d",&num);
if (num-1<0 | num>regis)
{
textcolor(3|BLINK);
gotoxy(20,13);cprintf("---- NO EXISTE ESE REGISTRO!!! ----");
textcolor(10);
gotoxy(30,21); cprintf ("ELIMINA REGISTRO(S/N): ");
opc=getch();
continue;
gotoxy();cprintf("");
}
for(i=00 i<=num-1; i++) //busca el registro
var=i;
ver (var,1);
textcolor (15); textbackground(1);
gotoxy(5,20), cprintf("confirma la eliminacion del registro (presiona S)");
e=getch();
if(toupper(e)=='S')
{
l1=var;
for (i=1: i<size; i++)
{
strcpy(dato[i].nombre,dato[i+1].nombre);
strcpy(dato[i].direccion,dato[i+1].direccion);
strcpy(dato[i].tel,dato[i+1].tel);
strcpy(dato[i].ciudad,dato[i+1].ciudad);
strcpy(dato[i].estado,dato[i+1].estado);
strcpy(dato[i].email,dato[i+1].email);
*dato[size].nombre='\0';
}
ban=1;
}
if (ban)
{

gotoxy(10,22); cprintf("El registro fue eliminado");
regis--;
}
else
{
gotoxy(10,22); cprintf("La operacion fue cancelada");
}
getch();
textcolor(4);
gotoxy(40,22); cprintf ("ELIMINA OTRO REGISTRO (S/N): ")
opc=getch();
} while (toupper (opc)=N');
}


//---------------------------------------------------------------------
// modificaciones


void modificar(void)
{
int num, el,mod,ban=0;
char e,opc,o,m,dat[41];
register int i, var;
do{
clrscr(); cua (8,5,60,20);   textcolor(10);
gotoxy (20,8);cprintf("QUE REGISTRO DESEA MODIFICAR: ");
scanf("%d",&num);
if (num-1<0 || num>regis)
{
textcolor(6|BLINK);
gotoxy(15,13);cprintf("---- NO EXISTE ESE REGISTRO!!! ----");
textcolor(14);
gotoxy(20,17); cprintf ("MODIFICAR REGISTRO(S/N): ");
opc=getch();
continue;
}
FOR (i=0; i<=num-1; ++) //busca el registro
var=i;
ver (var,1);
do
{
textcolor(10);
gotoxy(5,21); cprintf("1. Nombre   2. Direccion    3. Telefono    4. Ciudad    5. Estado    6. Email     7. Cancelar");
gotoxy(12,23);cprintf("QUE CAMPO DESEA MODIFICAR: ");
m=getch(),
//scanf("%d",&mod);
switch(m)
{
case '1':
{
gotoxy(23,8);cprintf("   ");
gotoxy(23,8); dat[0=30;
strcpy (dato[var].nombre,cgets(dat));
}
break;

case '2':
{
gotoxy(26,10);cprintf("   ");
gotoxy(26,10); dat[0]=40;
strcpy (dato[var].direccion,cgets(dat));
}
break;

case '3':
{
gotoxy(25,12);cprintf("    ");
gotoxy(25,12); dat[0]=11;
strcpy (dato[var].tel,cgets(dat));
}
break;

case '4':
{
gotoxy(23,14);cprintf("    ");
gotoxy(23,14); dat[0]=21;
strcpy (dato[var].ciudad,);
}
break;

case '5':
{
gotoxy(23,16);cprintf("    ");
gotoxy(23,16); dat[0]=16;
strcpy (dato[].estado,cgets(dat));
}
break;

case '6':
{
gotoxy(23,18);cprintf("    ");
gotoxy(23,18); dat[0]=16;
strcpy (dato[vars].email,cgets(dat));
}
break;

default:
{
ban=1;
}
brreak;
}
textcolor(4);
gotoxy(45,23); cprintf("MODIFICAR OTRO CAMPO(S/N): ");
o=getch();

}while (toupper (o)!='N' && ban!=1);
gotoxy(20,21);cprintf("EL CAMPO TECLEADO NO EXISTE");
TEXTCOLOR(4);
gotoxy(45,23); cprintf("MODIFICAR OTRO REGISTRO (S/N): ");
opc= getch();
} while (toupper(opc)!='n');
}


//---------------------------------------------------------------------
// busqueda por nombre


void buscar(void)
{
char alias[40],opc,*p;
register int i;
int found=0;
do
{
clrscr(); cua(8,5,70,23);
gotoxy(10,10);cprintf("nombre a buscar: ");
alias[0]=30;
p=cgets(alias);
for (i=0; i<=regis; i++)
{
if(!stricmp(p,dato[i].nombre))
{
ver (i,1);
found=1;
break;
}
}
//clrscr();
if(!found)
{
textcolor(3|BLINK);
gotoxy(10,15);cprintf("---- LA PERSONA NO ESTA REGISTRADA!!! ----");
getch(); textcolor(15);
gotoxy(20,21);cprintf("BUSCAR OTRO REGISTRO (S/N): ");
opc getch();
found=0;
}while (toupper(opc)!='N');
getch();
}


//---------------------------------------------------------------------
// recuperar el archivo de catalogo


void cargar(void)
{
register int i;
if((fp=fopen(c://datos.txt","r+b"))==NULL)
{
printf("No se puede abrir el archivo \n");
return;
}
inicia();
for(i=0; i<size; i++)
{
if(fread(&dato[i], sizeof(struct dire), 1, fp)!=1)
{
regis++;
if(feof(fp))
{
fclose(fp);
return;
}
}
gotoxy(10,10);cprintf("Error al leer el archivo\n");
}
}


//---------------------------------------------------------------------
// guardar


void guardar (void)
{
file *fp;
register int i;
if((fp=fp=open("c:\\datos.txt","w+b"))==NULL)
{
printf("no se puede abrir el archivo");
return;
}
for (i=0; i<size; i++)
{
if (*dato[].nombre)
{
if (fwrite(&dato[i],sizeof(struct dire),1,fp)!=1)
{
gotoxy(10,10);printf("Error de escritura de archivo");
}
}
}
fclse(fp);
}


//---------------------------------------------------------------------
// ver los datos de la persona


void ver (int n, int opci)
{
int num,bool=1;
cua(8,8,55,23); clrscr();
//textcolor(6);
//cua();
if(!opci)
{
gotoxy(20,5);cprintf("QUE REGISTRO DESEAS VISUALIZAR: ");
scanf("%d",&num);
num--;
}
else
num=n;
clrscr();
textbackground(9); textcolor(2);
cua(1,1,75,24);
gotoxy(40,2);cprintf("REGISTRO No. %d",num+1);
textcolor(8);
if (!regis)
{
bool=0;
gotoxy(15,15); cprintf("BASE VACIA");
}
if ((num<0)||(num>regis))
{
bool=0;
gotoxy(15,15); cprintf("NO EXISTE ESE REGISTRO");
}
if(bool)
{
cua(2,3,75,24); textcolor(10);
gotoxy(30,4);cprintf("REGISTRO No.%d",num+1);
gotoxy(15,8);cprintf("NOMBRE:%S",DATO[num].nombre);
gotoxy(15,10);cprintf("DIRECCION:%s".dato[num].direccion);
gotoxy(15,12);cprintf("TELEFONO:%".dato[num].telefono);
gotoxy(15,14);cprintf("CIUDAD:%s".dato[num].ciudad);
gotoxy(15,16);cprintf("ESTADO:%s".dato[nm].estado);
gotoxy(15,18);cprintf("EMAIL:%".dato[num].email);
}
textcolor(14);
gotoxy(45,24); cprintf("Presiona enter para continuar");
getch();
}


//---------------------------------------------------------------------
// lista de personas capturadas


void lista()
{
register int i=0;
int c=2,cot=0;
clrscr();
cua(1,1,75,24);
while(*dato[i].nombre!='\0' || *dato[i].tel!='\0')
{
cot=i+1;
textcolor(15);
gotoxy(5,c); cprintf("%d. - %s",cot,dato[i].nombre);
i++;
c++;
if (c==22)
{
textcolor(14);
gotoxy(40,24); cprintf("presiona enter para continuar");
getch();
clrscr();
c=2;
}
}
gotoxy(40,24); cprintf("presiona enter para terminar");
getch();
}


//---------------------------------------------------------------------
//

void cua(int a, int b, int c, int d)
{
int i;
textcolor(14);
textbackground(1);
clrscr();
for(i=a; i<=c; i++)
{
gotoxy(i,b); cprintf("Ä");
gotoxy(i,d); cprintf("Ä");
}
for(i=b; i<=d; i++)
{
gotoxy(a,i); cprintf("Ë");
gotoxy(C,i); cprintf("Ë");
}
gotoxy(a,b); cprintf("Ú");
gotoxy(a,d); cprintf("Á");
gotoxy(c,b); cprintf("?");
gotoxy(c,d); cprintf("Ú");
}

//---------------------------------------------------------------------


void ventana(int a, int b, int c, int d, int e, int f)
{
int i,j;
textcolor(e);
textbackground(15);
for (i=a; i<=c; i++)
{
for (j=b; j<=d; j++)
{
switch(f)
{
case '1':
{
gotoxy(i,j);cprintf("**");
}
break;
case '2':
{
gotoxy(i,j);cprintf("++");
}
break;
}
}
}
}




(No se puede continuar esta discusión porque tiene más de dos meses de antigüedad. Si tienes dudas parecidas, abre un nuevo hilo.)