Escribir un sistema de biblioteca en lenguaje C

¡Puedes consultar lo siguiente!

Sistema completo de gestión de bibliotecas en lenguaje c

# include ltstdlib.h gt

# include ltstdio.h gt

# include ltconio. h gt

#Contiene "graphics.h"

#Contiene "math.h"

#Definir m 1

estructura de datos

{ int año;

int mes;

int día

}; nodo

{

Número de carácter [20];

Estructurar datos hermano

Estructurar los datos nuevamente;

};

Nodo del libro de estructura

{

título char[15];

escritor char[15]; >

int currentnum

int totalnum

char brief[30];

lector de nodo lector de estructura[20]; };

Nodo de árbol de estructura

{

int n;

struct TreeNode * prt

int key [2 * m];

estructura libro nodo * rec[2 * m];

estructura TreeNode * enlace[2 * m 1];

} ;

struct book node * input node();

struct TreeNode * MB search(struct TreeNode * BTH, int x, int *k, int * flag);

struct TreeNode * mbinsert(struct TreeNode * BTH);

struct TreeNode * MB del(struct TreeNode * BTH);

nodo de salida nulo (struct TreeNode * BTH) ;

préstamo nulo(struct TreeNode * BTH);

retorno nulo(struct TreeNode * BTH);

menú char( void);

struct TreeNode * MB search(struct TreeNode * BTH, int x, int *k, int *flag)

{

struct TreeNode * p, * q

p = bth* bandera = 0; q = p;

Y ((p! = NULL) amp; amp(*flag==0))

{

* k = 1; q = p;

mientras((* k lt; q->; n) amp; amp (pregunta->; clave[* k-1] lt; x))* k = * k 1; * k-1]= = x)* flag = 1;

else if((* k = = q- gt; n) amp;

amp(pregunta->key[*k-1]lt;x)){ p = q- gt;link[*k];p->PRT = q;}

else { p = q - gt; enlace [* k-1]; p->; PRT = q; * k = * k-1; p>

}

struct TreeNode * mbinsert(struct TreeNode * BTH)

{

int flag, j, k, t < /p; >

int y, x, z;

Estructura TreeNode *p, *q, *u, *s;

struct BookNode *r, *l;

clr SCR();

printf(" \ n \ tIngrese el libro que desea insertar: ");

scanf("d ", ampx );

q=mbsearch(bth, x, ampk amp; bandera);

if(bandera==1)

{

printf(" \ n \ tYa existen d libros de este tipo. ¿Quieres agregar otro? (y/n)\n ", (q- gt; rec[k-1])- gt; total num ) ;

z = getch();

if(z=='y'||z=='Y ')

{

(Q->rec[k-1])- gt; número total; (Q->rec[k-1])- gt; número actual;

printf(" \ n \ tAhora hay un total de d libros de este tipo, ", (q- gt; rec[k-1])- gt; total num);

printf(" \ n \ tActualmente en Hay d en la biblioteca.

, (q- gt; rec[k-1])- gt; número actual

}

Retorno (BTH); p>

r = nodo de entrada (BTH);

if(bth==NULL)

{

BTH = p =(struct TreeNode * )malloc(tamaño de(struct TreeNode));

p->;n = 1;p->;key[0]= x;p->;rec[0]= r;p- >;prt = NULL

for(j = 1; j lt= 2 * m 1; j )p- gt; enlace[j-1]= NULL; p);

}

p = NULLt = 0;

mientras(t==0)

{

if(k = = q- gt; n){ y = x; l = r; u = p;}

Otro

{

y = q-gt; clave[q->n-1]; l = q-gt; rec[q->n-1]; p>

for(j =(q- gt; n)-1; j gt= k 1; j -)

{

q->; ]= q-gt; clave [j-1]; rec[j]= q-gt; rec[j-1]; ];

}

q->; clave[k]= x; rec[k]= r; ;

if (p!= NULL) p- gt; prt = q;

}

if (q->n lt2 * m )

{

q->; n = (q- gt; n) 1;

t = 1;

q ->clave; [(q->n)-1]=y;q->rec[(q->n)-1]= l;q->link[q->n]= u;

if (u!= NULL)ugt; PRT = q;

}

Otro

{

p =(struct TreeNode *)malloc(sizeof(struct TreeNode)).

p->n = m; q->; n = m; prt = q-gt; prt

x = q-gt; ; r = q- gt; sugerencia [m];

for(j = 1; j lt= m-1; j )

{

p ->clave[j-1]=q->clave[m j] p->rec[j-1]=q->rec[m j] p->enlace[j-1]=q ->enlace[m j] ;

if (q->; enlace[m j]!= NULL)(q- gt; enlace[m j])- gt;

}

p->;enlace[m-1]=q->enlace[2 * m];

p->;enlace[m]= u;

p->; clave[m-1]= y;

p->; rec[m-1]= l

Si (u! = NULL)ugt ; PRT = p;

for(j = m 2; j lt= 2 * m 1; j )

{

q->enlace[j] -1]= NULL; p->enlace[j-1]= NULL;

}

if (q->prt== NULL)

{

s =(struct TreeNode *)malloc(sizeof(struct TreeNode)).

s-gt; clave[0]= x; s-gt; rec[0]= r;

s-gt; ;enlace[1]= p;

s- gt;n = 1;s- gt;prt = NULLq->;PRT = s;p->;PRT = s;

for(j = 3; j lt= 2 * m 1; j )s- gt; enlace[j-1]= NULL

BTH = s;

}

Otros

{

q = q- gt; prtk = 1

Y ((k lt= q->n) amp(Q->tecla[k-1] lt;x))k = k 1;

k = k-1;

}

}

}

