updateAccount() member function has no output

I need to turn a struct into a class. The class needs to display bank account details - first cheque account and then an updated member function to update the details to a savings account. I am able to display the details of the cheque but having troubles with the updateAccounnt() member function. Please see the question below:

"Mrs Sithole realises that a savings account will provide a higher interest rate. Now add a member function updateAccount() to the class BankAccount to change the type of bank account as well as the interest rate. Then test your updateAccount() member function by changing the type of Mrs Sithole’s bank account to a savings account with 0.06% interest. Display the details of her new account on the screen."

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
#include <iostream>
#include <string>
using namespace std;

class BankDetails{
    private:
        string name;
        string accnr;
        string type;
        string branch;
        double interestRate;

    public:
        void setName(string x){
            name = x;
        }
        string getName(){
            return name;
        }
        void setAccnr(string x){
            accnr = x;
        }
        string getAccnr(){
            return accnr;
        }
        void setType(string x){
            type = x;
        }
        string getType(){
            return type;
        }
        void setBranch(string x){
            branch = x;
        }
        string getBranch(){
            return branch;
        }

        void setRate(double x){
            interestRate = x;
        }
        double getRate(){
            return interestRate;
        }

        void update( );

};

int main ()
{
    BankDetails na, acn, ty, bra, intr;

    na.setName("Mrs WR Sithole\n");
    cout << "Account Name: " << na.getName();

    acn.setAccnr("5421776632\n");
    cout << "Account Number: " << acn.getAccnr();

    ty.setType("Cheque\n");
    cout << "Type of Account: " << ty.getType();

    bra.setBranch("306623\n");
    cout << "Branch Code: " << bra.getBranch();

    intr.setRate(0.01);
    cout << "Interest Rate: " << intr.getRate() << "%";
    return 0;
}
    void BankDetails::update(){
        type = "Savings";
        interestRate = 0.06;
    }
1
2
3
4
5
6
7
    BankDetails na, acn, ty, bra, intr;

    na.setName("Mrs WR Sithole\n");
    cout << "Account Name: " << na.getName();

    acn.setAccnr("5421776632\n");
    cout << "Account Number: " << acn.getAccnr();



There's only one person, so only one account variable.
1
2
3
4
5
6
7
    BankDetails myAccount;

    myAccount.setName("Mrs WR Sithole\n");
    cout << "Account Name: " << myAccount.getName();

    myAccount.setAccnr("5421776632\n");
    cout << "Account Number: " << myAccount.getAccnr();


Okay, I deleted the other variables and added myAccount. I am still not able to get an output for the updated version of the savings account. The output only shows me the information in int main. Please check edited code below:

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 <string>
using namespace std;

class BankDetails{
    private:
        string name;
        string accnr;
        string type;
        string branch;
        double interestRate;

    public:
        void setName(string x){
            name = x;
        }
        string getName(){
            return name;
        }
        void setAccnr(string x){
            accnr = x;
        }
        string getAccnr(){
            return accnr;
        }
        void setType(string x){
            type = x;
        }
        string getType(){
            return type;
        }
        void setBranch(string x){
            branch = x;
        }
        string getBranch(){
            return branch;
        }

        void setRate(double x){
            interestRate = x;
        }
        double getRate(){
            return interestRate;
        }

        void update( );

};

int main ()
{
    BankDetails myAccount;

    myAccount.setName("Mrs WR Sithole\n");
    cout << "Account Name: " << myAccount.getName();

    myAccount.setAccnr("5421776632\n");
    cout << "Account Number: " << myAccount.getAccnr();

    myAccount.setType("Cheque\n");
    cout << "Type of Account: " << myAccount.getType();

    myAccount.setBranch("306623\n");
    cout << "Branch Code: " << myAccount.getBranch();

    myAccount.setRate(0.01);
    cout << "Interest Rate: " << myAccount.getRate() << "%";
    return 0;
}
    void updateAccount(){
        BankDetails myAccount;

        myAccount.setType("Savings\n");
        cout << "Type of Account: " << myAccount.getType();

        myAccount.setRate(0.06);
        cout << "Interest Rate: " << myAccount.getRate() << "%";
    }
Last edited on
The output only shows me the information in int main


You never call the updateAccount function. That function should not create another temporary myAccount object (not the same as the one in main), instead pass the myAccount object from main to the updateAccount function as an argument.

Edit: The Update Account function should also take const arguments for the things that will change.

Functions should only do 1 conceptual thing: updating and printing information is 2 things.

Instead of calling lots of set functions, consider writing a constructor to set all the values at once when the object is created. Set functions can be used after the fact IF something needs to change.

In the same manner, write one function to do output. It's better than calling them all from main.

Good Luck !!

Edit:
Go and research the things I mentioned, will be good to see your new code.
Last edited on
Topic archived. No new replies allowed.