### 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?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171`` `````` #include #include #include 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 " < transactions; vector 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
Hi there,

It will make it more readable to us.

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.
 ``12`` ``````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.