//**************************************************************
//
//  CS 240B   Winter Quarter 2003 Ohio University Travis Dillon
//  Proj2   : Array Workshop
//  file    : fill.cc  
//  started : 01-16-03
//
//**************************************************************

#include "search_sort.h"
#include "prog2.h"
#include "menu_print.h"
#include "fill.h"

void by_hand(int x[],int array_sz)
{
   for(int i = 0;i < array_sz; i++)
   {  //input from keyboard of each array element
      cout<<"Enter number " << i <<" in the array:  ";
      cin >>x[i];
   }
   cout<<endl;
}

void arith_progr(int x[],int array_sz)
{
   int s;
   int i;
   
   cout<<"\nEnter start number for the array:  ";
   cin >>s;
   cout<<"Enter the amount of increment:  ";
   cin >>i;
   //start at s and increment additional numbers by i
   for(int j=0; j < array_sz; j++)
   {
      x[j] = s + (i * j);
   }
   cout<<endl;
}

void fibonacci(int x[],int array_sz)
{
  x[0] = 1;
  x[1] = 1;
  //fill array with a[n] = a[n-1] + a[n-2]
  for(int j(2); j < array_sz; j++)
  {
     x[j] = x[j-1] + x[j-2];
  }
}

void random(int x[],int array_sz)
{
   static int lo(1);
   static int hi(10);
   char ans;
   bool done = false;
   
   while (!done)
   {
      cout<<"\nArray Workshop.";
      space(4);
      cout<<"Random Fill Menu";
      space(4);
      cout<<"low range = " <<lo;
      space(4);
      cout<<"high range = " <<hi <<endl;
      cout<<"\nchoose a fill method\n";
      cout<<"\n F       fill array";
      cout<<"\n L       adjust low range";
      cout<<"\n H       adjust high range";
      cout<<"\n X       return to fill menu without filling array";
      cout<<"\n\n   Enter choice of tasks in < F, L, H, X > :  ";
      cin >>ans;
      cout<<endl;
      
      switch(ans)
      {
         case'X':  //exit menu command
         case'x':  done = true;
            break;
         
         case'F':  //fill with random numbers
         case'f':  for(int j(0); j < array_sz; j ++)
                   {
                      do  //get random value from low to high
                      {
                         x[j] = rand();
                      }while((x[j] > hi) || (x[j] < lo));
                   }
                   done = true;
            break;
         
         case'L':  //change low value
         case'l':  cout<<"Enter new low range:  ";
                   cin >>lo;
            break;
         
         case'H':  //change high value
         case'h':  cout<<"Enter new high range:  ";
                   cin >>hi;
            break;
         
         default:  cout<<"\a" <<"\nInvalid choice.  Choose again.\n";
            break;
      }
   }         
}

void set_size(int x[], int& array_sz)
{
   cout<<"\nArray Workshop.";
   space(4);
   cout<<"Set Size Menu";
   space(4);
   cout<<"low range = " <<MIN_ARRAY_SIZE;
   space(4);
   cout<<"high range = " <<MAX_ARRAY_SIZE <<endl;
   
   do  //change the active portion of the array
   {
      cout<<"\nEnter new active array size between low and high range:  ";
      cin >> array_sz;
   }while((array_sz < MIN_ARRAY_SIZE)||(array_sz > MAX_ARRAY_SIZE));
}