37.1k views
2 votes
Create a file account.cpp containing a Bank Account Class.

Your class should contain:

- private fields for the customer’s name and a balance.
- one or more constructors.
- methods to access the name and balance (these methods don’t modify the data)
- and methods to deposit and withdraw an amount (these methods modifies the data).

Write a main function that creates two of these objects: Account1 & Account2 and then:
- prints the original balance for both accounts with the customer’s name
- deposits some amount in Account1 and prints the final balance with the customer’s name
- withdraws some amount from Account2 and prints the final balance with the customer’s name

1 Answer

5 votes

Answer:

#include <iostream>

using namespace std;

class BankAccount {

string name = name;

double balance = balance;

BankAccount( string name, double balance ) {

string name = name;

double balance = balance;

return 0;

}

string getName( ){

return name;

}

double getbalance( ) {

return balance;

void setName( string username){

name = username;

}

void setbalance( double newBalance){

balance = newBalance;

}

int main( ) {

BankAccount user1(John, 0.0);

BankAccount user2(Jane, 0.0);

user1.setbalance( 2300.00)

user2.setbalance( 4300.00)

cout << user1.getname() << user1.getbalance();

cout << user1.getname() << user1.getbalance();

}

Step-by-step explanation:

The C source code above using a class to create a data structure of a bank account user name and balance. The attribute name and balance are private to the class and can be retrieved and modified through the get and set methods.

User Tekkerue
by
5.2k points