/* Depreciation.cpp defines depreciation functions.
 * ...
 */

#include <iostream>       // cout
#include <iomanip>        // setprecision(), setw(), setiosflags()
#include <cassert>        // assert()
using namespace std;

#include "Depreciation.h"

// -----------------------------------------------

void straightLine(double amount, int numYears)
{
   double depreciation = amount / numYears;

   cout << "\nYear -  Depreciation"
        << "\n--------------------\n";

   cout << fixed << showpoint << right       // set up format for $$
        << setprecision(2);

   for (int year = 1; year <= numYears; year++)
      cout << setw(3) << year
           << setw(13) << depreciation << endl;
}

// -----------------------------------------------

void sumOfYears(double amount, int numYears)
{
   cout << "\nYear -  Depreciation"
        << "\n--------------------\n";

   double yearSum = sum(numYears);

   double depreciation;

   cout << fixed << showpoint << right       // set up format for $$
        << setprecision(2);

   for (int year = 1; year <= numYears; year++)
   {
      depreciation = (numYears - year + 1) * amount / yearSum;
      cout << setw(3) << year
           << setw(13) << depreciation << endl;
   }
}

// -----------------------------------------------

int sum (int n)
{
   assert(n > 0);

   return n * (n+1) / 2;
}
