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

291d1a96a2b543023beefe6f99b6f249 #17

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

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

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

Banco::~Banco(){
for(int i = 0; i < this->contas.size(); i++){
delete this->contas[i];
}
}
18 changes: 7 additions & 11 deletions Banco.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
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 exibir_todas_contas();
~Banco();
};

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

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

void ContaBancaria::depositar(double valor) {
if (valor > 0) {
this->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 <= this->saldo) {
this->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 this->titular;
}

double ContaBancaria::getSaldo(){
return this->saldo;
}
31 changes: 11 additions & 20 deletions ContaBancaria.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,19 @@
#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";
}
}
private:
std::string titular;

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";
}
}
public:
void depositar(double valor);
void sacar(double valor);
double getSaldo();
std::string getTitular();
//virtual bool transferir(double valor, char t);
ContaBancaria(std::string titular, double saldo);


std::string titular;
double saldo;
protected:
double saldo;
};

#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"

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

void ContaCorrente::usarChequeEspecial(double valor) {
double valorTotal = this->getSaldo() + this->limiteChequeEspecial;
if (valor > 0 && valor <= valorTotal) {
this->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";
}
}


19 changes: 7 additions & 12 deletions ContaCorrente.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@
#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;

double limiteChequeEspecial;
public:
void usarChequeEspecial(double valor);
ContaCorrente(std::string titular, double saldo, double limite);

};


Expand Down
10 changes: 10 additions & 0 deletions ContaPoupanca.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "ContaPoupanca.hpp"

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

void ContaPoupanca::calcularJuros() {
double juros = this->saldo * this->taxaJuros / 100;
this->saldo += juros;
std::cout << "Juros de R$" << juros << " calculados e adicionados à conta.\n";
}
13 changes: 6 additions & 7 deletions ContaPoupanca.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +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";
}
class ContaPoupanca : public ContaBancaria {
private:
double taxaJuros;

public:
void calcularJuros();
ContaPoupanca(std::string titular, double saldo, double taxaJuros);
};


Expand Down
28 changes: 7 additions & 21 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,16 @@
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;
ContaCorrente* conta1 = new ContaCorrente("Joao", 1500, 200);

ContaPoupanca* conta2 = new ContaPoupanca("Maria", 1000, 2.0);

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


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

conta_corrente* conta5 = new conta_corrente();
conta5->titular = "Luisa";
conta5->saldo = 5000;
conta5->limiteChequeEspecial = 300;
ContaCorrente* conta5 = new ContaCorrente("Luisa", 5000, 300);

meuBanco.adicionarConta(conta1);
meuBanco.adicionarConta(conta2);
Expand Down