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.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.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

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

Solution

Sure, here is a simple implementation of the Bank class in C++:

#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 account_number, char operation_type, double old_balance, double amount) {
        this->account_number = account_number;
        this->operation_type = operation_type;
        this->old_balance = old_balance;
        this->amount = amount;
    }

    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 << "New balance: " << new_balance << endl;
    }
};

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

In this program, we have a class Bank with private member variables for account_number, operation_type, old_balance, amount, and new_balance. The constructor of the class initializes these variables. The calculate function checks the operation_type and performs the deposit or withdrawal operation accordingly, then prints the new balance. If the operation type is invalid or there is not enough balance for withdrawal, it prints an error message. The main function creates an object of the class and calls the calculate function.

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

Program on Polymorphism: Implement a Program to demonstrate method overriding A boy has his money deposited $1000, $1500, and $2000 in banks-Bank A, Bank B and Bank C respectively. We have to print the money deposited by him in a particular bank.Create a class 'Bank' with a method 'getBalance' which returns 0. Make its three subclasses named 'BankA', 'BankB' and 'BankC' with a method with the same name 'getBalance' which returns the amount deposited in that particular bank. Call the method 'getBalance' by the object of each of the three bankswrite a java code and its explaination

Assignment operatorsYou want to withdraw some money from your bank account.The program takes two numbers as input, your account balance and the amount you want to withdraw, and assigns them to corresponding "balance" and "withdraw" variables.TaskCalculate and output the remaining balance after the withdrawal.Sample Input4500009000Sample Output441000ExplanationThe first two lines of the given code declare the balance and the withdraw variables, whose values will be automatically taken as input and will be used in test cases. This means that your solution will be tested with different values of those variables.Don't change that part of the code and treat it as a usual variable.Use the -= shorthand for easier calculation.

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.