Skip to content

Commit 34d4ae8

Browse files
committed
Added SavingsAccount
1 parent 86a7b8c commit 34d4ae8

8 files changed

+78
-6
lines changed

Homework3/Account.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Account::Account(const char iban[], int ownerId, double amount) : ownerId(ownerI
66
strcpy(this->iban, iban);
77
}
88

9+
/*
10+
void Account::setIban(const char newIban[]){
11+
strcpy(iban, newIban);
12+
}
13+
*/
14+
915
double Account::getBalance() const {
1016
return this->amount;
1117
}

Homework3/Account.h

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Account{
1010
virtual void display() const = 0;
1111

1212
double getBalance() const;
13+
//void setIban(const char []);
1314
protected:
1415
char iban[34];
1516
int ownerId;

Homework3/CurrentAccount.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include <iostream>
22
#include "CurrentAccount.h"
33

4+
CurrentAccount::CurrentAccount(const char iban[], int ownerId, double amount) : Account(iban, ownerId, amount) {
5+
}
6+
47
void CurrentAccount::deposit(double amountToDeposit){
58
this->amount+=amountToDeposit;
69
}

Homework3/CurrentAccount.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#pragma once
22
#include <iostream>
3-
#include "Account.h"
3+
#include "Account.cpp"
44

55
class CurrentAccount : public Account{
6+
public:
7+
CurrentAccount(const char [] = "unspecified", int = 0, double = 0);
8+
69
void deposit(double);
710
bool withdraw(double);
811
void display() const;

Homework3/Customer.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ Customer& Customer::operator=(const Customer& other){
2727
}
2828

2929
int Customer::getId() const{
30-
return id;
30+
return this->id;
3131
}
3232

3333
const char* Customer::getName() const{
34-
return name;
34+
return this->name;
3535
}
3636

3737
const char* Customer::getAddress() const{
38-
return address;
38+
return this->address;
3939
}
4040

4141
void Customer::display() const{
@@ -50,6 +50,6 @@ void Customer::copy(const Customer& other){
5050
}
5151

5252
void Customer::erase(){
53-
delete[] name;
54-
delete[] address;
53+
delete[] this->name;
54+
delete[] this->address;
5555
}

Homework3/SavingsAccount.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
#include "SavingsAccount.h"
3+
4+
SavingsAccount::SavingsAccount(const char iban[], int ownerId, double amount, double interestRate) : Account(iban, ownerId, amount), interestRate(interestRate) {
5+
}
6+
7+
void SavingsAccount::deposit(double amountToDeposit){
8+
this->amount+=amountToDeposit;
9+
}
10+
11+
bool SavingsAccount::withdraw(double amountToWithdraw){
12+
if(this->amount - amountToWithdraw < 0)
13+
return false;
14+
15+
this->amount-=amountToWithdraw;
16+
return true;
17+
}
18+
19+
void SavingsAccount::display() const{
20+
std::cout<<"This is an account of type savings account. It has IBAN: "<<this->iban<<"\nIt belong to a customer with id: "
21+
<<this->ownerId<<"\nIt has a current balance of "<<this->amount<<" eur.\n";
22+
}
23+
24+
double SavingsAccount::getInterestRate() const{
25+
return this->interestRate;
26+
}

Homework3/SavingsAccount.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
#include <iostream>
3+
#include "Account.cpp"
4+
5+
class SavingsAccount : public Account{
6+
public:
7+
SavingsAccount(const char [] = "unspecified", int = 0, double = 0, double = 0);
8+
9+
void deposit(double);
10+
bool withdraw(double);
11+
void display() const;
12+
13+
double getInterestRate() const;
14+
private:
15+
double interestRate;
16+
};

Homework3/main.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <iostream>
2+
#include "Account.cpp"
3+
#include "CurrentAccount.cpp"
4+
5+
int main() {
6+
/*
7+
CurrentAccount cur("gosho", 1, 2);
8+
CurrentAccount cur2(cur);
9+
cur2.display();
10+
cur.setIban("pesho");
11+
cur2.display();
12+
cur.display();
13+
*/
14+
15+
16+
return 0;
17+
}

0 commit comments

Comments
 (0)