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
Question
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
Solution
Sure, here is a simple implementation of a BankAccount class in C++:
#include<iostream>
using namespace std;
class BankAccount {
private:
int accountNumber;
double balance;
public:
// Constructor
BankAccount(int accountNumber, double initialBalance) {
this->accountNumber = accountNumber;
this->balance = initialBalance;
}
// Function to deposit money
void deposit(double amount) {
balance += amount;
}
// Function to withdraw money
void withdraw(double amount) {
if(balance >= amount) {
balance -= amount;
} else {
cout << "Insufficient balance!" << endl;
}
}
// Function to display account number and balance
void display() {
cout << "Account Number: " << accountNumber << ", Balance: " << balance << endl;
}
};
int main() {
BankAccount account1(123456, 500.0);
account1.display();
account1.deposit(200.0);
account1.display();
account1.withdraw(100.0);
account1.display();
account1.withdraw(700.0);
account1.display();
return 0;
}
In this program, we have a class BankAccount with private member variables accountNumber and balance. The class has a constructor to initialize these variables, and member functions deposit(), withdraw(), and display() to deposit money, withdraw money, and display the account number and balance respectively. The main() function creates an instance of BankAccount, and calls these member functions to demonstrate their functionality.
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 account.Testcase:Input:Rs.1000.0 // initial balanceRs.500.0 // depositRs.200.0 // withdrawOutput:Rs.1300.0 // final balance Input:Rs.2000.0 // initial balanceRs.1000.0 // depositRs.4000.0 // withdrawOutput:NA // final balance
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
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
Write a java program to create a bank account with Name of the account holder, type of account(savings or current), Account number and Balance amount in the account. Also, create 5 customers for the class Bank_account using array of objects. Access the customers to perform credit, debit and display of balance. Input 1: Enter the customers: Reena Savings 123 1000 Robin Current 456 2000 Praveen Savings 789 3000 Sherin Current 234 2500 Deena Savings 567 2000 Enter choice: 1. Credit 2. Debit
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.