Retorno (BTH);

}

Nodo del árbol de estructura *mbdel( Nodo del árbol de estructura * bth)

{

int flag, j, k, t;

int x, y

Estructura TreeNode *u, *s, *p, *q;

struct BookNode *r, *l;

clr SCR();

printf(" \n\tPor favor ingresa el libro que deseas eliminar: ");

scanf("d", ampx);

q=mbsearch(bth,x, ampk amp; flag );

if(flag == 0){ printf(" \ n \ t¡Este libro no existe! \ n "); return (BTH);

p = q - gt; [k];

if (p!=null)

{

mientras(p->;enlace[0]!= NULL )p = p - gt; enlace[0];

q->; clave[k-1]=p->clave[0]; ]=p->rec[0];

k = 1; q = p;

}

for(j = k; j lt= q ->;n-1;j)

{

q->;clave[j-1]=q->clave[j];

q->;rec[j-1]=q->recomendación[j];

}

q->;n = q- gt;n- 1;

Y ((q! = BTH) amp; amp(Q->n ltm))

{

p = q- prtj = 1; >enlace[j-1]! = q)j = j 1;

if ((j lt= p->n) amp; amp((p->enlace[j] )- gt; n gtm))

{

s = p- gt; enlace[j];

y = s- gt clave[0 ]; p>

l = s-gt; rec[0];

u = s-gt;

for(k = 1 ;k lt= s- gt; n-1; k )

{

s- gt; clave[k-1]= s- gt;

s-gt; rec[k-1]=s->rec[

k];

s-gt; enlace[k-1]= s-gt; enlace[k];

}

s-gt; [s- gt; n-1]=s->enlace[s- gt; n];

s- gt; >s- gt; n = s- gt; n->; n = q- n 1;

q->; p->key[j-1]

q->rec[q->n-1]= p->rec[j-1]

q->;Enlace [q-gt;n]=u;

p->;key[j-1]= y;

p->;rec[j -1]= l;

if (u!= NULL)ugt; PRT = q;

}

else if((j gt; 1); amp(( p->;enlace[j-2])- gt;n gtm))

{

s = p- gt;enlace[j-2 ];

q->;n = q- gt;n 1;

q->;Enlace[q- gt;n]= q- gt;Enlace[q- gt;n-1]

for(k = q- gt; n-1; k gt=1; k -)

{

q ->;clave[k ]= q- gt;key[k-1];

q->;rec[k]= q- gt;rec[k-1];

q-> ; enlace[k]= q-gt; enlace[k-1];

}

q->; ];

q->;rec[0]= p- gt;sugerencia[j-2];

u = s- gt;enlace[ s- gt; ;

q->; enlace[0] = u;

if (u! = NULL) u- gt = q; >clave[j-2]=s- gt;clave[s->n-1]

p->rec[j-2]=s- >rec[s- gt; ];

s-gt; enlace[s-gt; n] = NULL

s-gt; p>}

Otros

{

if(j = = p- gt; n 1)

{ q = p- gt; enlace[j-2]; s = p- gt; enlace[j-1]; j = j-1;}

otro s = p - gt;enlace[j];

q->;key[q->;n]= p- gt;key[j-1];

q->; rec[q->;n]= p - gt; rec[j-1];

t = q- gt;n 1;

for(k = 1;k lt= s- gt; n; k )

{ q->; clave[t k-1]= s- gt; clave[k-1];

q- >; rec[t k-1]= s-gt; rec[k-1];

u = s-gt; enlace[k-1]; u;

Si (u! = NULL)ugt;PRT = q;

}

>u = s- gt; enlace[s- gt; n]; q->; enlace[t s->; PRT = q;

q->; n = 2 * m;

Gratis

for(k = j; k lt= p->; n-1; k )

{

p->; clave[k-1]=p->clave[k];

p-> ;rec[k-1]=p->rec[k];

p->; enlace[k]= p- enlace[k 1];

}

p->; n = p-gt; s = q;

}

}

if((q == BTH) amp; amp(Q->n==0))

{free(BTH); BTH-gt; >

if(s- gt; n = = 0){ BTH = NULL; free;}

}

printf(" \ n \ t¡El libro ha sido eliminado! ");

Retorno (BTH);

}

