From 5000cb941f853e7cc006163f080b33a1f8439021 Mon Sep 17 00:00:00 2001 From: Muriki <mgy20@inf.ufpr.br> Date: Fri, 6 Dec 2024 20:20:34 -0300 Subject: [PATCH] Usuario fix --- main.cpp | 7 +++++-- sources/ControladorUsuarios.cpp | 4 ++-- sources/ControladorUsuarios.hpp | 4 ++-- sources/Emprestimo.cpp | 2 +- sources/Emprestimo.hpp | 4 ++-- sources/Usuario.cpp | 6 +++--- sources/Usuario.hpp | 4 ++-- tdd/obras-test.cpp | 2 +- 8 files changed, 18 insertions(+), 15 deletions(-) diff --git a/main.cpp b/main.cpp index 7d830a6..155221d 100644 --- a/main.cpp +++ b/main.cpp @@ -38,13 +38,16 @@ int main(){ Biblioteca bib; // Cria Usuarios - ControladorUsuarios contUsuarios = bib.getContUsuarios(); - cout << "> Criando Usuarios" << endl; + ControladorUsuarios contUsuarios = bib.getContUsuarios(); contUsuarios.adicionarUsuario("Muriki", "12345", "Casa", "9999", "murikigy@gmail.com"); contUsuarios.adicionarUsuario("Nico", "54321", "Apartamento", "8888", "nico@gmail.com"); contUsuarios.adicionarUsuario("Marcus", "12345", "Casa", "9988", "marcus@gmail.com"); + // Cria Obras + cout << ""; + + // Interation Loop int option = START; while (option != FINISH) { diff --git a/sources/ControladorUsuarios.cpp b/sources/ControladorUsuarios.cpp index e132493..15b2220 100644 --- a/sources/ControladorUsuarios.cpp +++ b/sources/ControladorUsuarios.cpp @@ -38,7 +38,7 @@ bool ControladorUsuarios::adicionarUsuario(string nome, string CPF, string ender } -int ControladorUsuarios::registrarEmprestimo(string CPF, DescricaoObra descricao){ +int ControladorUsuarios::registrarEmprestimo(string CPF, DescricaoObra& descricao){ // Search for user auto it = find_if(usuarios.begin(), usuarios.end(), [CPF](Usuario& u) { @@ -60,7 +60,7 @@ int ControladorUsuarios::registrarEmprestimo(string CPF, DescricaoObra descricao } -int ControladorUsuarios::retornarEmprestimo(string CPF, DescricaoObra descricao){ +int ControladorUsuarios::retornarEmprestimo(string CPF, DescricaoObra& descricao){ // Search for user auto it = find_if(usuarios.begin(), usuarios.end(), [CPF](Usuario& u) { diff --git a/sources/ControladorUsuarios.hpp b/sources/ControladorUsuarios.hpp index 72f064b..f471534 100644 --- a/sources/ControladorUsuarios.hpp +++ b/sources/ControladorUsuarios.hpp @@ -20,8 +20,8 @@ class ControladorUsuarios { // Methods bool adicionarUsuario(string nome, string CPF, string endereco, string telefone, string email); - int registrarEmprestimo(string CPF, DescricaoObra descricao); - int retornarEmprestimo(string CPF, DescricaoObra descricao); + int registrarEmprestimo(string CPF, DescricaoObra& descricao); + int retornarEmprestimo(string CPF, DescricaoObra& descricao); int recuperarMultas(string CPF); bool registrarMultaPaga(string CPF, int valor); diff --git a/sources/Emprestimo.cpp b/sources/Emprestimo.cpp index b638d2c..6ba6c55 100644 --- a/sources/Emprestimo.cpp +++ b/sources/Emprestimo.cpp @@ -6,7 +6,7 @@ using namespace std; // Constructor -Emprestimo::Emprestimo(int data, DescricaoObra descricao) +Emprestimo::Emprestimo(int data, DescricaoObra& descricao) : dataEmprestimo(data), descricao(descricao) {} void Emprestimo::mostraDetalhes() const { diff --git a/sources/Emprestimo.hpp b/sources/Emprestimo.hpp index b8ce99c..f2185e4 100644 --- a/sources/Emprestimo.hpp +++ b/sources/Emprestimo.hpp @@ -6,12 +6,12 @@ class Emprestimo { private: int dataEmprestimo; - DescricaoObra descricao; + DescricaoObra &descricao; public: // Constructor Emprestimo(); - Emprestimo(int data, DescricaoObra descricao); + Emprestimo(int data, DescricaoObra& descricao); void mostraDetalhes() const; // Methods diff --git a/sources/Usuario.cpp b/sources/Usuario.cpp index e5cb15b..5ee7565 100644 --- a/sources/Usuario.cpp +++ b/sources/Usuario.cpp @@ -25,7 +25,7 @@ void Usuario::mostrarDetalhes() const { // Methods -bool Usuario::emprestar(DescricaoObra descricao){ +bool Usuario::emprestar(DescricaoObra& descricao){ // Check number of Borrowed works if (this->emprestimos->size() >= 3) { @@ -44,7 +44,7 @@ bool Usuario::emprestar(DescricaoObra descricao){ return true; } -bool Usuario::devolver(DescricaoObra descricao){ +bool Usuario::devolver(DescricaoObra& descricao){ // Search for Borrowed work auto emp_it = find_if(this->emprestimos->begin(), this->emprestimos->end(), [&descricao](Emprestimo& emp){ @@ -59,7 +59,7 @@ bool Usuario::devolver(DescricaoObra descricao){ emp_it->removeEmprestimo(); // Remove work - this->emprestimos->erase(emp_it); + //this->emprestimos->erase(emp_it); return true; } diff --git a/sources/Usuario.hpp b/sources/Usuario.hpp index f76d9bc..8447299 100644 --- a/sources/Usuario.hpp +++ b/sources/Usuario.hpp @@ -27,8 +27,8 @@ class Usuario { void mostrarDetalhes() const; // Methods - bool emprestar(DescricaoObra descricao); - bool devolver(DescricaoObra descricao); + bool emprestar(DescricaoObra& descricao); + bool devolver(DescricaoObra& descricao); int atualizarMulta(int valor); // Increase fee string getCPF(); int getMulta(); diff --git a/tdd/obras-test.cpp b/tdd/obras-test.cpp index b5feaf3..5c7c894 100644 --- a/tdd/obras-test.cpp +++ b/tdd/obras-test.cpp @@ -10,7 +10,7 @@ TEST_CASE("Adicionar Obras") { cout << "> Instanciando o Controlador de Obras" << endl; ControladorObras contObras; - cout << "=> Instanciando um Periodico: " << endl; + cout << "==> Instanciando um Periodico: " << endl; Periodico p("Revista de Ciência", 2023, 5, 3); p.mostrarDetalhes(); cout << endl; -- GitLab