Help with errors for bank statement

Hi,

I’m writing a code that displays a Bank Statement. It involves two classes, one called Transaction and another called Statement. Transaction basically details the transaction itself (the amount, whether it is a withdrawal or deposit, and a note on what the transaction was for). Statement collects the data and compiles it together to display all the transactions that have been done and the end results (end balance, number of withdrawals/deposits, transaction history, etc).



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
//BankStatement.h//

#ifndef BankStatement_H
#define BankStatement_H
#include "Transaction.h"
#pragma once
#include <iostream> 
#include <string> 
#include <array>
#include <cstdlib>	// for the library rand() function
#include <cmath>
#include <ctime>
#include <vector>
using namespace std;

const unsigned int TRANS_LOG_SIZE = 30;

class BankStatement
{
public:
	BankStatement();
	void SetBegBal(float Balance); // Validate parameter and then initialize BegBal AND EndBal
	float GetBegBal();
	float GetEndBal();
	int GetNumEntries();
	void EnterTransaction(Transaction Input); // Inserts Input transaction into next available 
	// slot in TransactionLog array, updates RunningBal array, and adjusts NumEntries, 
	// NumDeposits (or NumWithdrawals) and EndBal
	void DisplayResults();  // Displays BegBal, TransactionLog array, RunningBal array, and final
	// stats (i.e., EndBal, # of total transactions, # of  deposits and # of withdrawls) -- see pg 37 
	void ArrangeTransactions();   // Arranges the Arranged array from the TransactionLog array
	void PrintArranged();	// Displays the Arranged[] array
private:
	array<Transaction, TRANS_LOG_SIZE > TransactionLog; 	// Transactions as container
	array<Transaction, TRANS_LOG_SIZE > Arranged; 	           // Sorted Transactions container
	array<float, TRANS_LOG_SIZE > RunningBal;                      // Running balance container
	float BegBal;      	 			// Balance as of last transaction entered
	float EndBal;       	 			// Record of beginning balance
	int NumEntries;    				// Total number of transactions in the statement
	int NumDeposits;				// Number of deposit transactions
	int NumWithdrawals;			// Number of withdrawal transactions

};

#endif





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
//Transaction.h//
#ifndef Transaction_H
#define Transaction_H
#pragma once
#include <iostream> 
#include <string> 
using namespace std;

class Transaction
{
public:
	Transaction();
	Transaction(float InAmount, char InCode, string InNote);
	void SetAmount(float NewAmount);
	float GetAmount();
	void SetCode(char NewCode);
	char GetCode();
	void SetNote(string NewNote);
	string GetNote();
	// void LoadTransaction();  ← optional per discussion on page 34
private:
	float Amount;   	// Transaction amount
	char Code;       	// Transaction type, ‘D’ for deposit, ‘W’ for withdrawal
	string Note; 	// Purpose of the transaction
};

#endif




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
//BankStatement.cpp//
#include "BankStatement.h"
#include "Transaction.h"


BankStatement::BankStatement()
{
	NumEntries = 0;
	BegBal = EndBal = 0.0f;
}
void BankStatement::SetBegBal(float Balance)
{
	//Before any transaction was performed, beginning and ending balances would be equal
	EndBal = BegBal = Balance;
	NumEntries = 0;
}
float BankStatement::GetBegBal()
{
	return BegBal;
}
float BankStatement::GetEndBal()
{
	return EndBal;
}
int BankStatement::GetNumEntries()
{
	return NumEntries;
}
void BankStatement::EnterTransaction(Transaction Input)
{
	//Check if transactions count didn't reach max value
	if (NumEntries == MaxTransactions)
		return;
	TransactionLog[NumEntries] = Input;
	// update ending balance field according to transaction type
	if (Input.GetCode() == 'D') // deposit transaction
	{
		EndBal += Input.GetAmount();
	}
	else // withdraw transaction
	{
		EndBal -= Input.GetAmount();
	}
	// check for float precision issue
	if (fabs(EndBal) < 0.01) EndBal = 0;
	// copy current ending balance to running balance
	RunningBal[NumEntries] = EndBal;
	NumEntries++;
}
void BankStatement::DisplayResults()
{
	// setup output format (2 digits after decimal point)
	cout.setf(ios_base::fixed);
	cout.precision(2);
	// print balance details
	cout << "The beggining balance was: $" << BegBal << endl;
	int nDepNum = 0;
	for (int Count = 0; Count < NumEntries; Count++)
	{
		cout << "Transaction#" << Count + 1 << " was a " << TransactionLog[Count].GetCode() << " amount: $"
			<< Count[TransactionLog].GetAmount() << " for " << TransactionLog[Count].GetNote() << endl
			<< "Running balance: $" << RunningBal[Count];
		if (RunningBal[Count] < 0) cout << " OVERDRAWN";
		cout << endl;
		if (TransactionLog[Count].GetCode() == 'D') nDepNum++;
	}
	cout << "The ending balance is: $" << EndBal << endl << "The number of Transactions is: " << NumEntries << endl
		<< "The number of Deposits is: " << nDepNum << endl << "The number of Withdrawals is: "
		<< NumEntries - nDepNum << endl;
}
void BankStatement::ArrangeTransactions()
{
	int ArrangedIndex = 0;
	for (int Count = 0; Count < NumEntries; Count++)
	{
		if (TransactionLog[Count].GetCode() != 'D') continue;
		Arranged[ArrangedIndex] = TransactionLog[Count];
		ArrangedIndex++;
	}
	for (int Count = 0; Count < NumEntries; Count++)
	{
		if (TransactionLog[Count].GetCode() != 'W') continue;
		Arranged[ArrangedIndex] = TransactionLog[Count];
		ArrangedIndex++;
	}
}
void BankStatement::PrintArranged()
{
	// print arranged transactions array
	cout << "Printing the Deposits and Withdrawals as a group:" << endl;
	for (int Count = 0; Count < NumEntries; Count++)
	{
		cout << "Transaction#" << Count + 1 << " was a " << Arranged[Count].GetCode() << " amount: $"
			<< Arranged[Count].GetAmount() << " for " << Arranged[Count].GetNote() << endl;
	}
}



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
//Transaction.cpp//
#include "Transaction.h"
#include <cstring>



