Please send questions to st10@humboldt.edu .
/*--------------------------------------------------
created by st10 at Mon Apr 23 10:34:32 PDT 2007
--------------------------------------------------*/
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;

/*--------------------------------------------------
 Contract: put_contents : double[] int char* -> bool
 Purpose: try to open file <outfile_name> for writing,
          and try to write the first <desired_size>
          values of array <contents> into <outfile_name>,
          one value per line. Return true if succeeded,
          and false if failed.

 Examples: if const int NUM_SCORES = 4; and
              double scores[NUM_SCORES] = {90, 80.5, 85.5, 99};
           then the call put_contents(scores, NUM_SCORES, "looky.txt")
           would result in a file named looky.txt in the current
           working directory with the following contents:
90
80.5
85.5
99
--------------------------------------------------*/
bool put_contents(double contents[], int desired_size,
                  char* outfile_name)
{
    double next_value;

    ofstream outstream;
    outstream.open(outfile_name);

    if (outstream.fail())
    {
        return false;
    }

    // can only reach here if COULD open file for writing...

    for (int i = 0; i < desired_size; i++)
    {
        outstream << contents[i] << endl;
    }

    outstream.close();
    return true;

}