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

6edca9c772179893841bb1c4cda74bfc #42

Open
wants to merge 3 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
18 changes: 18 additions & 0 deletions Banco.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "Banco.hpp"
#include "ContaBancaria.hpp"

void Banco::adicionarConta(ContaBancaria* conta) {
contas.push_back(conta);
}

void Banco::exibirTodasContas() {
for (ContaBancaria* conta : contas) {
std::cout << "Saldo da conta de " << conta->getTitular() << ": R$" << conta->getSaldo() << "\n";
}
}

Banco::~Banco() {
for (ContaBancaria* conta : contas) {
delete conta;
}
}
20 changes: 6 additions & 14 deletions Banco.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,13 @@
#include <vector>
#include "ContaBancaria.hpp"

using namespace std;

class Banco {
public:
void adicionarConta(ContaBancaria* conta) {
contas.push_back(conta);
}

void exibir_todas_contas() {
for (ContaBancaria* conta : contas) {
std::cout << "Saldo da conta de " << conta->titular << ": R$" << conta->saldo << "\n";
}
}

private:
std::vector<ContaBancaria*> contas;
public:
void adicionarConta(ContaBancaria* conta);
void exibirTodasContas();
~Banco();
};

#endif
#endif
30 changes: 30 additions & 0 deletions ContaBancaria.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "ContaBancaria.hpp"
#include <string>

ContaBancaria::ContaBancaria(std::string titular, double saldo) : titular(titular), saldo(saldo) {}

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

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

std::string ContaBancaria::getTitular() {
return titular;
}

double ContaBancaria::getSaldo() {
return saldo;
}
27 changes: 7 additions & 20 deletions ContaBancaria.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,15 @@
#include <vector>

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

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


protected:
std::string titular;
double saldo;
public:
ContaBancaria(std::string titular, double saldo);
void depositar(double valor);
void sacar(double valor);
std::string getTitular();
double getSaldo();
};

#endif
16 changes: 16 additions & 0 deletions ContaCorrente.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "ContaCorrente.hpp"
#include "ContaBancaria.hpp"
#include <string>

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

void ContaCorrente::usarChequeEspecial(double valor) {
double valorTotal = saldo + limiteChequeEspecial;
if (valor > 0 && valor <= valorTotal) {
saldo -= valor;
std::cout << "Uso de cheque especial de R$" << valor << " efetuado com sucesso.\n";
} else {
std::cout << "Uso de cheque especial inválido. Verifique o valor ou limite.\n";
}
}
20 changes: 7 additions & 13 deletions ContaCorrente.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
#ifndef CONTA_CORRENTE_H
#define CONTA_CORRENTE_H

#include <string>
#include <iostream>
#include "ContaBancaria.hpp"

class conta_corrente : public ContaBancaria {
public:
void usarChequeEspecial(double valor) {
double valorTotal = saldo + limiteChequeEspecial;
if (valor > 0 && valor <= valorTotal) {
saldo -= valor;
std::cout << "Uso de cheque especial de R$" << valor << " efetuado com sucesso.\n";
} else {
std::cout << "Uso de cheque especial inválido. Verifique o valor ou limite.\n";
}
}

class ContaCorrente : public ContaBancaria {
private:
double limiteChequeEspecial;
public:
ContaCorrente(std::string titular, double saldo, double limiteChequeEspecial);
void usarChequeEspecial(double valor);
};


#endif
#endif
12 changes: 12 additions & 0 deletions ContaPoupanca.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "ContaPoupanca.hpp"
#include "ContaBancaria.hpp"
#include <string>

ContaPoupanca::ContaPoupanca(std::string titular, double saldo, double taxaJuros) :
ContaBancaria(titular, saldo), taxaJuros(taxaJuros) {}

void ContaPoupanca::calcularJuros() {
double juros = saldo * taxaJuros / 100;
saldo += juros;
std::cout << "Juros de R$" << juros << " calculados e adicionados à conta.\n";
}
16 changes: 7 additions & 9 deletions ContaPoupanca.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
#include <iostream>
#include "ContaBancaria.hpp"

class conta_poupanca : public ContaBancaria {
public:
void calcularJuros() {
double juros = saldo * taxaJuros / 100;
saldo += juros;
std::cout << "Juros de R$" << juros << " calculados e adicionados à conta.\n";
}
double taxaJuros;
class ContaPoupanca : public ContaBancaria {
private:
double taxaJuros;
public:
ContaPoupanca(std::string titular, double saldo, double taxaJuros);
void calcularJuros();
};


#endif
#endif
37 changes: 9 additions & 28 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,43 @@
int main() {
Banco meuBanco;

conta_corrente* conta1 = new conta_corrente();
conta1->titular = "Joao";
conta1->saldo = 1500;
conta1->limiteChequeEspecial = 200;

conta_poupanca* conta2 = new conta_poupanca();
conta2->titular = "Maria";
conta2->saldo = 1000;
conta2->taxaJuros = 2.0;

conta_poupanca* conta3 = new conta_poupanca();
conta3->titular = "Luiz";
conta3->saldo = 3000;
conta3->taxaJuros = 1.5;

conta_poupanca* conta4 = new conta_poupanca();
conta4->titular = "Lara";
conta4->saldo = 2000;
conta4->taxaJuros = 2.5;

conta_corrente* conta5 = new conta_corrente();
conta5->titular = "Luisa";
conta5->saldo = 5000;
conta5->limiteChequeEspecial = 300;
ContaCorrente* conta1 = new ContaCorrente("Joao", 1500, 200);
ContaPoupanca* conta2 = new ContaPoupanca("Maria", 1000, 2.0);
ContaPoupanca* conta3 = new ContaPoupanca("Luiz", 3000, 1.5);
ContaPoupanca* conta4 = new ContaPoupanca("Lara", 2000, 2.5);
ContaCorrente* conta5 = new ContaCorrente("Luisa", 5000, 300);

meuBanco.adicionarConta(conta1);
meuBanco.adicionarConta(conta2);
meuBanco.adicionarConta(conta3);
meuBanco.adicionarConta(conta4);
meuBanco.adicionarConta(conta5);

meuBanco.exibir_todas_contas();
meuBanco.exibirTodasContas();

conta1->depositar(500);
conta2->sacar(200);
conta3->sacar(100);
conta4->depositar(-1);
conta5->sacar(5001);

meuBanco.exibir_todas_contas();
meuBanco.exibirTodasContas();

conta1->sacar(500);
conta2->depositar(200);
conta3->depositar(100);
conta4->sacar(300);
conta5->depositar(50);

meuBanco.exibir_todas_contas();
meuBanco.exibirTodasContas();

conta1->usarChequeEspecial(500);
conta2->calcularJuros();
conta3->calcularJuros();
conta4->calcularJuros();
conta5->usarChequeEspecial(50);

meuBanco.exibir_todas_contas();
meuBanco.exibirTodasContas();

return 0;
}