// This program demonstrates that a pointer may be used as a \
// parameter to accepts the address of an array 
#include <iostream>
#include <iomanip>
using namespace std;

// Funtion prototype 
void getSales(double *, int);
double totalSales(double *, int);

int main()
{
    const int QTRS = 4;
    double sales[QTRS];
    
    // Get the sales data for all quarter
    getSales(sales, QTRS);
    
    // Set the numeric output formatting 
    cout << fixed << showpoint << setprecision(2);
    
    // dispaly the total sales for the year 
    cout << "The total sales for the year are $";
    cout << totalSales(sales, QTRS) << endl;
    return 0;
}

//*******************************************************************
// definition of getSales. This function uses a pointer to accepts  *
// the address of an array of doubles. the function asks the user   *
// to enter sales figures and stores them in the array              *
//*******************************************************************

void getSales(double *arr, int size)
{
    for (int count = 0; count < size; count++)
    {
        cout << "Enter the sales figure for quarter ";
        cout << (count + 1) << ": ";
        cin  >> arr[count];
    }
}


//*******************************************************************
// definition of totalSales. this function uses a pointer to        *
// accept the address of an array. the function returns the total   *
// of the elements in the array                                     *
//******************************************************************* 

double totalSales (double *arr, int size)
{
    double sum = 0.0;
    
    for(int count = 0; count < size; count++)
    {
        sum += *arr;
        arr++;
    }
    return sum;
}