Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
22 views

Assignment 3

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

Assignment 3

Question on C++
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment No 3

Kanishk Tomar
23BCE10588

Implement below given problem in C++: Supporting Code has been given. You need to
submit pdf
file of runnable code. This is the work against class dated on 30th July 2024.
Assume that a bank maintains two kinds of account for its customers, one called
saving account and the other current account. The saving account provides
compound interest and withdrawal facilities but no cheque book facility. The
current account provides cheque book facility but no interest. Current account
holders should also maintain a minimum balance falls below this level, a service
charge is imposed. Create a class Account that stores customer name, account

number, and l type of account. From this device the classes Curr-acct and Sav-
acct to make them more specific to their requirements. Include the necessary

methods in order to achieve the following tasks. • Accept deposit from a


customer and update the balance • Display the balance • Compute and deposit
interest • Permit withdrawal and update the balance • Check for the minimum
balance, impose penalty, if necessary and update the balance. Do not use any
constructors. Use methods to initialize the class members.
#include <iostream>
#include <string>
using namespace std;

// Base class
class Account {
protected:
string customer_name;
int account_number;
string account_type;
double balance;

public:
// Method to initialize account details
void initialize(string name, int acc_num, string acc_type, double bal) {
customer_name = name;
account_number = acc_num;
account_type = acc_type;
balance = bal;
}

// Method to accept deposit and update balance


void deposit(double amount) {
balance += amount;
cout << "Deposit successful. Updated balance: " << balance << endl;
}

// Method to display balance


void display_balance() const {
cout << "Balance: " << balance << endl;
}

// Virtual method for withdrawal, to be overridden by derived classes


virtual void withdraw(double amount) = 0;
};
// Derived class for savings account
class Sav_acct : public Account {
private:
double interest_rate; // Annual interest rate in percentage

public:
// Method to initialize savings account details
void initialize(string name, int acc_num, double bal, double rate) {
Account::initialize(name, acc_num, "Savings", bal);
interest_rate = rate;
}

// Method to compute and deposit interest


void compute_interest() {
double interest = balance * (interest_rate / 100);
deposit(interest);
cout << "Interest computed and deposited. Interest: " << interest << endl;
}

// Method to permit withdrawal and update balance


void withdraw(double amount) override {
if (amount > balance) {
cout << "Insufficient balance for withdrawal." << endl;
} else {
balance -= amount;
cout << "Withdrawal successful. Updated balance: " << balance << endl;
}
}
};

// Derived class for current account


class Curr_acct : public Account {
private:
double minimum_balance;
double penalty;

public:
// Method to initialize current account details
void initialize(string name, int acc_num, double bal, double min_bal, double pen) {
Account::initialize(name, acc_num, "Current", bal);
minimum_balance = min_bal;
penalty = pen;
}

// Method to check minimum balance and impose penalty if necessary


void check_min_balance() {
if (balance < minimum_balance) {
balance -= penalty;
cout << "Penalty imposed due to insufficient minimum balance. Penalty: " << penalty
<< endl;
cout << "Updated balance: " << balance << endl;
}
}

// Method to permit withdrawal and update balance


void withdraw(double amount) override {
if (amount > balance) {
cout << "Insufficient balance for withdrawal." << endl;
} else {
balance -= amount;
cout << "Withdrawal successful. Updated balance: " << balance << endl;
check_min_balance();
}
}
};

int main() {
// Example for Savings Account
Sav_acct savings;
savings.initialize("John Doe", 1001, 5000.0, 4.0);
savings.deposit(1000.0);
savings.compute_interest();
savings.withdraw(2000.0);
savings.display_balance();

cout << "\n";

// Example for Current Account


Curr_acct current;
current.initialize("Jane Doe", 1002, 10000.0, 5000.0, 500.0);
current.deposit(2000.0);
current.withdraw(8000.0);
current.display_balance();

return 0;
}

You might also like