//file main.cpp
#include <iostream>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iomanip>

using namespace std;


#include "date.h"
#include "loan.h"
#include "setOfLoans.h"

void main() {
	//Test 1 in output file

	//create some loans on the heap
	Loan *p1 = new Loan("Lou", "11 Elgin St. Ottawa", Date(14,9,2006), 1000, 6.0, 12);
	Loan *p2 = new Loan("Sue", "21 Bank St. Ottawa", Date(14,9,2006), 5000, 7.0, 60);
	Loan *p3 = new Loan("Frank", "43 1st Avenue. Ottawa", Date(14,9,2006), 3000, 6.0, 24);

	cout << "\n" << *p1;
	p1->printPaymentSchedule(cout);

	//Create some sets
	SetOfLoans carLoans, otherLoans;
	//Add some loans to the sets
	carLoans.add(*p1);

	//test to see if the same object is retrieved from the set.
	cout << "\nTest for identity";
	if (p1 != &carLoans.removeSomeElement() )
		cout << "\nERROR: the objects are different ";
	else
		cout << "\nGood, the objects are the same ";
	cout << "\n----------------------------------------------------------\n";
	
	cout << "\nAdding " << *p1 << " to Car Loans";
	carLoans.add(*p1);
	cout << "\nAdding " << *p2 << " to Car Loans";
	carLoans.add(*p2);
	cout << "\nAdding " << *p3 << " to Other Loans";
	otherLoans.add(*p3);

	cout << "\nIn Car Loans: ";
	carLoans.add(*(new Loan("Anne", "76 Bronson Ave. Ottawa", Date(14,9,2006), 2000, 6.0, 12)));
	cout << "\nIn Car Loans: ";
	carLoans.add(*(new Loan("John", "90 Elgin St. Ottawa", Date(10,7,2005), 12000, 6.0, 48)));
	cout << "\nIn Car Loans: ";
	carLoans.add(*(new Loan("Mary", "14 Scott St. Ottawa", Date(10,7,2005), 15000, 6.0, 60)));

	cout << "\nIn Other Loans: ";
	otherLoans.add(*(new Loan("Dave", "34 Colonel By. Ottawa", Date(10,7,2005), 12000, 6.0, 48)));
	cout << "\nIn Other Loans: ";
	otherLoans.add(*(new Loan("Louis", "14 Scott St. Ottawa", Date(10,7,2005), 15000, 6.0, 60)));


	//print all the car loans using the removeSomeElement() method and delete them
	int numberOfCarLoans = carLoans.size();
	cout << "\nnumber of car loans = " << numberOfCarLoans << "\n";
	for(int i = 0; i<numberOfCarLoans ; i++) {
		Loan & aLoan = carLoans.removeSomeElement();
		cout << "\n\n" << aLoan ;
		delete &aLoan;
	}


	//print the loans using the << operator of the SetOfLoans class
	cout << "\n\nnumber of other loans = " << otherLoans.size() << "\n";
	cout << "\n" << otherLoans << "\n";
	//print of the loans balances and using the someElement() method
	cout << "\nBalances";
	cout << "\n==========\n";
	int numberOfLoans = otherLoans.size();
	for(int i = 0; i<numberOfLoans; i++){
		cout << "\n" << otherLoans.someElement().getBalance();
	}

	//delete all the loans from the heap
	cout << "\n\nDeleting Other Loans";
	cout << "\n======================\n";
	numberOfLoans = otherLoans.size();
	for(int i = 0; i<numberOfLoans; i++) {
		Loan & aLoan = otherLoans.removeSomeElement();
		delete &aLoan;
	}

	cout << "\n\n";
} //end of main 