예제 #1
0
        /// Deletes a targetInt objects at the given index and returns the
        /// objectID for the object that was just deleted
        ///
        /// Preconditions:
        ///     There need to be at least one object in the array
        ///
        ///  Postconditions:
        ///     currentSize will decrease by one and stats_size will increase
        ///     by one
        ///
        ///  Invariant(s):
        ///     currentSize and stats_size will never be greater than ARR_SIZE
        ///
        ///State will change to empty if currentSize = 0
        public int delete(int index)
        {
            targetInt[] temp  = new targetInt[currentSize - 1];
            int         count = 0;

            for (int i = 0; i < currentSize; i++)
            {
                if (i != index)
                {
                    temp[count] = new targetInt(array[i]);
                    count++;
                }
                else
                {
                    statsArray[stats_size] = new targetInt(array[i]);
                    stats_size++;
                }
            }
            Array.Resize(ref array, currentSize - 1);

            for (int i = 0; i < (currentSize - 1); i++)
            {
                array[i] = new targetInt(temp[i]);
            }

            currentSize--;

            if (currentSize == 0)
            {
                empty = true;
            }

            return(statsArray[stats_size - 1].getobjectID());
        }
예제 #2
0
 public targetInt(targetInt t)
 {
     numGuess   = t.numGuess;
     highGuess  = t.highGuess;
     lowGuess   = t.lowGuess;
     avgGuess   = t.avgGuess;
     objectID   = t.objectID;
     numToGuess = t.numToGuess;
     total      = t.total;
     known      = t.known;
 }
예제 #3
0
        private bool empty;             //determines whether array is empty or not

        //constructor
        public randomTargets(int size, int[] arr)
        {
            array      = new targetInt[size];
            statsArray = new targetInt[size];

            for (int i = 0; i < size; i++)
            {
                array[i] = new targetInt(arr[i], (i + 1));
            }

            currentSize = size;
            stats_size  = 0;
            empty       = false;
        }
예제 #4
0
        /// Returns object with the greatest number of high guess and the object
        /// with the greatest number of low guesses
        ///
        ///
        /// <param name="r"></param>
        static void stats(randomTargets r)
        {
            targetInt temp  = new targetInt(r.findHighGuesses());
            targetInt temp2 = new targetInt(r.findLowGuesses());

            WriteLine("Greatest # of high guesses: Object " + temp.getobjectID());
            WriteLine("--------------------------------------");

            WriteLine("# of guesses: " + temp.getnumGuess());
            WriteLine("# of high guesses: " + temp.gethighGuess());
            WriteLine("# of low guesses: " + temp.getlowGuess());
            WriteLine("Average guess: " + temp.getavgGuess());
            WriteLine("\n");

            WriteLine("Greatest # of low guesses: Object " + temp2.getobjectID());
            WriteLine("--------------------------------------");

            WriteLine("# of guesses: " + temp2.getnumGuess());
            WriteLine("# of high guesses: " + temp2.gethighGuess());
            WriteLine("# of low guesses: " + temp2.getlowGuess());
            WriteLine("Average guess: " + temp2.getavgGuess());
            WriteLine("\n");
        }