Transaction::Transaction()
{
	//Default field values
	Amount = 0.0f;
	Code = 'U'; // Unknown code
	strcpy(Note, ""); //No comment given
}

Transaction::Transaction(float InAmount, char InCode, char InNote[])
{
	//Setup fields according to parameters passed to Constructor
	Amount = InAmount;
	Code = InCode;
	strcpy(Note, InNote);
}
void Transaction::SetAmount(float NewAmount)
{
	Amount = NewAmount;
}
float Transaction::GetAmount()
{
	return Amount;
}
void Transaction::SetCode(char NewCode)
{
	Code = NewCode;
}
char Transaction::GetCode()
{
	return Code;
}
void Transaction::SetNote(char* NewNote)
{
	strcpy(Note, NewNote);
}
const char* Transaction::GetNote()
{
	return Note;
}




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
//main.cpp//

#include <iostream> // for cin,cout
#include <string>	
#include <cmath>
#include "Transaction.h"	// for processing the roll
#include "BankStatement.h"	// for processing die roll

using namespace std;

int main()  // NOTE THIS IS A NON-INTERACTIVE DRIVER!
{
	BankStatement MyStatement;	// Consider carefully all that takes place as a result of
	// this single object declaration!
	MyStatement.SetBegBal(15.92f);   	//Enter beginning balance

	// Declare some transaction objects
	Transaction T1;      				// TEST DATA
	T1.SetAmount(123.56f);
	T1.SetCode('D');
	T1.SetNote("CTPay");

	Transaction T2(153.86f, 'W', "Rent");

	Transaction T3;
	T3.SetAmount(75.56f);
	T3.SetCode('D');
	T3.SetNote("Tips");

	Transaction T4(12.56f, 'D', "Gift");

	Transaction T5;
	T5.SetAmount(73.74f);
	T5.SetCode('W');
	T5.SetNote("Date");

	Transaction T6(145.75f, 'D', "Loan");

	Transaction T7;
	T7.SetAmount(40.00f);
	T7.SetCode('W');
	T7.SetNote("Loan Payment");

	Transaction T8(21.74f, 'W', "Groceries");

	// Now insert the transaction objects into the bank statement
	MyStatement.EnterTransaction(T1); //Enter transactions into the
	MyStatement.EnterTransaction(T2); //BankStatement object
	// Six more transactions entered…………………………………………………………………
	MyStatement.EnterTransaction(T3);
	MyStatement.EnterTransaction(T4);
	MyStatement.EnterTransaction(T5);
	MyStatement.EnterTransaction(T6);
	MyStatement.EnterTransaction(T7);
	MyStatement.EnterTransaction(T8);


	//View history
	MyStatement.DisplayResults();
	cout << endl;

	//View grouped transactions
	
	MyStatement.ArrangeTransactions();
	MyStatement.PrintArranged();
	return 0;
}





However, I have got errors and taking time to figure out the issues;

Error 9 error C2040: 'Transaction::GetNote' : 'const char *(void)' differs in levels of indirection from 'std::string (void)'
Error 10 error C2065: 'MaxTransactions' : undeclared identifier
Error 12 error C2228: left of '.GetAmount' must have class/struct/union
Error 2 error C2511: 'Transaction::Transaction(float,char,char [])' : overloaded member function not found in 'Transaction'
Error 6 error C2511: 'void Transaction::SetNote(char *)' : overloaded member function not found in 'Transaction'
Error 8 error C2556: 'const char *Transaction::GetNote(void)' : overloaded function differs only by return type from 'std::string Transaction::GetNote(void)'
Error 3 error C2597: illegal reference to non-static member 'Transaction::Amount'
Error 1 error C2664: 'char *strcpy(char *,const char *)' : cannot convert argument 1 from 'std::string' to 'char *'
Error 11 error C2677: binary '[' : no global operator found which takes type 'std::array<Transaction,30>' (or there is no acceptable conversion)

The following is the example of the output from the function, DisplayResults().
The beginning balance was: $15.92
Transaction: 1 was a D amount: $123.56 for CTPay
Running Bal: $139.48
Transaction: 2 was a W amount: $153.86 for Rent
Running Bal: $-14.38 OVERDRAWN
etc., for the other transactions...................................................................... ........................................................................................................... The ending balance is: $84.01
The number of Transactions is: 8
The number of Deposits is: 4
The number of Withdrawals is: 4


The following is the result after calling the ArrangeTransactions() and PrintArranged() functions in the BankStatement class.
Printing the Deposits and Withdrawals as a group: Transaction was a D amount: $123.56 for CTPay Transaction was a D amount: $75.56 for Tips Transaction was a D amount: $12.56 for Gift

Transaction was a D amount: $145.75 for Loan Transaction was a W amount: $153.86 for Rent Transaction was a W amount: $73.74 for Date Transaction was a W amount:$40.00 for Loan Payment Transaction was a W amount: $21.74 for Groceries


Topic archived. No new replies allowed.