My Assignment-OOP
My Assignment-OOP
void withdraw(double amount): subtracts the specified amount from the account
balance.
3. Create at least two objects of the BankAccount class and demonstrate the usage
of the member functions by performing deposit and withdrawal operations on these
objects.
Note: Ensure proper encapsulation and access specifiers are used. Use
appropriate constructors and destructors wherever necessary.
Program:-
#include <iostream>
#include <string>
using namespace std;
2
class BankAccount {
private:
int accountnumber;
double balance;
string ownername;
public:
// Constructor to initialize a BankAccount object
BankAccount(int accnum, double bal, string owner)
{
accountnumber=accnum;
balance=bal;
ownername=owner;
3
// Method to withdraw money from the account
void withdraw(double amount)
{
if (amount > balance)
{
cout << "Withdrawal failed: Insufficient funds!"<<endl;
} else {
balance -= amount;
cout << "Withdrew $" << amount << " from account number: "
<< accountnumber << endl;
}
}
4
int main()
{
// User input for account creation
int accountnumber1,accountnumber2;
double balance1,balance2;
string ownername1,ownername2;
6
Output: