

//  MAIN.CC    
//
//  This is the main file for our first programming assignment, prog 1 HW 2, CS 222/420 
//  Fall 98.  It creates an object, Pool, of class "sortedArray" of individuals, and then
//  goes into a loop, each time through asking the console user to do a member check, or
//  print the pool, or check the size, etc.  Use, modify, etc. to test your code.


typedef enum boolean {FALSE,TRUE} BOOLEAN;   //  Have to make our own BOOLEAN type for C/C++  
const int CHROMLENGTH = 12;                   //  For now, fix chromosome length to 8 bits
static int count = 0;


#include <iostream.h>
#include <fstream.h>
#include <math.h>

#include "individual.cc"                       //  These files contain class def.ns for us
#include "sortedarray.cc"



void main() { 
        SortedArray Pool;                       //   The pool of all chromosomes
        char operation = 'f'; 
        int i, position; 
        Individual who;                         //   An individual from console user, to be
        char tempchar;                          //   searched for in Pool.
        

while (operation != 'q') 
  { 
   cout << "\n Enter your choice: (m)ember, (w)here, (p)rint all, (s)ize of array, or (q)uit:  "; 
   cin  >> operation; 
   if (operation == 'm' || operation == 'w' ) 
      { 
       cout << "Please enter a chromosome:    "; 
       for (i = 0; i < CHROMLENGTH; i++)
          {
            cin >> tempchar;
            if(tempchar == '0')
               who.chromosome[i] = FALSE;
               else who.chromosome[i] = TRUE;
          };
      }; 
       cout << "\n"; 
   switch (operation) 
    { 
     case 'm':                       //  Search for a chromosome in Pool, and return T,F. 
       if(Pool.Member(who)) 
         {cout << "\n Yes, it has been seen.\n";} 
         else cout << "\n No, it has not been seen.\n"; 
       break; 
     case 'w':                      //  Search for a chromosome in Pool and return
       position = Pool.IndexOf(who);           // its location (index). 
       cout << "\n It is in position "  << position << " in the pool..\n"; 
       break; 
     case 'p':                      //  Print all chroms in Pool, to console, one chrom per line.
       Pool.printEveryone();
       break;
     case 's':                        //  Print current length of the array (number of chroms)
       Pool.totalnumber();
       break;
     case 'q':                       
       break; 
     default : 
       cout<< "\n INPUT ERROR:  PLEASE CHOOSE ONE OF THE AVAILABLE COMMANDS! \n"; 
       break; 
     } 
  } 
} 

