Class member function

I have no idea how to write the statement for the displayAccount member function. I have tried everything. I would be grateful if someone could correct it for me. Thank you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <string>

class Account{
public:
Account(std::string accountName,
        int initialBalance)
: name {accountName}{
    if(initialBalance > 0){
        balance = initialBalance;
    }
}
void deposit (int depositAmount){
    if(depositAmount>0){
    balance = balance + depositAmount;
    }
}
int getBalance(){
    return balance;
}

void setName (std::string accountName){
    name = accountName;
}
std::string getName() const{
    return name;
}
//I have problem with the following statement:

void displayAccount (Account account1){
    std::cout << "\naccount1 name:" 
     << name << "balance: " << balance;
}
void displayAccount (Account account2){
    std::cout << "\naccount2 name: "
     << name << "balance: " << balance;
}
private:
std::string name;
int balance{0};
};
using namespace std;

int main(){

Account account1 {"John Doe", -40};
Account account2 {"Joe White", 30};

//second part to display it in the main. also //need help.
displayAccount(account1);
displayAccount(account2);
}
1
2
3
4
void displayAccount (){
    std::cout << "\naccount1 name:" 
     << name << "balance: " << balance;
}


Call it like this:
account1.displayAccount();
Topic archived. No new replies allowed.