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. "; cin >> initialBalance; BankAccount account(initialBalance); account.displayBalance(); cout << "Enter withdrawal amount: Rs. "; cin >> withdrawalAmount; try { account.withdraw(withdrawalAmount); } catch (const invalid_argument &e) { cout << "Transaction unsuccessful: " << e.what() << endl; } catch (const runtime_error &e) { cout << "Transaction unsuccessful: " << e.what() << endl; } return 0; } ``` The program begins by including the ``
_________ ___ ______ _________ ______ ___ ______ ________.
________ ___ ______ ______ ____ ___ _____ ______ _____.
________ ____ ________ ________ _____.
_____ __________ _____ _______ __________ ____ _____ _________ _____ _____ ___ __________.
______ ____ ______ ________ ______ ___ ___ _________ ____ _________ ________ ______.
______ ________ _________ ________ __________ _____ _________ __________ ____ _____ __________ __________.
__________ __________ __________ _________ _______ ______ _____ __________.
_____ _______ ____ _______ __________ ___ ____ ______.
_______ _________ __________ __________ ______ _______.
__________ _________ __________ ________ _________ ____ ____ ______ ____.
_______ ____ __________ _________ _____ _____ _________ ______ _______ ________.
______ __________ __________ _____ ___ ____ ________.
___ _________ ______ _________ ________ __________.
________ _____ __________ ____ ____.
________ ________ ______ _____ ____ __________ _________ ________.
_______ _________ _____ _____ ______ ___ ______ ________ __________ _________ ______ ____.
___ _________ _____ ___ _______ ______ ____ ____.
____ ___ __________ ________ ____ ___ _________ _____.
_________ ___ _______ _________ ____ ____ ______ __________ ______.
______ ____ __________ ________ ___ ______ ______.
________ _______ ______ ____ __________ __________ ____ _______ _____ ____.
______ __________ ____ ___ ________ ______ __________ ____ _________ _________ _______.
__________ ___ _________ __________ _____ _______.
_______ _______ _____ ________ __________ __________ ____ ____ ______ ____.
___ ____ _______ ______ _____ _________ _________.
____ _________ ________ ______ ____ _________ ______ ____ ________ ______ _______.
_______ ________ ______ ______ _________.
_________ ___ _______ _________ _________ _______ ________ _____ ______ _____ ______ ______.
_______ ________ _______ ___ _______ _______ ___ __________ _________ _______.
_________ ______ ____ _________ __________ ___ ___.
______ ___ _________ ____ ________ _____ ________ ____ ________.
____ __________ ____ ____ ________ __________ ________ __________ _________ __________ _______ __________.
___ ______ _____ ________ __________.
_____ ________ ____ ____ _____ ________ ___ _________.
______ ______ ___ _________ ___ _________ ________ __________ ________ _______ ___.
______ ___ __________ __________ ________ ____ ____ ______ _________.
____ __________ _______ _________ _______.
_______ ________ _______ _________ _____ __________ _______ ________ _____.
______ _______ ______ _______ ___ _____.
_____ _______ _________ _____ _________ _________ __________ ___.
________ _________ ___ _____ _______ __________ _______ _____ ________.
______ ______ ___ __________ ____ _____ __________ ____.
_________ ______ ___ _____ _______ ______ _______ ___.
_______ _______ __________ ____ ________ __________.
__________ ________ ___ __________ ________ ______ _________ ____ ______ ________ ___.
__________ ____ ________ ____ ______ _________ _______.
___ ______ ________ __________ ____ __________.
___ __________ _____ _____ _______ ____ ______ ______ ____ ________ ________ ___.
_________ _________ ______ _____ ______ __________ __________ ___ _______ _____ ____.
___ ____ _______ _________ ____ __________.
_____ _____ _________ ______ ___ _________ __________.
___ _____ _______ __________ _________ ___ ______.
___ __________ _______ _________ __________ _______ ____ _________ ________ __________.
_________ ________ _______ _____ _________ ____ ____ ___ __________ ______.
________ __________ ______ _____ _____ _________ _____ _______ ____ ________.
____ ___ ____ _______ ________ ______ __________ ______ ___ ______ _______ ______.
_____ ________ ________ ________ ________ ______ ______ _______ ______ _________.
______ ______ _____ __________ ______ ______ ____.
_________ _________ _____ ______ _________ ________.
_________ _______ __________ _____ __________ _____ ____ ________.
__________ __________ _____ _______ _______ __________ _________ ____ ________.
___ ____ _________ __________ __________ ____ ______ _______ ______.
______ ___ ___ ___ __________ ___.
______ _________ _______ ________ ___ _______ _________ ________.
________ _____ ____ __________ ____ ____.
_____ ___ _________ ________ ____ _________ ___ ______ ___.
____ _______ ______ _________ ____ ___ _______ _____ _________ ____ __________ ___.
__________ ________ _____ ________ __________ _________ __________.
______ __________ ___ ______ _________ _____.
___ ____ _____ _____ ________ ____ _______ _______ _____ __________ ____ __________.
_________ ___ _______ _____ ________ ______ __________.
________ _______ __________ _________ __________ ________ _____ ___ _________ _____ ___.
__________ ______ ______ ______ ________ __________ _______ __________ ___.
_________ _____ _______ _____ ___ ________.
______ __________ ________ ______ _______ ____ _______.
_____ ______ ________ ______ _______ ______.
__________ ________ __________ ________ ___ __________ ____ __________ ____.
_________ ___ ________ __________ _______ _________ _________ _____ __________ _____ _______.
____ _________ ______ _______ _______ _______ ______ __________ ___ _____.
_____ ________ _______ _________ ___ ___ __________ _________.
_______ ______ _________ ________ _________.
________ _______ ________ _____ _____ ______ ______ ____ _______ ______ ______ _________.
___ __________ ____ ______ _____ _____ _________ ___.
_____ _______ _____ ________ __________ _______ ______ __________ ______ _________.
_____ _______ ___ ___ ______ __________ _________ _____ _____ ___ ________ _______.
___ ____ ______ __________ __________ ____ ___.
_______ ____ _________ _________ _________ ________ __________ ___ _____ ___ __________ ______.
_________ ________ _________ _________ ____ __________ _____ ____ ________ __________ _________ __________.
_______ ___ ______ _________ ________ ____ ___ __________ _______ ____.
______ ____ _____ ____ ___ _________ _______ _____ ___ ________.
__________ _______ ____ ______ _____ ______ ____ ________ ____.
_______ __________ _____ ___ _______ ________ ____ ______ ________ ________ __________ ______.
____ _____ _____ _______ _______ _________ _______ _________ ____.
_____ ______ _______ _________ _______ ______.
_________ _______ ___ ____ _____ ___ _______.
____ _________ _______ _______ ______ _______ ___ ______.
_____ ____ _________ _______ _____ _________ ___.
_______ ________ ____ _____ __________ ____ ____ ____ ____ _______.
___ ______ ______ _______ __________ _________ ___ _______ ________.
___ ________ ___ ___ _________ ________ __________.
___ __________ ____ __________ ____ _________ ____.
________ ____ __________ _____ _____ _________ ________ _____.
______ _________ _________ _________ ______.
_______ _______ ____ _____ _____ _______ _________ _______ ______ _____ __________.
_____ __________ ________ ______ ________ _________ _____ ______.
________ __________ ________ ____ ______ ___ ________ ____ ________.
_____ _______ ________ ______ ___ _____.
_________ ________ ________ ___ _______ __________ ________.
_________ ____ ______ ____ __________.
_________ _______ _________ ______ _______ ______ _____.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU BCS 31 2026 2027 - A banking application allows users to withdraw money from their accoun | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→