Hw help w/ classes

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
54
55
56
57
58
#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

class Acct
{
public:
  Account( char [], char, double);           //constructor
    
  void printAccount();
  void changeBalance( double );

  void setAcctType( char );

  char getAcctType();
  double getBalance();

private:
  char name[50];
  char acctType;
  double balance;
};

void printAccount()
void changeBalance(double amountToChange)
void setAcctType(char newType)
double getBalance()
char getAcctType()


int main()
{
Acct account1 = Acct( "Dylan, John", 'C', 113019.77 );
Acct account2 = Acct( "Taylor, Jon", 'C', 1234.50 );
Acct account3 = Acct( "Temperance, Brennan", 'C', 82.12 );
Acct account4 = Acct( "Seeley, Booth", 'C', 3869.00 );
Acct account5 = Acct( "Zach, Addy", 'C', 71940.76 );

account1.printAcct();
account2.printAcct();
account3.printAcct();
account4.printAcct();
account5.printAcct();
}

void Acct::printAccount()
{
int i;

cout << "
}


void setAcctType( char newType )
{
} 


I need help setting up these methods into my program. Can someone show me how it would look in my program above
void printAccount()

void setAcctType( char newType )

char getAcctType()

double getBalance()

Last edited on
Here's an example to help you get started. Your function definition:

void printAccount()

has no scope. You need to prepend the name of the function with your class name:

void Acct::printAccount()

Get these fixed, and see how it does.
okay i did that. I'm just unfamiliar on how it knows which account to print from above
You tell it which account, by calling the method from the appropriate object, as you're doing here:

1
2
3
4
5
6
account1.printAcct();
account2.printAcct();
account3.printAcct();
account4.printAcct();
account5.printAcct();
}


This code will run the printAcct() routine for each of the five accounts you've created.
okay, after i print account1 i need to increase the balance by 500 do i just

 
account1.set_acctBal( 500 )
and would
1
2
3
4
5

void Acct::printAccount()
{
cout << name << acctType << balance; 
}

work?
If you want to increment the balance, you need to know what the balance is. The usual way to do this is with a get() function, similar to your set() function.

Your cout statement will display those three members, but they'll be run together. You might want to put a " " in between the members.
would it be like this then?
 
account1.set_acctBal = double getBalance()

or how would it work, and i have an error with
1
2
3
4
5
6
7
void Acct::printAccount()
{
if (acctType == 'C')
cout << name << "/t"<< "Checking Account Balance:  $"<< balance; 
else
cout << name << "/t"<< "Savings Account Balance:  $"<< balance; 
}


i get a error saying it expected initializer before void
No, your set_acctBal() is a function, so you have to call it. The parameter you pass it is the new balance you want to set, which is $500 more than it currently is, right?

account1.set_acctBal(account1.getBalance() + 500.);

The error you're getting with printAccount() sounds like it's being caused by a code problem just before the function definition. I can't be sure, though, unless I see your entire program.
Last edited on
I cant help you with your constructors until i see what you have so far.
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78



#include <iostream>
#include <iomanip>

using namespace std;

class Acct
{
public:
  Acct(char [], char, double);           //constructor
    
  void printAccount();
  void changeBalance(double);

  void setAcctType(char);

  char getAcctType();
  double getBalance();

private:
  char name[50];
  char acctType;
  double balance;
  void set_acctName(char []);
  void set_acctType(char );
  void set_acctBal(double);
};

void printAccount();
void changeBalance();
void setAcctType();
double getBalance();
char getAcctType();


int main()
{
Acct account1 = Acct( "Goloshubov, Artem", 'C', 113019.77 );
Acct account2 = Acct( "Ampulski, Adam", 'C', 1234.50 );
Acct account3 = Acct( "Temperance, Brennan", 'C', 82.12 );
Acct account4 = Acct( "Seeley, Booth", 'C', 3869.00 );
Acct account5 = Acct( "Zach, Addy", 'C', 71940.76 );

account1.printAccount();

account2.printAccount();
account3.printAccount();
account4.printAccount();
account5.printAccount();
}

void Acct::printAccount()
{
if (acctType == 'C')
cout << "Name: " << name << "/t"<< "Checking Account Balance:  $"<< balance; 
else
cout << "Name: " << name << "/t"<< "Savings Account Balance:  $"<< balance; 
}

void Acct::changeBalance()
{
}

void Acct::setAcctType()
{
}

char Acct::getAcctType()
{
}

double Acct::getBalance()
{
}

Topic archived. No new replies allowed.