0% found this document useful (0 votes)
9 views

INFO231-Object Oriented Programming

The document describes an object-oriented banking application in C++. It defines classes for accounts (CurrentAccount and SavingsAccount) that inherit from an abstract Account class, transactions, and a banking application to manage accounts and process transfers and external transactions from Bank Z. The main function demonstrates adding a customer, transferring funds between accounts, and processing the transactions through Bank Z.

Uploaded by

Aiden Tigere
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

INFO231-Object Oriented Programming

The document describes an object-oriented banking application in C++. It defines classes for accounts (CurrentAccount and SavingsAccount) that inherit from an abstract Account class, transactions, and a banking application to manage accounts and process transfers and external transactions from Bank Z. The main function demonstrates adding a customer, transferring funds between accounts, and processing the transactions through Bank Z.

Uploaded by

Aiden Tigere
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Midlands State University

Bachelor of Commerce Honors in Information Systems Degree


(HINFOSYS)
LEVEL 2.1

INFO231- Object Oriented Programming

LECTURER: T Hondoma

GROUP ASSIGNMENT
NAME REG NUMBER
Ellen Bridget Mhandu R231767T
Aiden Tigere R228501A
Tawonezvi Tatenda Mike R236948N
Pius Nyika R172423m
#include <iostream>
#include <vector>
#include <string>
#include <ctime>
#include <sstream>

using namespace std;

// Forward declaration
class BankZ;

// Bank Z class for external transactions


class BankZ {
public:
void processTransactions(const vector<string>& transactionList) {
// Process transactions from Bank Z
cout << "Processing transactions from Bank Z..." << endl;
// Process transactionList
}
};

// Base class for Account


class Account {
protected:
double balance;

public:
Account() : balance(0) {}

virtual void deposit(double amount) = 0;


virtual void withdraw(double amount) = 0;
virtual void applyInterest() = 0;
virtual void applyTransactionFee(double amount) = 0;
virtual void sendNotification(const string& message) = 0;
virtual void reconcileTransactions(const vector<string>& transactionList) = 0;

double getBalance() const {


return balance;
}
};

// Current Account class


class CurrentAccount : public Account {
public:
void deposit(double amount) {
balance += amount;
}

void withdraw(double amount) {


balance -= amount;
}

void applyInterest() {
// Current account does not accrue interest
}

void applyTransactionFee(double amount) {


// Transaction fee for withdrawal
balance -= amount * 0.0005; // 0.05%
}

void sendNotification(const string& message) {


cout << "Notification sent for Current Account: " << message << endl;
}

void reconcileTransactions(const vector<string>& transactionList) {


// Reconciliation process for Bank X
cout << "Reconciling Current Account transactions..." << endl;
// Process transactionList
}
};

// Savings Account class


class SavingsAccount : public Account {
public:
void deposit(double amount) {
balance += amount;
}

void withdraw(double amount) {


balance -= amount;
}

void applyInterest() {
// Interest for Savings account
balance += balance * 0.005; // 0.5%
}

void applyTransactionFee(double amount) {


// No transaction fee for deposit into Savings account
}
void sendNotification(const string& message) {
cout << "Notification sent for Savings Account: " << message << endl;
}

void reconcileTransactions(const vector<string>& transactionList) {


// Reconciliation process for Bank X
cout << "Reconciling Savings Account transactions..." << endl;
// Process transactionList
}
};

// Transaction class
class Transaction {
private:
string from;
string to;
double amount;
time_t timestamp;

public:
Transaction(const string& from, const string& to, double amount) : from(from),
to(to), amount(amount) {
timestamp = time(NULL); // Current timestamp
}

string getFrom() const {


return from;
}

string getTo() const {


return to;
}

double getAmount() const {


return amount;
}

time_t getTimestamp() const {


return timestamp;
}
};

// Banking Application class


class BankingApplication {
private:
vector<Account*> accounts;
vector<Transaction> transactions;
public:
void addCustomer() {
CurrentAccount* currentAccount = new CurrentAccount();
SavingsAccount* savingsAccount = new SavingsAccount();
currentAccount->deposit(0); // Joining bonus of R500 credited to Savings
Account
savingsAccount->deposit(500);
accounts.push_back(currentAccount);
accounts.push_back(savingsAccount);
}

void transferMoney(int fromAccountIndex, int toAccountIndex, double amount) {


Account* fromAccount = accounts[fromAccountIndex];
Account* toAccount = accounts[toAccountIndex];

fromAccount->withdraw(amount);
toAccount->deposit(amount);

transactions.push_back(Transaction("Customer", "Customer", amount));


}

void processTransactions(BankZ& bankZ) {


// Process transactions with Bank Z
vector<string> transactionList;
for (size_t i = 0; i < transactions.size(); ++i) {
stringstream ss;
ss << transactions[i].getAmount();
string transactionInfo = "Transaction: From " + transactions[i].getFrom() + " to
" + transactions[i].getTo() + ", Amount: " + ss.str();
transactionList.push_back(transactionInfo);
}

bankZ.processTransactions(transactionList);

// Reconcile transactions for each account


for (size_t i = 0; i < accounts.size(); ++i) {
accounts[i]->reconcileTransactions(transactionList);
}
}
};

int main() {
BankingApplication bank;

bank.addCustomer();

int fromAccountIndex, toAccountIndex;


double amount;

cout << "Enter from account index (0 for Current Account, 1 for Savings Account):
";
cin >> fromAccountIndex;

cout << "Enter to account index (0 for Current Account, 1 for Savings Account): ";
cin >> toAccountIndex;

cout << "Enter amount to transfer: ";


cin >> amount;

bank.transferMoney(fromAccountIndex, toAccountIndex, amount);

BankZ bankZ;
bank.processTransactions(bankZ);

return 0;
}

You might also like