Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bd8a6631a712ac68ac7d0a4fe2e9e451 #47

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions Banco.hpp

This file was deleted.

33 changes: 0 additions & 33 deletions ContaBancaria.hpp

This file was deleted.

23 changes: 0 additions & 23 deletions ContaCorrente.hpp

This file was deleted.

18 changes: 0 additions & 18 deletions ContaPoupanca.hpp

This file was deleted.

28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CXX = g++
CXXFLAGS = -std=c++11 -Wall -Wextra

SRC_DIR = src
INC_DIR = include
OBJ_DIR = obj
BIN_DIR = bin

SOURCES = $(wildcard $(SRC_DIR)/*.cpp)
OBJECTS = $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SOURCES))
EXECUTABLE = $(BIN_DIR)/main

INCLUDES = -I$(INC_DIR)

all: directories $(EXECUTABLE)

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

$(EXECUTABLE): $(OBJECTS)
$(CXX) $(CXXFLAGS) $(INCLUDES) $(OBJECTS) -o $@

directories:
mkdir -p $(OBJ_DIR)
mkdir -p $(BIN_DIR)

clean:
rm -rf $(OBJ_DIR) $(BIN_DIR)
17 changes: 17 additions & 0 deletions include/Banco.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef BANCO_HPP
#define BANCO_HPP

#include "ContaBancaria.hpp"

class Banco {
private:
std::vector<ContaBancaria*> _contas;
public:
Banco(const std::vector<ContaBancaria*>& contas);
~Banco();

void adicionar_conta(ContaBancaria* conta);
void exibir_todas_contas() const;
};

#endif // BANCO_HPP
24 changes: 24 additions & 0 deletions include/ContaBancaria.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef CONTA_BANCARIA_HPP
#define CONTA_BANCARIA_HPP

#include <iostream>
#include <vector>

class ContaBancaria {
private:
std::string _titular;
double _saldo;
public:
ContaBancaria(const std::string& titular, double saldo);
~ContaBancaria();

void depositar(double valor);
void sacar(double valor);
std::string get_titular() const;
void set_titular(std::string nome);
double get_saldo() const;
void set_saldo(double valor);
void alterar_saldo(double valor);
};

#endif // CONTA_BANCARIA_HPP
18 changes: 18 additions & 0 deletions include/ContaCorrente.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef CONTA_CORRENTE_HPP
#define CONTA_CORRENTE_HPP

#include "ContaBancaria.hpp"

class ContaCorrente : public ContaBancaria {
private:
double _limiteChequeEspecial;
public:
ContaCorrente(const std::string& titular, double saldo, double limiteChequeEspecial);
~ContaCorrente();

void usarChequeEspecial(double valor);
double get_limiteChequeEspecial() const;
void set_limiteChequeEspecial(double limiteChequeEspecial);
};

#endif // CONTA_CORRENTE_HPP
18 changes: 18 additions & 0 deletions include/ContaPoupanca.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef CONTA_POUPANCA_HPP
#define CONTA_POUPANCA_HPP

#include "ContaBancaria.hpp"

class ContaPoupanca : public ContaBancaria {
private:
double _taxaJuros;
public:
ContaPoupanca(const std::string& titular, double saldo, double taxaJuros);
~ContaPoupanca();

void calcularJuros();
double get_taxaJuros() const;
void set_taxaJuros(double taxaJuros);
};

#endif // CONTA_POUPANCA_HPP
71 changes: 0 additions & 71 deletions main.cpp

This file was deleted.

21 changes: 21 additions & 0 deletions src/Banco.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "../include/Banco.hpp"

Banco::Banco(const std::vector<ContaBancaria*>& contas)
: _contas {contas} {}

Banco::~Banco() {
for (ContaBancaria* conta : _contas) {
delete conta;
}
_contas.clear();
}

void Banco::adicionar_conta(ContaBancaria* conta) {
_contas.push_back(conta);
}

void Banco::exibir_todas_contas() const {
for (const ContaBancaria* conta : _contas) {
std::cout << "Saldo da conta de " << conta->get_titular() << ": R$" << conta->get_saldo() << std::endl;
}
}
44 changes: 44 additions & 0 deletions src/ContaBancaria.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "../include/ContaBancaria.hpp"

ContaBancaria::ContaBancaria(const std::string& titular, double saldo)
: _titular {titular}, _saldo {saldo} {}

ContaBancaria::~ContaBancaria() {}

void ContaBancaria::depositar(double valor) {
if (valor > 0) {
_saldo += valor;
std::cout << "Depósito de R$" << valor << " efetuado com sucesso." << std::endl;
} else {
std::cout << "Valor de depósito inválido." << std::endl;
}
};

void ContaBancaria::sacar(double valor) {
if (valor > 0 && valor <= _saldo) {
_saldo -= valor;
std::cout << "Saque de R$" << valor << " efetuado com sucesso." << std::endl;
} else {
std::cout << "Saque inválido. Verifique o valor ou saldo insuficiente." << std::endl;;
}
}

std::string ContaBancaria::get_titular() const {
return _titular;
}

void ContaBancaria::set_titular(std::string nome) {
_titular = nome;
}

double ContaBancaria::get_saldo() const {
return _saldo;
}

void ContaBancaria::set_saldo(double valor) {
_saldo = valor;
}

void ContaBancaria::alterar_saldo(double valor) {
_saldo += valor;
}
25 changes: 25 additions & 0 deletions src/ContaCorrente.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "../include/ContaCorrente.hpp"

ContaCorrente::ContaCorrente(const std::string& titular, double saldo, double limiteChequeEspecial)
: ContaBancaria {titular, saldo}, _limiteChequeEspecial {limiteChequeEspecial}{}

ContaCorrente::~ContaCorrente() {}

void ContaCorrente::usarChequeEspecial(double valor) {
double valorTotal = get_saldo() + _limiteChequeEspecial;

if (valor > 0 && valor <= valorTotal) {
alterar_saldo(-valor);
std::cout << "Uso de cheque especial de R$" << valor << " efetuado com sucesso." << std::endl;
} else {
std::cout << "Uso de cheque especial inválido. Verifique o valor ou limite." << std::endl;
}
}

double ContaCorrente::get_limiteChequeEspecial() const {
return _limiteChequeEspecial;
}

void ContaCorrente::set_limiteChequeEspecial(double limiteChequeEspecial) {
_limiteChequeEspecial = limiteChequeEspecial;
}
Loading