Skip to content

Commit 4dd2c28

Browse files
committed
Added privileged accounts. Started work on Bank
1 parent 34d4ae8 commit 4dd2c28

File tree

9 files changed

+123
-4
lines changed

9 files changed

+123
-4
lines changed

Homework2/Exercise3/Bank.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <iostream>
2+
#include <cstring>
3+
#include "Bank.h"
4+
#define NUM_CUSTOMERS 10
5+
#define NUM_ACCOUNTS 10
6+
7+
Bank::Bank(const char* name, const char* address) :
8+
maxCustomers(NUM_CUSTOMERS), curCustomers(0), maxAccounts(NUM_ACCOUNTS), curAccounts(0) {
9+
this->name = new char[strlen(name) + 1];
10+
strcpy(this->name, name);
11+
this->address = new char[strlen(address) + 1];
12+
strcpy(this->address, address);
13+
this->customers = new Customer*[maxCustomers];
14+
this->accounts = new Account*[maxAccounts];
15+
}
16+
17+
Bank::Bank(const Bank& other){
18+
copy(other);
19+
}
20+
21+
Bank& Bank::operator=(const Bank& other){
22+
if(this!=&other){
23+
erase();
24+
copy(other);
25+
}
26+
27+
return *this;
28+
}
29+
30+
Bank::~Bank(){
31+
erase();
32+
}

Homework2/Exercise3/Bank.h

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <iostream>
2+
#include "Account.cpp"
3+
#include "Customer.cpp"
4+
5+
class Bank{
6+
public:
7+
Bank(const char* = "default_name", const char* = "James Baucher 5");
8+
Bank(const Bank&);
9+
Bank& operator=(const Bank&);
10+
~Bank();
11+
12+
const char* getName() const;
13+
const char* getAddress() const;
14+
15+
bool addCustomer(int, const char*, const char*);
16+
void listCustomers() const;
17+
bool deleteCustomer(int);
18+
19+
bool addAccount(const char*, const char [], int, double);
20+
bool deleteAcccount(const char []);
21+
void listAccounts() const;
22+
void listCustomerAccount(int) const;
23+
24+
bool transfer(const char[], const char[], double);
25+
void display() const;
26+
27+
private:
28+
char* name;
29+
char* address;
30+
Customer** customers;
31+
int maxCustomers;
32+
int curCustomers;
33+
Account** accounts;
34+
int maxAccounts;
35+
int curAccounts;
36+
37+
void resizeCustomers();
38+
void resizeAccounts();
39+
40+
void copy(const Bank&);
41+
void erase();
42+
};
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <iostream>
2+
#include "PrivilegeAccount.h"
3+
4+
PrivilegeAccount::PrivilegeAccount(const char iban[], int ownerId, double amount, double overdraft) : Account(iban, ownerId, amount), overdraft(overdraft){
5+
6+
}
7+
8+
PrivilegeAccount::deposit(double amountToDeposit){
9+
this->amount+=amountToDeposit;
10+
}
11+
12+
PrivilegeAccount::withdraw(double amountToWithdraw){
13+
if((this->amount + this->overdraft) - amountToWithdraw < 0)
14+
return false;
15+
16+
this->amount-=amountToWithdraw;
17+
return true;
18+
}
19+
20+
void PrivilegeAccount::display() const{
21+
std::cout<<"This is an account of type privilege account. It has IBAN: "<<this->iban<<"\nIt belong to a customer with id: "
22+
<<this->ownerId<<"\nIt has a current balance of "<<this->amount<<" eur.\n It has an allowed overdraft of "<<this->overdraft<<" eur.\n";
23+
}
24+
25+
double PrivilegeAccount::getOverdraft() const{
26+
return this->overdraft;
27+
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
#include <iostream>
3+
#include "Account.h"
4+
5+
class PrivilegeAccount{
6+
public:
7+
PrivilegeAccount(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 getOverdraft()const;
14+
private:
15+
double overdraft;
16+
};

Homework3/Account.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include <iostream>
3+
#define STANDARD_IBAN_LENGTH 34
34

45
class Account{
56
public:
@@ -12,7 +13,7 @@ class Account{
1213
double getBalance() const;
1314
//void setIban(const char []);
1415
protected:
15-
char iban[34];
16+
char iban[STANDARD_IBAN_LENGTH];
1617
int ownerId;
1718
double amount;
1819
};

Homework3/CurrentAccount.h

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

55
class CurrentAccount : public Account{
66
public:

Homework3/SavingsAccount.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ bool SavingsAccount::withdraw(double amountToWithdraw){
1818

1919
void SavingsAccount::display() const{
2020
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";
21+
<<this->ownerId<<"\nIt has a current balance of "<<this->amount<<" eur.\nIt has an yearly interest rate of "<<this->interestRate<<"%.\n";
2222
}
2323

2424
double SavingsAccount::getInterestRate() const{

Homework3/SavingsAccount.h

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

55
class SavingsAccount : public Account{
66
public:

Homework3/main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ int main() {
1111
cur2.display();
1212
cur.display();
1313
*/
14+
Account* acc = new Account[10];
1415

1516

1617
return 0;

0 commit comments

Comments
 (0)