Classes and Vectors

I am in need of assistance with a homework assignment where I have to write a program that prints out a bank statement .The program input is a sequence of transactions with each transaction having the following: day, amount, description. The program should read in the descriptions and then print out a statement listing all deposits, withdrawals and the daily balance for each day. Then compute the interest earned by the account. The minimum and average daily balances methods should be used for computing interest and print out both values. An interest rate of .5% per month with the assumption that each month has 30 days with the data sorted by date. The first entry is the form of: 1 1143.24 initial balance.

Here is the template I was given:
#include <iostream>
#include <string>
#include <vector>
#include <fstream>

using namespace std;

class Transaction
{
public:
Transaction();
bool read(ifstream& infile);
int get_day();
double get_amount();
string get_description();
void print();
private:
int day;
double amount;
string description;
};

Transaction::Transaction()
{
amount = 0;
}

bool Transaction::read(ifstream& infile)
{
if (infile >> day)
{
infile >> amount;
getline(infile, description);
return true;
}
else
return false;
}

int Transaction::get_day()
{
return day;
}

double Transaction::get_amount()
{
return amount;
}

string Transaction::get_description()
{
return description;
}

void Transaction::print()
{
cout << day << " " << amount << " " << description << "\n";
}

const int MAX_DAY = 30;

class Statement
{
public:
Statement();
void read();
void compute_balances();
void print();
double get_average_daily_balance();
double get_minimum_daily_balance();
private:
vector<Transaction> transactions;
vector<double> daily_balances;
};

Statement::Statement()
{
}

void Statement::read()
{
ifstream infile;

// STUDENTS: Replace the pathname within the quotes to the location of this file on your system.
// Please remember to use two backslash characters between directories
// because a single backslash is interpreted as an escape key.

string filename="C:\\Data\\Strayer\\CIS242\\Lab Assignments\\lab13\\P6.13 Input Data.txt";

infile.open(filename);
if (infile.fail())
{
cout << "Error opening " << filename << " \nExiting program\n";
exit(1);
}
// cout << "Enter transactions in the format\n"
// << "date amount description:\n";
bool more = true;
while (more)
{
Transaction t;
if (t.read(infile))
transactions.push_back(t);
else
more = false;
}
compute_balances();
}

/*
INSTRUCTIONS TO STUDENTS:
Complete the remaining portion of the Statement implementation code here.
The Statement constructor and the Statement::read functions are provided
for you. In addition, you will need to replace the filename string with
the location of the input data file on your computer. Remember to use
to backslashes between each directory, since a single backslash is interpreted
as the escape key. A backslash character in C++ is denoted as "\\".
*/

void Statement::compute_balances()
{
// Insert implementation code for compute_balances here. This function
// should compute the balance for each day of the month.
}

double Statement::get_average_daily_balance()
{
// Insert the implementation code for this function which should
// calculate the average daily balance from each of the 30 days
// of balances.
}

double Statement::get_minimum_daily_balance()
{
// Insert the implementation code for this function which should
// determine the minimum monthly balance from the 30 days of
// balances.
}

void Statement::print()
{
// This function is responsible for printing the statement.
// For each day, print the balance at the end of the day
// followed by the transactions for that day.
// You will also need to print out the interest on the
// average and daily balances. You can call those functions
// from this routine.
}

// Leave the main routine untouched.

int main()
{
Statement stat;
stat.read();
stat.print();

system("pause");
return 0;
}
Topic archived. No new replies allowed.