Question

Design a BankAccount class (Links to an external site.) that has the following member variables (Links...

Design a BankAccount class (Links to an external site.) that has the following member variables (Links to an external site.): • custName: a string • balance: a double

The class (Links to an external site.) should have the following member functions:

• Default Constructor (Links to an external site.). A default constructor (Links to an external site.) that sets custName as empty string and balance as 0. • Constructor (Links to an external site.). Accepts the custName and balance as arguments (Links to an external site.).

• setCustName. A mutator function for the custName variable (Links to an external site.).

• getCustName. An accessor function for the custName variable (Links to an external site.).

• setBalance. A mutator function for the balance variable (Links to an external site.).

• getBalance. An accessor function for the balance variable (Links to an external site.).

• deposit(double amount). Add the deposit amount passed in to the balance, assume the amount is not negative.

• withdrawal(double amount). Subtract the withdrawal amount from the balance. Assume the amount is not negative and is not greater than the balance.

Create an instance/object of BankAccount class using default constructor. Set the balance and customer name. Add $100 deposit by calling the deposit method. Subtract $50 withdrawal by calling the the withdrawal method. Display customer name and final balance.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ CODE:

#include <iostream>
#include <string>

using namespace std;

class BankAccount{
private:
    string custName;
    double balance;

public:
    // Default constructor
    BankAccount() : custName(""), balance(0) {}

    // Constructor
    BankAccount(string name, double bal) : custName(name), balance(bal) {}

    // Accessor
    string getCustName() const {
        return custName;
    }

    // Mutator
    void setCustName(string custName) {
        this->custName = custName;
    }

    // Accessor
    double getBalance() const {
        return balance;
    }

    // Mutator
    void setBalance(double balance) {
        this->balance = balance;
    }

    // Method to deposit amount
    void deposit(double amount) {
        this->balance += amount;
    }

    // Method to withdraw amount
    void withdraw(double amount) {
        this->balance -= amount;
    }
};

int main(){
    BankAccount b;
    b.setBalance(150.0);
    b.setCustName("John Doe");
    b.deposit(100.0);
    b.withdraw(50.0);
    cout << "Customer name: " << b.getCustName() << endl;
    cout << "Final balance: $" << b.getBalance() << endl;
    return 0;
}

OUTPUT:

FOR ANY HELP JUST DROP A COMMENT

Add a comment
Know the answer?
Add Answer to:
Design a BankAccount class (Links to an external site.) that has the following member variables (Links...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT