class help

This is what i should do
Implement class to represent Bank Account
With Attributes:
- Account Name text with spaces :char *
- Account ID : unique value :int
- Balance :double
- date : Date that represent the creation date of the account
Methods:
- Constructor default and parameterized with name, Account ID, Balance and current date
- Destructor
-Setters and Getters
-View to view Account Name, Account ID, currentbalance and date
-double Deposit(double value)
which returns balance value after adding the amount of deposit.
-double Withdraw( double value)
which calculate balance value after subtracting the amount of Withdraw. if balance >= value compute the amount of withdraw otherwise " Cannot Withdraw From the account , No available balance"

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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//header file
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include "Date.h"

class Account
{
    private:
        string Account_Name;
        static int Unique_ID;
        double Balance;
        Date Current_Date;

    public:

        Account();

        Account(string acoName, double bal, Date datee );

        void setName(string name);
        void setBalance (double balance);
        void setDate (Date date);

        string getName ();
        double getBalance();
        void getCurrentDate ();
        int getID ();

        void view ();
        double Deposit (double value);
        double Withdraw (double value);







        ~Account();
};
#endif // ACCOUNT_H


//.pp file 


#include "Account.h"
#include <iostream>
using namespace std;

Account :: Account ()
{
    Unique_ID = 1;
}

Account :: Account(string acoName, double bal , Date datee)
{
        Account_Name = acoName;
       // Unique_ID = uniID;
        Balance = bal;
        Current_Date = datee;

}
/**********************************************/
void Account :: setName(string name)
{
    Account_Name = name;

}

void Account ::  setBalance (double balance)
{
    Balance = balance;

}

void Account ::  setDate (Date date)
{
    Current_Date = date ;
}
/*******************************************/
string Account ::  getName ()
{
    return Account_Name;
}

double Account ::  getBalance()
{
    return Balance;
}
int Account :: getID()
{
    return Unique_ID ;
}

void Account ::  getCurrentDate ()
{
    Current_Date.getDate();
}
/*********************************************/
void Account :: view ()
{
    cout<<"Account Balance : "<<getBalance<<"\n Account Date : "<<getCurrentDate<<"\n Account ID : "<<getID<<"\n Account Name : "<<getName<<endl;
}
/************************************************************/
double Account :: Deposit (double value)
{
    return (Balance + value) ;

}
double Account :: Withdraw (double value)
{
    if (Balance >= value)
    {
        return (Balance - value);
    }
    else
        cout<<"Can Not Withdraw From the Account, No available Balance."<<endl;
}


Line 103, you are calling functions incorrectly. Rather than something like this:
getBalance

you need to call them like this:
getBalance()

getCurrentDate() returns void, so that won't work anyway in line 103 with the << operator.

Your Withdraw function looks a bit dodgy too. You are returning a double, but if your if condition sends you into the else part, then you don't return anything. you could do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
double Account :: Withdraw (double value)
{
    double rtn = 0.0;  // or some sensible default value
    if (Balance >= value)
    {
        rtn = (Balance - value);
    }
    else
    {
        std::cout<<"Can Not Withdraw From the Account, No available Balance."<<std::endl;
     }

     return rtn;
}


also, why have you declared your unique ID as static?

Last edited on
In addition to what mutexe said, Withdraw() and Deposit() should modify the Balance.
Topic archived. No new replies allowed.