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

745e1e5deb2a6f9505b3013177d69d4e #33

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

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


void Banco::exibir_todas_contas() {
for (ContaBancaria* conta : contas) {
//Change chama o metodo para imprimir
conta->printInfo();
}
}
21 changes: 9 additions & 12 deletions Banco.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@
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";
}
}

std::vector<ContaBancaria*> contas;

private:
std::vector<ContaBancaria*> contas;

public:
void adicionarConta(ContaBancaria* conta);

void exibir_todas_contas();

};

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

ContaBancaria::ContaBancaria(std::string titular, double saldo){
this->titular = titular;
this->saldo = saldo;
}

double ContaBancaria::getSaldo(){
return saldo;
}

void ContaBancaria::setSaldo(double valor){
saldo += valor;
}

void ContaBancaria::printInfo(){
std::cout << "Saldo da conta de " << titular << ": R$" << saldo << "\n";
}


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";
}
}
43 changes: 21 additions & 22 deletions ContaBancaria.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@
#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";
}
}


std::string titular;
double saldo;

//Change: deixar os atributos privados
private:
std::string titular;
double saldo;

public:

//Change: Metodo Construtor
ContaBancaria(std::string titular, double saldo);

//Change Metodos para retornar e atualizar o valor
double getSaldo();
void setSaldo(double valor);

// Change: Metodo para imprimir
virtual void printInfo();

void depositar(double valor);
void sacar(double valor);

};

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


void ContaCorrente::usarChequeEspecial(double valor) {
double valorTotal = getSaldo() + limiteChequeEspecial;
if (valor > 0 && valor <= valorTotal) {
setSaldo(-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";
}
}
22 changes: 10 additions & 12 deletions ContaCorrente.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
#define CONTA_CORRENTE_H

#include <iostream>
#include <string>
#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 {

//change: deixar o atributo privado
private:
double limiteChequeEspecial;

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

double limiteChequeEspecial;
};


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


void ContaPoupanca::calcularJuros(){
double juros = getSaldo() * taxaJuros / 100;
setSaldo(juros);
std::cout << "Juros de R$" << juros << " calculados e adicionados à conta.\n";
}
16 changes: 9 additions & 7 deletions ContaPoupanca.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
#define CONTA_POUPANCA_H

#include <iostream>
#include <string>
#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 {

//change: deixar o atributo privado
private:
double taxaJuros;

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


Expand Down
25 changes: 5 additions & 20 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,15 @@
int main() {
Banco meuBanco;

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

conta_poupanca* conta2 = new conta_poupanca();
conta2->titular = "Maria";
conta2->saldo = 1000;
conta2->taxaJuros = 2.0;
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
Binary file added vpl_exec
Binary file not shown.