Knowee
Questions
Features
Study Tools

Write a C++ program to implement a class called Bank that has private member variables for account_number, operation_type,old_balance , amount, and  new_balance.Create a parameterized constructor to initialize the data members.Include member function “calculate “that prints the balance after deposit or withdrawal.Sample output1011 (account number)D  (D-deposit / W-withdraw)1000 (old balance)2000 (amount)Sample Output3000

Question

Write a C++ program to implement a class called Bank that has private member variables for account_number, operation_type,old_balance , amount, and  new_balance.Create a parameterized constructor to initialize the data members.Include member function “calculate “that prints the balance after deposit or withdrawal.Sample output1011 (account number)D  (D-deposit / W-withdraw)1000 (old balance)2000 (amount)Sample Output3000

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple C++ program that implements a Bank class as per your requirements:

#include<iostream>
#include<string>
using namespace std;

class Bank {
    private:
        int account_number;
        char operation_type;
        double old_balance;
        double amount;
        double new_balance;

    public:
        Bank(int acc_no, char op_type, double old_bal, double amt) {
            account_number = acc_no;
            operation_type = op_type;
            old_balance = old_bal;
            amount = amt;
        }

        void calculate() {
            if(operation_type == 'D' || operation_type == 'd') {
                new_balance = old_balance + amount;
            } else if(operation_type == 'W' || operation_type == 'w') {
                if(old_balance >= amount) {
                    new_balance = old_balance - amount;
                } else {
                    cout << "Insufficient balance." << endl;
                    return;
                }
            } else {
                cout << "Invalid operation type." << endl;
                return;
            }
            cout << "Account Number: " << account_number << endl;
            cout << "Operation Type: " << operation_type << endl;
            cout << "Old Balance: " << old_balance << endl;
            cout << "Amount: " << amount << endl;
            cout << "New Balance: " << new_balance << endl;
        }
};

int main() {
    Bank b1(1011, 'D', 1000, 2000);
    b1.calculate();
    return 0;
}

This program creates a Bank class with private member variables for account_number, operation_type, old_balance, amount, and new_balance. It has a parameterized constructor to initialize these data members. The member function "calculate" checks the operation type and performs the deposit or withdrawal operation accordingly, then prints the new balance. If the operation type is invalid or if there is an attempt to withdraw more than the available balance, it prints an error message.

This problem has been solved

Similar Questions

Write a C++ program to implement a class called BankAccount that represents a simple bank account. The class should have private member variables for account number and balance. Include member functions to deposit and withdraw money from the accoun

Program that creates a class Account that stores a variable balance. The class has methods to startaccount, to deposit money, to withdraw money and tell the current balance amoun

You are required to implement a simple C++ program for managing a bank account. The program should include a class BankAccount with private attributes for account number, account holder name, and account balance.The BankAccount class should have the following:A parameterized constructor to initialize the account number, account holder name, and account balance.A friend function displayAccountInfo that takes a BankAccount object as an argument and displays the account information (account number, account holder name, and account balance).Additionally, the program should check if the account balance is greater than Rs.10,000 and display whether the account holder is eligible for a credit card.Testcase1:Sample Input:12345   // account numberJohn Doe  // name15000   // balanceSample Output:12345John Doe15000Yes Testcase2:Sample Input:98765   // account numberVirat Kohli  // name8000   // balanceSample Output:98765Virat Kohli8000No

A program to simulate a simple banking system in which the initial balance and rate of interest are read from the keyboard and these values are initialised using the constructor member function. The program consists of the following methods:To initialise the balance amount and the rate of interest using constructor member functionTo make depositTo withdraw an amount for the balanceTo find compound interest based on the rate of interestTo know the balance amountTo display the menu options

Write a java program to create a bank account with Name of the account holder, type of account(savings or current), Account number and Balance amount in the account. Also, create 5 customers for the class Bank_account using array of objects. Access the customers to perform credit, debit and display of balance. Input 1: Enter the customers: Reena Savings 123 1000 Robin Current 456 2000 Praveen Savings 789 3000 Sherin Current 234 2500 Deena Savings 567 2000 Enter choice: 1. Credit 2. Debit

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.