CJCoding With Joseph
15free / daySign inCreate account

A friend function is a non-member function that is allowed to access a class's private members. Create a class Wallet with a private double balance set by its constructor.

Requirements: 1) Constructor Wallet(double b) that stores b in balance. 2) Declare a friend function inside the class: friend double getBalance(const Wallet& w); 3) Define getBalance as a normal free function (NOT a member) that returns w.balance.

Do NOT write a main function.

Expected output

25.5
12.75

= newline. The output ends with a newline, so print one after the last line.

Hints3 available
Topics
ClassesFriend Functions
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.