fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class Customer
  4. {
  5. string name;
  6. int balance,account_number;
  7.  
  8. public:
  9. Customer(string name,int balance,int account_number)
  10. {
  11. this->name=name;
  12. this->balance=balance;
  13. this->account_number=account_number;
  14. }
  15.  
  16. void deposit(int amount)
  17. {
  18. if(amount>0)
  19. {
  20. balance=balance+amount;
  21. cout<<amount<<" rs is credited successfully\n";
  22. }
  23. else
  24. {
  25. throw runtime_error("Enter valid amount");
  26. }
  27. }
  28.  
  29. void withdraw (int amount)
  30. {
  31. if(amount>0 && amount<=balance)
  32. {
  33. balance=balance-amount;
  34. cout<<amount<<" rs is debited successfully\n";
  35. }
  36. else if(amount>balance)
  37. {
  38. throw runtime_error("Your balance is low");
  39. }
  40.  
  41. else
  42. {
  43. throw ("Enter valid amount");
  44. }
  45. }
  46.  
  47.  
  48. };
  49.  
  50.  
  51. int main()
  52. {
  53. try
  54. {
  55. Customer C1("Rohit",5000,10);
  56. C1.withdraw(6000);
  57. }
  58. catch(const runtime_error &e)
  59. {
  60. cout<<"Exception occured: "<<e.what()<<endl;
  61. }
  62.  
  63. }
  64.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Exception occured: Your balance is low