Knowee
Questions
Features
Study Tools

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

Question

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

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple C++ program that implements the requirements:

#include<iostream>
#include<string>

using namespace std;

class BankAccount {
private:
    int accountNumber;
    string accountHolderName;
    double accountBalance;

public:
    // Parameterized constructor
    BankAccount(int accountNumber, string accountHolderName, double accountBalance) {
        this->accountNumber = accountNumber;
        this->accountHolderName = accountHolderName;
        this->accountBalance = accountBalance;
    }

    // Friend function
    friend void displayAccountInfo(BankAccount account);
};

void displayAccountInfo(BankAccount account) {
    cout << "Account Number: " << account.accountNumber << endl;
    cout << "Account Holder Name: " << account.accountHolderName << endl;
    cout << "Account Balance: " << account.accountBalance << endl;

    if(account.accountBalance > 10000) {
        cout << "Eligible for credit card: Yes" << endl;
    } else {
        cout << "Eligible for credit card: No" << endl;
    }
}

int main() {
    // Testcase 1
    BankAccount account1(12345, "John Doe", 15000);
    displayAccountInfo(account1);

    // Testcase 2
    BankAccount account2(98765, "Virat Kohli", 8000);
    displayAccountInfo(account2);

    return 0;
}

This program first defines a BankAccount class with private attributes for account number, account holder name, and account balance. The class has a parameterized constructor for initializing these attributes.

The displayAccountInfo function is a friend function of the BankAccount class, which means it can access the private attributes of the class. This function takes a BankAccount object as an argument and displays the account information. It also checks if the account balance is greater than 10,000 and displays whether the account holder is eligible for a credit card.

In the main function, we create two BankAccount objects for testing and call displayAccountInfo on each of them.

This problem has been solved

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 accoun

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.Create a parameterized constructor to initialize the data members.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

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

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

// BankAccount.java// Parent class BankAccountpublic class BankAccount { private String accountNumber; private double balance; public BankAccount(String accountNumber, double balance) { this.accountNumber = accountNumber; this.balance = balance; } public void deposit(double amount) { balance += amount; } public void withdraw(double amount) { if (balance >= amount) { balance -= amount; } else { System.out.println("Insufficient balance"); } } public double getBalance() { return balance; }}Copy// SavingsAccount.java// Child class SavingsAccountpublic class SavingsAccount extends BankAccount { public SavingsAccount(String accountNumber, double balance) { super(accountNumber, balance); } @Override public void withdraw(double amount) { if (getBalance() - amount < 100) { System.out.println("Minimum balance of $100 required!"); } else { super.withdraw(amount); } }}Copy // Main.java// Main classpublic class Main { public static void main(String[] args) { System.out.println("Create a Bank Account object (A/c No. BA1234) with initial balance of $500:"); //Create a BankAccount object (A/c No. "BA1234") with initial balance of $500 BankAccount BA1234 = new BankAccount("BA1234", 500); // Deposit $1000 into account BA1234 System.out.println("Deposit $1000 into account BA1234:"); BA1234.deposit(1000); System.out.println("New balance after depositing $1000: $" + BA1234.getBalance()); // Withdraw $600 from account BA1234 System.out.println("Withdraw $600 from account BA1234:"); BA1234.withdraw(600); System.out.println("New balance after withdrawing $600: $" + BA1234.getBalance()); // Create a SavingsAccount object (A/c No. "SA1234") with initial balance of $450 System.out.println("\nCreate a SavingsAccount object (A/c No. SA1234) with initial balance of $450:"); SavingsAccount SA1234 = new SavingsAccount("SA1234",450); // Withdraw $300 from SA1234 SA1234.withdraw(300); System.out.println("Balance after trying to withdraw $300: $" + SA1234.getBalance()); // Create a SavingsAccount object (A/c No. "SA1000") with initial balance of $300 System.out.println("\nCreate a SavingsAccount object (A/c No. SA1000) with initial balance of $300:"); SavingsAccount SA1000 = new SavingsAccount("SA1000",300); // Withdraw $250 from SA1000 (balance falls below $100) System.out.println("Try to withdraw $250 from SA1000!"); SA1000.withdraw(250); System.out.println("Balance after trying to withdraw $250: $" + SA1000.getBalance()); }}

1/3

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.