Question

A banking application allows users to withdraw money from their account. Write a C++ program that throws and catches an exception if the withdrawal amount is greater than the available balance. Display an appropriate message for both successful and unsuccessful transactions. Make use of suitable C++ construc

08 Aug 2026
Answer :
Word Count : 1245
A banking application must ensure that a customer cannot withdraw an amount greater than the available balance in the account. In C++, this situation can be handled effectively using exception handling. Exception handling provides a structured mechanism for detecting and responding to runtime errors without abruptly terminating the program. The main constructs used for exception handling in C++ are `try`, `throw`, and `catch`. In this banking application, the withdrawal operation can check whether the requested amount is greater than the account balance. If it is greater, an exception is thrown and an appropriate error message is displayed. If the withdrawal amount is within the available balance, the transaction is completed successfully and the remaining balance is displayed. A suitable C++ program can be written as follows: ```cpp #include #include using namespace std; class BankAccount { private: double balance; public: // Constructor BankAccount(double initialBalance) { balance = initialBalance; } // Function to withdraw money void withdraw(double amount) { if (amount <= 0) { throw invalid_argument("Withdrawal amount must be greater than zero."); } if (amount > balance) { throw runtime_error("Insufficient balance. Withdrawal cannot be completed."); } balance -= amount; cout << "Withdrawal successful." << endl; cout << "Amount withdrawn: Rs. " << amount << endl; cout << "Remaining balance: Rs. " << balance << endl; } // Function to display balance void displayBalance() { cout << "Available balance: Rs. " << balance << endl; } }; int main() { double initialBalance, withdrawalAmount; cout << "Enter initial account balance: Rs. ______ ____ ___ ___ __________ ____ _____ ___ ________.
______ _________ __________ ________ _____ ____ ___ ____ _______.
_________ ________ _________ _____ ____.
__________ ___ __________ _______ __________ ______.
_____ ________ ____ _________ ________ ___.
_______ _____ _____ ______ __________ _________ _________ ________ _______.
______ ____ __________ _________ ________ ______ ________ _______ ______ _____ __________.
__________ ____ _________ ___ _________ _______ _________.
___ ___ __________ _______ ___ ____ _______ _______.
______ ______ ____ ____ ___ _____ ____ ___ ____ ______ _________ _______.
_________ _______ _________ __________ _____.
______ ______ __________ _____ __________ _____ _______ _______ _______ _____ _________ __________.
____ __________ __________ ___ _______ __________ _____ __________ ____ _________ _______.
_________ ________ _______ ____ _______ ________ _______ _______ ________.
_____ ______ ___ _____ __________ ______.
__________ ____ _________ ________ _________ ____ _____ ______ ___ ________.
__________ _____ ________ ______ ______ __________ ______.
________ __________ ___ _________ _______ _____ __________.
______ ____ ________ ________ ________ _____ _______ ___ __________.
_______ ______ _______ _______ _______ __________.
_______ _______ _________ _______ ___ _______ _________ ______ ___ _____ _________.
________ _____ ___ ______ _________.
___ ___ ______ ______ __________ _____ ___ __________ ______.
_____ ________ ________ ______ _____ _____ _______ _______.
________ _________ ____ __________ _____ _______ _______ _____ _________ _______ _____ ______.
___ _________ _______ ______ __________ ______ _______ _______ ____.
_____ ___ _______ ________ _________ _______.
__________ ____ _____ ___ _____ ______ _______ __________ ___ ________ __________.
_____ ______ _________ ___ _________ _________ _________ ____.
_____ ____ ___ _____ ____ _________ __________ ____ ______ ________ ______ _______.
____ __________ __________ ____ __________ __________ _________ _________ __________ _____ __________ ____.
_____ __________ ___ __________ _____ ________ _________ _______ _________.
______ __________ ___ ______ _____ _____ ______ __________ __________ __________.
____ ______ ____ _____ ________ _______.
_____ _________ _____ _________ ______ ________ ____ ________.
___ ____ __________ _______ ________ _____.
_______ _______ __________ _________ _____ ________ _____.
_______ _____ _______ ______ ___ ______ ____ __________.
______ ______ ____ ____ _______ ___ __________ _________ _____.
_______ __________ _________ ___ _________ ________.
_________ ____ ____ _________ _______ _______ __________.
______ _____ _______ _________ ________ ___ _____.
________ _____ ________ ___ ______ ______.
_______ _________ ____ ____ ________.
_________ ______ ______ _____ ____ __________ ________.
_____ _______ ________ _______ _________ _________ ______ ________ _____ _____ ________.
_____ ___ __________ _____ ______ ________ ___ ___ _____.
_______ ____ ______ ______ _____ _____.
__________ _____ _______ ___ _________ _______ ______ _____.
_________ ___ __________ __________ ___ ____ ___ _______ ____ _________ _________ ________.
___ _____ ________ _________ ______.
_____ ____ ____ ______ _______ ____ _________.
__________ ______ _________ __________ _________ ____ ______ _____ _________ _____ _______.
_______ _____ ______ ________ ___ ___ ______ ____ _________ _____ __________ ______.
___ ________ ___ _______ ______ _________ __________ _________ ______ ____ ___.
_____ _______ __________ _______ __________ ________.
___ _______ ______ ___ _____ ________ ________ ____ ______.
____ _____ ______ ___ __________ _______.
___ ______ ________ __________ _____ ___ ______ ______ _________ _____ ___.
__________ _____ __________ _______ ________ _________ ________ ____ ___.
__________ _________ ________ ____ _________.
______ _____ ________ ___ _________ _________ _____ _______ __________ __________ ___.
__________ _________ ______ _____ __________ ______ __________ ____ ______ ____.
__________ ______ __________ ________ ____ _____ ________ ______.
_____ _______ _____ ____ _________ _______ _________ _______ _____.
_______ ________ _________ _______ _________ ___ ________ _______ __________ _________ __________.
______ _______ ________ ________ ________ ____ _______.
_______ __________ ________ _________ ________ ___ _______ __________ _________.
___ _____ ____ _______ ______ __________ ___ ____ _____ _____ ____.
_________ ___ ________ ________ ________ __________ ________ _____ _________ ________ _______.
_________ ___ _______ ___ _____ ____ ____ ___ ___.
____ ________ _____ __________ _________ ______ _____ ______ __________ __________ ______ ___.
_________ ______ ________ _____ _______ _____ ______ _______ _______ __________ _________.
_________ ______ __________ ________ _____.
______ ___ _____ __________ _____ ____ ____.
_______ ______ ________ _____ ___ __________ ___ ____ _____ ________ _______ _______.
____ ________ __________ ______ _________ ______ _______ ____ _______ ___ _______.
____ ____ ______ _____ _________ _______ ________ ______.
__________ ________ _______ _____ ________ ____ __________ ______.
_________ ______ __________ ___ ____ _______.
_________ ____ _____ _________ _______ _________ ___ _______.
________ ___ ________ _______ ________ _________ ________ _______ ________ ____ _____ _____.
_______ ___ _____ _____ ______ _______ ____.
___ _____ ____ _________ ________ _____ ______ ___.
__________ _________ _____ _____ ________.
________ _____ ______ _____ _________ _______ ________ __________ _____ _______ ________.
__________ _____ ________ ________ ______ _____.
__________ _____ _________ ______ ___ _______ _____ ________ _____ _________.
__________ ___ ________ _________ ______ ___ _________ __________ __________ ____ ______.
______ ________ _______ ___ ___.
______ ________ ___ _____ _____.
_________ ________ _____ __________ _____ __________ ___.
_________ _____ ________ ____ _________ ________ _______ _____ ____ _____ _______ ______.
_______ ____ ______ ______ ____ _____ ___ ___ ______.
_________ ______ ______ _______ _____ _________.
_________ ______ _________ ____ ___.
________ ____ ______ _________ _______ _____ ________ ________ ________ __________ _______ _____.
__________ ____ _____ ________ _________ _______ _____.
__________ _________ ___ _____ _________ _________ __________ ________ ____ _____.
_________ _______ _______ _______ ________ ___ ______ ___ _________ ______ _______.
__________ ____ ______ _______ __________ ___.
______ ___ _____ ____ _________ __________ _____.
_______ _______ __________ _________ __________ ________ ________ ___ __________ _________.
______ __________ __________ _______ _______ _____ ______ __________ _____ ______ _________ ______.
____ ___ ________ _______ ___ _________ ___ _____ ____ ______ _____.
______ _____ _________ ____ ____.
______ ________ __________ _________ ____ ______ _______ ______ __________.
_________ _____ _________ _________ ________ ________ _________.
_________ _______ ______ __________ ______ _______ ______ ___ _______.
_______ ___ _________ ____ __________ ___ ____ ___.
_________ ____ _______ ____ _______ _______ ________ ________ ________ _________ _________.
_____ ___ _________ _________ _______ ____ _______ ______ ________ _______.
____ ___ __________ __________ ________ _________.
__________ _____ ________ ________ __________ __________ ____ ________.
___ _______ _________ ______ _______ _______ ________.
_____ _____ ___ ____ ________ _________ _______ _____ __________.
______ ______ ___ ________ __________ ______ _______ ______ _______.
______ __________ ____.
Get Full Answer on WhatsApp
IGNOU NEWS
Assignment Submission Last Date Extended Till 30 June 2026 Click Here★★★IGNOU June 2026 TEE Date Sheet Released Click Here★★★
Top
📞
Call Support Instant phone assistance A banking application allows users to withdraw money from their accoun
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→