Classes and Vectors

Hi , I have been working on this for a while and I cant finish implementing this program. What Im doing is creating a program that prints out a bank statement. Has to list all deposits withdrawals and daily balance for each day. Then compute average daily balance, and minimum daily balance methods to compute interest of 0.5 percent per month. Assume month has 30 days. Input data is stored by date

Each transaction has the form;

Day Transaction Description

First entry should be in this form:

1 1143.24 Initial Balance

This is what I have and desperately need help getting the main function done and making it work

The compiler Xcode for mac is NOT showing any errors just saying build failed. So I cannot figure out what the problem is. I also am very new to this and cannot figure out how to debug it. Also, I dont know how to get any new created objects into the vectors transactions and day_bals? I know how to build the classes and such but can't get how to build the OBJECTS in main and get them to store in the vector. Then how I could print all transactions stored in the vectors?

PLEASE HELP!!!

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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

#include <iostream>
#include <string> 
#include <vector> 
using namespace std;

int MAX_DAY = 30;


class Transaction
{
public:
    Transaction();
    Transaction( int i_day, double i_amount, string i_description);
    void read() const;
    void print();
    int get_day() const;
    double get_amount() const;
        
private:
    int input_day;
    double input_amount;
    string input_description;
};

Transaction::Transaction (int i_day, double i_amount, string i_description)
{
    input_day = i_day;
    input_amount = i_amount;
    input_description = i_description;
}

int Transaction::get_day() const
{
    return input_day;
}

double Transaction::get_amount() const
{
    return input_amount;
}

void read()
{
    
}

void Transaction::print()
{
    cout << "DAY      " << "AMOUNT      " << "DESCRIPTION      " <<endl;
    cout <<input_day<< "      " << input_amount <<"      "<< input_description <<"      " <<endl;
}




class Statement
{
public:
    Statement();
    void read();
    void print(); 
    void compute_bal();
    double get_avg_day_bal();
    double get_min_day_bal();
    
    
private:
    
    vector <Transaction> transactions;
    vector <double> day_bals; 
    
};

Statement::Statement()
{
    
}

void Statement::read()
{
    cout << "Enter Transaction in DAY AMOUNT DESCRIPTION format: " << endl;
    bool more = true;
    while (more)
    {
        Transaction new_trans;
        new_trans.read();
        if (cin.fail())
            more = false;
        else
            transactions.push_back(new_trans);
            
    }
    compute_bal();
}


void Statement::compute_bal()
{
    int day;
    int i = 0;
    double balance = 0;
    
    for (day = 1; day <= MAX_DAY; day++)
    {
        while (i < transactions.size() && transactions[i].get_day() == day)
        {
            balance = balance + transactions[i].get_amount();
            i++;
        }
        day_bals.push_back(balance);
            
    }
}
    
double Statement::get_avg_day_bal()
{
    int day;
    double sum_of_bals = 0;
    
    for (day = 0; day < day_bals.size(); day++)
        sum_of_bals = sum_of_bals + day_bals[day];
    return sum_of_bals / MAX_DAY;
}

double Statement::get_min_day_bal()
{
    int day;
    double min_bal = day_bals[0];
    for (day = 1; day < day_bals.size(); day++)
        if (day_bals[day] < min_bal)
            min_bal = day_bals[day];
    return min_bal;
    
}

void Statement::print()
{
    int day;
    int i = 0;
    
    
    for (day = 1; day <= MAX_DAY; day++)
    {
        cout << "DAY: " << day << "BALANCE: " << day_bals[i - 1] << endl;
        while (i < transactions.size() && transactions[i].get_day() == day)
        {
            transactions[i].print();
            i++;
        }
    }
    
    
    const double INTEREST = 0.005;
    cout << "Minimum daily balance interest: " << get_min_day_bal() * INTEREST << endl;
    cout << "Average daily balance interest: " << get_avg_day_bal() * INTEREST << endl; 
}



    
    
    
    
int main()
{
 
    
   return 0;
}








Last edited on
closed account (o3hC5Di1)
Hi there,

Could you please wrap your code in [code]-tags?
It will make it more readable to us.

Also, try and be a little bit more specific about what's not working about it, it can help us help you faster.
I.e. of it throws compiler errors, say so (and copy them), if the program shows unexpected behaviour, say so (and tell us what it's supposed to do).

Thanks!

All the best,
NwN
Thanks NmN, I edited it with the code tags, I didn't know to do that, Ive only posted here once. I appreciate the response though and I tried to add whatever else I could. However, the compiler only says BUILD FAILED, and no errors are reported.
the compiler only says BUILD FAILED, and no errors are reported.

I compiled it with VS2010 with only minor warnings. However, I did get linker errors.
1
2
1>junk1.obj : error LNK2019: unresolved external symbol "public: void __thiscall Transaction::read(void)const " (?read@Transaction@@QBEXXZ) referenced in function "public: void __thiscall Statement::read(void)" (?read@Statement@@QAEXXZ)
1>junk1.obj : error LNK2019: unresolved external symbol "public: __thiscall Transaction::Transaction(void)" (??0Transaction@@QAE@XZ) referenced in function "public: void __thiscall Statement::read(void)" (?read@Statement@@QAEXXZ)


Transaction::read is declared as a class member at line 15, but is not implemented. You have a read function at line 43, but it is not qualified as a member of the Transaction class. I assume you meant Transaction::read. There is also a const mismatch between line 15 and line 43.

The linker is also trying to tell you your implementation of the Transaction default constructor is missing (invoked at line 86).



Last edited on
Topic archived. No new replies allowed.