Program Biblioteca ;
Type
Usuario = Record
Nome: String;
Endereco: String;
Telefone: String;
Cpf: String;
End;
Type
Livros = Record
matricula:integer;
Nome: String;
Autor: String;
Editora: String;
situacao:String;
myfile: text;
End;
Type
empresta_livro = record
nome_cliente: String;
cpf_cliente: String;
endereco_cliente: String;
telefone_cliente: String;
matricula_livro:integer;
nome_livro: String;
data_empresta_livro: String;
data_devolve_livro:String;
End;
var
vetor_usuario: array[1..100] of Usuario;
vetor_livros: array[1..100] of Livros;
vetor_empresta: array[1..100]of empresta_livro;
esc: char;
opcao, qtd_usuarios,qtd_livros,qtd_emprestimo,emprestimo: integer;
remover:boolean;
procedure Menu;
Begin
writeln('Sistema de Biblioteca 7.3.2');
writeln('Menu de opções:');
writeln('');
writeln('1. Cadastrar Livro:');
writeln('2. Cadastrar o Usuario:');
writeln('3. Listar Livro:');
writeln('4. Listar Usuario:');
writeln('5. Realizar empréstimo:');
writeln('6. Devolver Livro:');
writeln('7. Listar todos os Emprestimos:');
writeln('8. Pesquisar Livros:');
writeln('9. Pesquisar Usuarios:');
writeln('10. Alterar dados do Livro:');
writeln('11. Alterar dados do Usuario:');
writeln('12. Exluir Livro:');
writeln('13. Excluir Usuario:');
writeln('14. Mostrar Livros na Biblioteca');
writeln('15. Mostrar Livros Emprestados');
writeln('00. Sair');
end;
Procedure Cadastrar_Livro;
var
i,quant:integer;
Begin
esc := 'S' ;
while ((esc = 'S') or (esc = 's'))do
begin
qtd_livros:= qtd_livros + 1;
writeln();
Writeln('Digite a Matricula: ');
readln(vetor_livros[qtd_livros].matricula);
Writeln('Digite o nome do Livro: ');
readln(vetor_livros[qtd_livros].Nome);
Writeln('Digite o Autor: ');
readln(vetor_livros[qtd_livros].Autor);
Writeln('Digite a Editora: ');
readln(vetor_livros[qtd_livros].Editora);
vetor_livros[qtd_livros].situacao := '1';
writeln('');
writeln('Matricula realizada com sucesso!!');
writeln('Deseja continuar cadastrando?(S - SIM / N - NÃO) ');
readln(esc);
end;
End;
Procedure Cadastrar_Usuario;
Begin
esc := 'S' ;
while ((esc = 'S') or (esc = 's'))do
begin
qtd_usuarios := qtd_usuarios +1;
Writeln('Digite o nome do Usuario: ');
readln(vetor_usuario[qtd_usuarios].Nome);
Writeln('Digite o endereço do Usuario: ');
readln(vetor_usuario[qtd_usuarios].Endereco);
Writeln('Digite o Telefone do Usuario: ');
readln(vetor_usuario[qtd_usuarios].Telefone);
Writeln('Digite o Cpf do Usuario: ');
readln(vetor_usuario[qtd_usuarios].Cpf);
writeln('Deseja continuar cadastrando?(S - SIM / N - NÃO) ');
readln(esc);
end;
End;
Procedure Listar_Livro;
var
i:integer;
Begin
for i:=1 to qtd_livros do
begin
writeln('Matricula do Livro:',vetor_livros[i].matricula);
writeln('Nome: ',vetor_livros[i].Nome);
writeln('Autor: ',vetor_livros[i].Autor);
writeln('Editora: ',vetor_livros[i].Editora);
if(vetor_livros[i].situacao = '1')then
begin
writeln('Situação: Na Biblioteca');
end
else
begin
writeln('Situação: Emprestado');
end;
end;
End;
Procedure Listar_Usuario;
var
i:integer;
Begin
for i:=1 to qtd_usuarios do
begin
writeln('Nome: ',vetor_usuario[i].Nome);
writeln('Endereço: ',vetor_usuario[i].endereco);
writeln('Telefone: ',vetor_usuario[i].telefone);
writeln('Cpf:',vetor_usuario[i].cpf);
end;
End;
function Pesquisar(matriculaAPesquisar : integer) : integer;
var
result:integer;
i : integer;
begin
Pesquisar := -1;
for i:= 1 to qtd_livros do begin
if (matriculaAPesquisar = vetor_livros[i].matricula) then begin
Result := i;
break;
end;
end;
end;
Procedure Realizar_Emprestimo;
var
pesq:String;
pesq_n:integer;
i,cont,conta:integer;
indiciLivro:integer;
achou:boolean;
encontra:boolean;
esc:integer;
indicibusca:integer;
Begin
Writeln('Digite o cpf do Usuario:');
readln(pesq);
writeln('Resultado da Busca:');
for i:=1 to qtd_usuarios do
begin
if(vetor_usuario[i].cpf = pesq)then
begin
achou:=true;
indicibusca:=i;
end;
end;
if achou = true then
begin
writeln('Usurio encontrado! Fazer Emprestimo:');
emprestimo:= emprestimo + 1;
Writeln('Digite o nome do Cliente: ');
readln(vetor_empresta[emprestimo].nome_cliente);
Writeln('Digite o Cpf do Cliente: ');
readln(vetor_empresta[emprestimo].cpf_cliente);
Writeln('Digite o endereço do Cliente: ');
readln(vetor_empresta[emprestimo].endereco_cliente);
Writeln('Digite o Telefone do Cliente ');
readln(vetor_empresta[emprestimo].telefone_cliente);
end
else
begin
writeln('Nenhum usuario encontrado com esse CPF!!!');
end;
writeln('Pesquisa livros pela matricula:');
readln(pesq_n);
indiciLivro := Pesquisar(pesq_n);
if (indiciLivro > -1) then
begin
writeln('Livro com matricula ',vetor_Livros[indiciLivro].matricula,' encontrado!');
writeln('');
writeln('Digite a matricula do Livro a ser emprestado:');
readln(vetor_empresta[emprestimo].matricula_livro);
writeln('Digite o nome do Livro:');
readln(vetor_empresta[emprestimo].nome_livro);
writeln('Digite a data do emprestimo:');
readln(vetor_empresta[emprestimo].data_empresta_livro);
vetor_livros[i].situacao := '2';
writeln('O livro ',vetor_empresta[emprestimo].nome_livro,' foi emprestado a ',vetor_empresta[emprestimo].nome_cliente,' com sucesso*!');
writeln('');
end
else
writeln('Livro não encontrado');
End;
//devolve o livro
Procedure Devolver_Livro;
var
i,contaa,pesq_mat: integer;
Begin
writeln('Digite a matricula do livro:');
readln(pesq_mat);
for i:=1 to emprestimo do
begin
if(vetor_empresta[i].matricula_livro = pesq_mat)then
begin
writeln('Digite a data da devolução:');
readln(vetor_empresta[emprestimo].data_devolve_livro);
writeln('A devolução do livro ',vetor_livros[i].nome, ' foi realizada com sucesso**!');
vetor_livros[qtd_livros].situacao := '1';
end;
end;
End;
//
Procedure Listar_Emprestimo;
var
i:integer;
Begin
for i:=1 to emprestimo do
begin
writeln('Matricula do livro:',vetor_empresta[i].matricula_livro);
writeln('Nome do Livro: ',vetor_empresta[i].nome_livro);
writeln('Nome do Cliente: ',vetor_empresta[i].nome_cliente);
writeln('Endereço do Cliente: ',vetor_empresta[i].endereco_cliente);
writeln('Telefone do Cliente: ',vetor_empresta[i].telefone_cliente);
writeln('CPF do Cliente: ',vetor_empresta[i].cpf_cliente);
writeln('Data que o livro foi emprestado: ',vetor_empresta[i].data_empresta_livro);
writeln('Data que o livro foi devolvido: ',vetor_empresta[i].data_devolve_livro);
end;
End;
//Pesquisa o livro
Procedure Pesquisar_Livros;
var
pesq:String;
pesq_n:integer;
i,cont:integer;
indicibusca:integer;
achou:boolean;
esc:integer;
Begin
writeln('OPÇÕES : 1-Pesquisar pelo nome/2-Pesquisar pela matricula');
readln(esc);
if(esc = 1)then
begin
cont:=0;
Writeln('Digite o nome do livro para pesquisa-lo:');
readln(pesq);
writeln('Resultado da Busca:');
for i:=1 to qtd_livros do
begin
if(vetor_livros[i].nome = pesq)then
begin
achou:=true;
indicibusca:=i;
end;
end;
if achou=true then
begin
writeln('Matricula do Livro:',vetor_livros[indicibusca].matricula);
writeln('Nome: ',vetor_livros[indicibusca].Nome);
writeln('Autor: ',vetor_livros[indicibusca].Autor);
writeln('Editora: ',vetor_livros[indicibusca].Editora);
if(vetor_livros[i].situacao = '1')then
begin
writeln('Situação: Na Biblioteca');
end
else
begin
writeln('Situação: Emprestado');
end;
cont:= cont+1;
end;
if(cont = 1)then
writeln('Quantidade encontrada:',cont)
else
writeln('Nenhum livro com esse nome foi encontrado');
end
else
if(esc = 2)then
begin
cont:=0;
Writeln('Digite a matricula do livro para pesquisa-lo:');
readln(pesq_n);
writeln('Resultado da Busca:');
for i:=1 to qtd_livros do
begin
if(vetor_livros[i].matricula = pesq_n)then
begin
achou:=true;
indicibusca:=i;
end;
end;
if achou=true then
begin
writeln('Matricula do Livro:',vetor_livros[indicibusca].matricula);
writeln('Nome: ',vetor_livros[indicibusca].Nome);
writeln('Autor: ',vetor_livros[indicibusca].Autor);
writeln('Editora: ',vetor_livros[indicibusca].Editora);
if(vetor_livros[i].situacao = '1')then
begin
writeln('Situação: Na Biblioteca');
end
else
begin
writeln('Situação: Emprestado');
end;
cont:= cont+1;
end;
if(cont = 1)then
writeln('Quantidade encontrada:',cont)
else
writeln('Nenhum livro com esse nome foi encontrado');
end;
End;
//Altera o livro
Procedure Alterar_Livros;
var
pesq:String;
pesq_n:integer;
i,cont:integer;
Begin
cont:=0;
Writeln('Digite o nome do livro para pesquisa-lo:');
readln(pesq);
writeln('Resultado da Busca:');
for i:=1 to qtd_livros do
begin
if(vetor_livros[i].nome = pesq)then
begin
Writeln('Digite a Matricula: ');
readln(vetor_livros[qtd_livros].matricula);
Writeln('Digite o nome do Livro: ');
readln(vetor_livros[qtd_livros].Nome);
Writeln('Digite o Autor: ');
readln(vetor_livros[qtd_livros].Autor);
Writeln('Digite a Editora: ');
readln(vetor_livros[qtd_livros].Editora);
cont:= cont+1;
end;
end;
if(cont = 0)then
writeln('Nenhum livro com esse nome foi encontrado')
else
writeln('Quantidade encontrada:',cont);
End;
Procedure Excluir_Livros;
var
liv:integer;
i:integer;
Begin
writeln('Digite o livro a ser removido:');
readln(liv);
for i:= 1 to qtd_livros do
begin
if(vetor_Livros[i].matricula = liv)then
begin
writeln('O livro ',vetor_livros[i].matricula,' foi excluido com sucesso!!');
qtd_livros:= qtd_livros - 1;
end;
end;
End;
Procedure Pesquisar_Usuarios;
var
pesq:String;
pesq_n:integer;
i,cont,indicibusca:integer;
achou:boolean;
Begin
cont:=0;
Writeln('Digite o CPF do Usuario:');
readln(pesq);
writeln('Resultado da Busca:');
for i:=1 to qtd_usuarios do
begin
if(vetor_usuario[i].cpf = pesq)then
begin
achou:=true;
indicibusca:=i;
end;
end;
if achou=true then
begin
writeln('Nome: ',vetor_usuario[indicibusca].Nome);
writeln('Endereço: ',vetor_usuario[indicibusca].endereco);
writeln('Telefone: ',vetor_usuario[indicibusca].telefone);
writeln('Cpf:',vetor_usuario[indicibusca].cpf);
end
else
writeln('Nenhum usuario com esse CPF encontrado!');
End;
Procedure Alterar_Usuarios;
var
pesq:String;
pesq_cpf:integer;
i,cont:integer;
Begin
cont:=0;
Writeln('Pesquise pelo nome ou CPF ');
readln(pesq);
writeln('Resultado da Busca:');
for i:=1 to qtd_usuarios do
begin
if((vetor_usuario[i].nome = pesq) or (vetor_usuario[i].cpf = pesq))then
begin
Writeln('Digite o nome do Usuario: ');
readln(vetor_usuario[qtd_usuarios].Nome);
Writeln('Digite o endereço do Usuario: ');
readln(vetor_usuario[qtd_usuarios].Endereco);
Writeln('Digite o Telefone do Usuario: ');
readln(vetor_usuario[qtd_usuarios].Telefone);
Writeln('Digite o Cpf do Usuario: ');
readln(vetor_usuario[qtd_usuarios].Cpf);
cont:= cont+1;
end;
if(cont = 0)then
writeln('Nenhum usuario encontrado!')
else
writeln('Quantidade encontrada:',cont);
End;
end;
Procedure Excluir_Usuarios;
var
liv:string;
i:integer;
Begin
writeln('Digite o livro a ser removido:');
readln(liv);
for i:= 1 to qtd_usuarios do
begin
if(vetor_usuario[i].cpf = liv)then
begin
writeln('O usuario de CPF ',vetor_usuario[i].cpf,' foi excluido com sucesso!!');
qtd_usuarios:= qtd_usuarios - 1;
end;
end;
End;
procedure Livros_biblioteca;
var
i:integer;
Begin
for i:=1 to qtd_livros do
begin
if(vetor_livros[i].situacao = '1')then
begin
writeln('Matricula do Livro:',vetor_livros[i].matricula);
writeln('Nome: ',vetor_livros[i].Nome);
writeln('Autor: ',vetor_livros[i].Autor);
writeln('Editora: ',vetor_livros[i].Editora);
writeln('Situação: Na Biblioteca');
end
else
begin
writeln('Sem livros na biblioteca!');
end;
end;
end;
procedure livros_emprestados;
var
i:integer;
Begin
for i:=1 to qtd_livros do
begin
if(vetor_livros[i].situacao = '2')then
begin
writeln('Matricula do Livro:',vetor_livros[i].matricula);
writeln('Nome: ',vetor_livros[i].Nome);
writeln('Autor: ',vetor_livros[i].Autor);
writeln('Editora: ',vetor_livros[i].Editora);
writeln('Situação: Emprestado');
end
else
begin
writeln('Não a livros na biblioteca!!');
end;
end;
End;
Procedure Sair;
Begin
Writeln('Programa encerrado com sucesso. Até a Proxima!');
End;
Procedure Selecine_opcao(Opc: integer);
Begin
Case opc of
1: Cadastrar_Livro;
2: Cadastrar_Usuario;
3: Listar_Livro;
4: Listar_Usuario;
5: Realizar_emprestimo;
6: Devolver_Livro;
7: Listar_Emprestimo;
8: Pesquisar_Livros;
9: Pesquisar_Usuarios;
10:Alterar_Livros;
11:Alterar_Usuarios;
12:Excluir_Livros;
13:Excluir_Usuarios;
14:Livros_biblioteca;
15:Livros_Emprestados;
00: Sair;
End;
End;
Begin
opcao:= 1;
while (opcao<>00) do
Begin
Menu;
Write('Escolha uma opção: ');
Readln(opcao);
if(opcao <= 15) then
begin
Selecine_opcao(opcao);
Writeln('');
end
else
begin
writeln('');
writeln('**OPÇÃO INVALIDA!** / Escolha um número da opção:');
writeln('');
end;
end;
End.