creating a display function

Hey there, I am working on this for an assignment and cannot figure out how to even get started to write the function for the following program.

The code given is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
#include "BACCOUNT.H"
using namespace std;
 
void display(const bankAccount & anAcct)
{

}


int main()
{
	bankAccount a("Annie Hill", 123.00);
	bankAccount b("Becker" , 45.60);
	display(a);
		display(b);
		return 0;
}


and I need to write a display function that will make the name and balance for bankAccount a and bankAccount b display.

I've been working on this for about 3 days now, and cannot figure out how to even start.
Last edited on
Do you know what bankAccount looks like?
Do you know how to output members of a class or struct?
Simply display the members of bankAccount.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
Forgot to add my output needs to read:

bankAccount: Hill, Annie, $123.00
bankAccount: Becker, Bob, $45.60

I understand how to display the members of bank account, its just the separating and organizing of them that's throwing be off.

Also I'm realllly new to c++ , so I'm sure I'm full of dumb questions.
Thanks for editing you post to add code tags.

You haven't posted the declaration of bankAccount (baccount.h), so I have to guess what it looks like. I'm thinking it looks something like this:
1
2
3
4
5
6
7
8
class bankAccount
{   
public:
    string m_name;
    double m_balance;

    bankAccount (const string & name, double bal);
};


If that's close, then your display function should look something like this:
1
2
3
void display (const bankAccount & anAcct)
{   cout << "bankAccount: " << anAcct.name << ", $" << fixed << prec(2) << anAcct.balance << endl;
}

You'll need a #include <iomanip> and you'll also need to write the constructor for the class.


Topic archived. No new replies allowed.