struct BookNode *InputNode()

{

struct book node * p;

int I;

p =(struct BookNode *)malloc(sizeof(struct BookNode));

clr SCR( );

fflush(stdin);

printf("\n\tIngrese el título:");

Obtener (p- gt; título ); /p>

printf("\n\tIngrese el escritor:");

Get(p- gt;writer);

printf(" \ n\tIngrese el actual importe del libro: ");

scanf("d", ampp->;num actual);

printf("\n\tIngrese el importe total del libro: ");

scanf("d ", ampp->; num total);

fflush(stdin);

printf(" \ n \ tEnter una breve descripción del libro: ");

Get (p- gt; short);

for (I = 0; i lt20; i )

(p->lector[i]).

num[0]= '\0';

Retorno (p);

}

nodo de salida nulo (struct TreeNode * BTH)

{

estructura TreeNode * q;

estructura libro nodo * p;

int k;

int x;

int flag;

clr SCR();

printf(" \ n \ tIngrese el libro que desea buscar: "

);

scanf("d ", ampx);

q=mbsearch(bth, x, ampk amp; bandera);

if(bandera==1)

{

p = q- gt; rec[k-1];

printf("\n\tTítulo: s ", p- gt; título);

printf("\n\tWriter: s ", p- gt; escritor

printf("\n\tCurrentAmount: d ", p- gt; número actual) ;

printf("\n\tMontoTotal: d ",p- gt; num total);

printf("\n\tbreve introducción: s\n",p- gt; short);

}

else printf("\n\t¡Este libro no existe!");

}

void pedir prestado(struct TreeNode *bth)

{

struct TreeNode * q;

struct book node * p;

Estructura nodo lector * r;

int i, k, x, flag, t;

clr SCR();

printf(" \ n \ t Por favor ingresa el libro que deseas tomar prestado: ");

scanf("d ", ampx);

q=mbsearch(bth, x, ampk amp; flag);

p>

if(flag==1)

{

p = q- rec[k-1]; p>printf(" \n\t¿Quieres este libro? (s/n)");

printf("\n\tTítulo: s ", p- gt; título);

printf("\n\tEscritor: s " , p- gt; escritor);

printf("\n\tCantidadActual: d ", p- gt; número actual);

printf("\n\tCantidadTotal: d ", p- gt; num total);

printf(" \ n \ tbreve introducción: s ", p- gt; short);

t = getch();

if(t=='y'||t=='Y ')

{

Si ((p- gt; número actual)== 0)printf(" \ n \ tLo sentimos, todo este libro ha sido retirado..."

Otros

);

p>

{

clr SCR();

for(I = 0; i lt20; i ) if ((p- gt; lector [i]). num [0]= = ' \ 0 ')break;

printf(" \ n \ tIngrese su número de certificado: "); gt;reader[i]).num);

printf("\n\tPor favor ingrese los datos del préstamo:");

printf("\n\tAño: ");

scanf("d ", amp((p->lector[I]).bro.year);

printf("\tmes:") ;

scanf("d", amp((p->lector[I]).bro.month);

printf("\tDía:");

p >

scanf("d ", amp((p->reader[I]).bro.day);

printf("\n\tIngrese los datos de devolución:") ;

printf("\n\tAño:");

scanf("d", amp((p->;lector[I]).back.año);

printf("\t mes:");

scanf("d", amp((p->lector[I]).back.mes));

printf("\tDay:");

scanf("d", amp((p->;lector[I]).back.day));

p->numero actual-

printf("\n\tHas tomado prestado este libro.

);}

}

}

else printf(" \ n \ t¡Este libro no existe!"

}

reciclaje de vacíos (struct TreeNode *bth)

{

struct TreeNode * q;

struct book node * p;< / p>

int i, k, x, bandera, t, j;

int año, mes, día, d

Salario variable

< p; >Temperatura de carga[20];

clr SCR();

printf("\n\tPor favor, introduzca el libro que desea reembolsar:");

scanf("d ", ampx);

q=mbsearch(bth, x, ampk amp; bandera);

if(bandera==1)

{

p = q- gt; rec[k-1];

printf("\n\t¿Quieres pagar este libro? (s/ n)" );

printf("\n\tTítulo: s ", p- gt; título

printf("\n\tEscritor: s ", p- gt; escritor); );

printf("\n\tCantidadActual: d ",p- gt; número actual);

printf("\n\tCantidadTotal: d ",p - gt; número total);

printf(" \ n \ tbreve introducción: s ", p- gt; short

t = getch(); if(t=='y'||t=='Y ')

{

If ((p- gt; currentnum)>=(p-> ;Cantidad total ) )

printf(" \ n \ tLe gustaría proporcionar más libros\ n ");

Otro

{

clr SCR();

printf("\n \tPor favor ingrese su número de certificado: ");

scanf("s", temp);

p>

j = 0;

for(I = 0;ilt20;i)

{

if (!(strcmp(temp, (p- gt ; lector[i]). num)){ j = 1; break;}

}

if(j = = 0){ printf(" \ n \ tNo tomaste prestado este libro.") ; Return;}

printf("\n\tHoy es:");

printf("\n\tAño:");

scanf (" d", amp año);

printf("\t mes:");

scanf("d", amp mes);

printf( "\tDía:");

scanf("d", amp día);

d = 0;

if (año lt(p -> lector[I]).back.año)d = 1;

if (añolt=(p->lector[I])).

amp meslt(p->lector[I]).back.mes)d = 1;

if (añolt=(p->lector[I]). ampmonthlt=( p->lector[i ]), back.month ampday lt(p->lector[I]).back.day)d = 1;

if (d==0)

{

clr SCR();

Salario=(año-(p- gt; lector[i]).back.año)*365 (mes -(p- gt; lector[I] ]). atrás . mes)* 30 (día-(p- gt; lector[I]). atrás . día);

printf(" \ n \ tTomaste prestado este libro en d-d-d ", ( p- gt; lector[i]). año hermano, (p- gt; lector[I]) mes hermano, (p- gt; lector[I] ).bro.día);

printf(" \ n \ t debe reembolsarse dentro de d-d-d ", (p- gt; lector[i]).back.year, (p- gt; lector[ i]).back.month, (p- gt; lector[i]).back.day);

printf("\n\tHoy es d-d-d", año, mes, día

printf("\n\n); \tAsí que has salido del día de pago");

printf("\n\tTienes que pagar 2,1f yuanes.", 0,1 *Pagar);

}

(p->;Lector [I]). num[0]= '\0';

p->;num actual;

printf("\n\tHas devuelto este libro.");

}

}

}

else printf(" \ n \ t¿Quieres devolver un libro que no existe? ");

}

Donghua()

{ int Graphdriver = VGA

int Graphmode = VGAHI

int i, j;

registerbgidriver(EGA VGA _ driver);

init graph( amp; controlador de gráficos amp; modo gráfico, "";

clr SCR();

for(I = 0; ilt=150; i =5)

{ establecer color(I);

fondo de texto( rojo

settextstyle(0, 0, 2);

outtextxy(100, i 140, "sistema de gestión de biblioteca");

Retraso (1000000);

clr SCR();

}

setcolor(rojo);

outtextxy(50, 200, " Cargando");

Retraso(10000000000);

outtextxy(50, 200, "Cargando.

");

Retraso (10000000000);

outtextxy (50, 200, "Cargando..");

Retraso (10000000000);

outtextxy(50, 200, "Cargando...");

Retraso (10000000000);

outtextxy(50, 200, "Cargando...") ; Cargando...");

Retraso(10000000000);

outtextxy(50, 200, "Cargando...");

Tiempo de retraso (10000000000);

outtextxy(50, 200, "Cargando...");

Retraso(10000000000);

outtextxy(50, 200, "Cargando...");

Retraso (10000000000);

outtextxy(50, 200, "Cargando...");

Retraso. (10000000000);

outtextxy(50, 200, "Cargando...");

Retraso (10000000000

outtextxy (50, 200, "Cargando...");

Retraso (10000000000);

outtextxy (50, 200, "Cargando...");

outtextxy( 50, 200, "Cargando...");

outtextxy(50, 200, "Cargando...");

p>

Retraso(10000000000);

for(I = 0; ilt=10;i)

Retraso(10000000000);

clr SCR();

}

Menú de caracteres (no válido)

{

clr SCR();

Ventana (1, 1, 80, 25);

modo de texto (mono);

fondo de texto (negro);

color de texto( 5);

printf(" \ n \ t * * * * * * * * * * * * * * * * * * * * * * * * *);

printf("\n\t *****Bienvenido a la gestión de la biblioteca sistema* * * * *);

printf(" \ n \t * * * * * * * * * * * * * * * * * * * * * * * *);

printf(" \ n \ t * * * * * * * * * * * * * * * * * * * * * * * *);

printf("\n \ t *1. Añadir un libro*);

printf(" \ n \ t * * * * * * * * * * * * * * * * * * * * * * * * *);

printf("\n\t *2. Eliminar un libro* ";

printf(" \ n \ t * * * * * * * * * * * * * * * * * * * * * * * * *);

printf("\n\t *3.

Buscar un libro*);

printf(" \ n \ t * * * * * * * * * * * * * * * * * * * * * * * *);

printf("\n\t *4. Pedir prestado libros*";

printf(" \ n \ t * * * * * * * * * * * * * * * * * * * * * * * * *);

printf("\n\t *5.

"Devuelve el libro*";

printf(" \ n \ t * * * * * * * * * * * * * * * * * * * * * * * *);

printf(" \ n \ t * 0 . salir * ");

printf(" \ n \ t * * * * * * * * * * * * * * * * * * * * * * *);

printf("\n\tPor favor seleccione: ");

Devuelve getch();

}

Donghua Oriental

{ int graphdriver = VGA

int graphmode = VGAHI

int i, j;

char c;

registerbgidriver(EGA VGA_driver);

init graph( amp; controlador de gráficos amp; graphmode, "";

/* * * * * * * * * * * * * Shi Fu Fang Bo Dong Hua? ****************/

printf: { set color(RED);

settextstyle(3, 0, 5);

outtextxy(100, 30, "¿Fang Bo Donghua?");

outtextxy(150, 80, "Sí"); ) ;

outtextxy(300, 80, "No");

c = getch();

if(c=='Y'|| c =='y ')

{Donghua();

menú();

}

Otros

if(c=='N'||c=='n ')

menu();

Otros

{setcolor(verde

settextstyle(3, 0, 8);

outtextxy(200, 240, "¡Error!"); /p>

clr SCR();

ir a printf

}

}

/***** * ********************************/

}

anular principal ()

{

char c, t;

int x;

int k, bandera, p = 1; p>

estructura TreeNode * bth = NULL

Bofang Donghua();

mientras(1)

{

c = menú();

parche(c);

getch();

Cambiar(c)

{

caso '1': BTH = mbinsert(BTH);

Pausa;

Caso '2': BTH = MB del(BTH);

Pausa;

Caso "3": nodo de salida (BTH);

Pausa;

Caso "4": Préstamo (BTH);

p>

Pausa;

Caso '5': Retorno (BTH);

Break;

Caso "0": clrscr();

printf("\n\t¿Quieres volver? (s/n)");

t = getch();

if(t = = ' Y ' | | t = = ' Y ')salir(0);

Pausa;

predeterminado: break;

}

printf("\n\tPresione cualquier tecla para ingresar al menú principal...");

obtener( );

}

}