Need help with vectors and arrays
Mar 8, 2013 at 10:22pm UTC
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.
This what I have thus far:
header
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
# include<iostream.h>
# include<conio.h>
# include<iomanip.h>
class bank
{
char name[20];
int acno;
char actype[4];
float balance;
public :
void init();
void deposit();
void withdraw();
void disp_det();
};
void bank :: init()
{
cout<<"New Account" ;
cout<<"Enter the Name of the depositor : " ;
cin.get(name,19,'' );
cout<<"Enter the Account Number : " ;
cin>>acno;
cout<<"Enter the Account Type : (CURR/SAVG/FD/RD/DMAT) " ;
cin>>actype;
cout<<"Enter the Amount to Deposit : " ;
cin >> balance;
}
void bank::deposit()
{
float more;
cout <<"Depositing" ;
cout<<"Enter the amount to deposit : " ;
cin >> more;
balance+=more;
}
void bank::withdraw()
{
float amt;
cout<<"Withdrwal" ;
cout<<"Enter the amount to withdraw : " ;
cin >> amt;
balance -=amt;
}
void bank::disp_det()
{
cout<<"Account Details" ;
cout<<"Name of the depositor : " << name << endl;
cout<<"Account Number : " << acno << endl;
cout<<"Account Type : " << actype << endl;
cout<<"Balance : $" << balance << endl;
}
void main(void )
{
clrscr();
bank obj;
int choice =1;
while (choice != 0 )
{
cout<<"Enter 0 to exit
1. Initialize a new acc.
2. Deposit
3.Withdraw
4.See A/c Status" ;
cin>>choice;
switch (choice)
{
case 0 :obj.disp_det();
cout<<"EXITING PROGRAM." ;
break ;
case 1 : obj.init();
break ;
case 2: obj.deposit();
break ;
case 3 : obj.withdraw();
break ;
case 4: obj.disp_det();
break ;
default : cout<<"Illegal Option" <<endl;
}
}
getch();
}
.cpp
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
#include<iostream>
#include<vector>
class bank
{
char name[20];
int acno;
char actype[4];
float balance;
public :
void init();
void deposit();
void withdraw();
void disp_det();
};
void bank::init()
{
cout<>acno;
cout<>actype;
cout<>balance;
}
void bank :: deposit()
{
float more;
cout <>more;
balance+=more;
}
void bank :: withdraw()
{
float amt;
cout<>amt;
balance-=amt;
}
void bank :: disp_det()
{
cout<>choice;
switch (choice)
{
case 0 :obj.disp_det();
cout<
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
#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 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()
{
system("PAUSE" );
return 0;
}
Last edited on Mar 8, 2013 at 10:34pm UTC
Mar 8, 2013 at 10:28pm UTC
You didn't explain what your problem is. Not too many people are going to read through 400 lines of poorly formatted code.
To have a better chance of getting help, state exactly what is wrong with your code and try to isolate it to a few lines or concepts.
Topic archived. No new replies allowed.