Assignment 5
Seperate Header and Implementation
Date Due:  February 27, 2001

Part I -- Sort Routine Module
  1. Create a C++ header file (*.h) that would contain
  2. Create the implementation (*.cpp) file that would implement the above functions and procedures.
Part II -- Main Program using the Sort Routine Module
The main program should perform the following functions:
  1. Input from the user the name of the output file.
  2. Input from the user the number of elements to be created and sorted.
  3. Test an unsorted array for being sorted using IsSorted.  Print the results of the test on the output file.
  4. Time the sorting of a random real array using the Bubble sort.
  5. Test the results for the bubble sort for being sorted using IsSorted.
  6. Print the time of the bubble sort on the output file.  It should read something like

  7. "The time needed to sort 3000 real numbers using the bubble sort is 45 seconds".  (note the values should come from your program.)
  8. Repeat steps 4, 5 & 6 for the insert sort on a real array, the bubble sort on an integer array and the insert sort on an integer array.

  9.  
  10. Execute the program.  Enter a number of elements for which the time of the insert sort on an integer array is between 5 and 10 seconds.  The output file will be submitted as an attachment.
  11. Execute the program for a second time.  Enter a number twice your run of the first time.  Use a different output file name.  This output file will also be submitted as an attachment.
Note: Your source files must be properly documented.  This includes all *.h and *.cpp files.

When finished e-mail the following

  1. SortRoutine.h as an attachment
  2. SortRoutine.cpp as an attachment
  3. main program .cpp file as an attachment
  4. Two output text files as attachments.
The e-mail message must be made to albert@CrawfordEnterprise.com
The subject must be "CSC404, Assignment 5, C++ Module"
The "from" must be your own name and the reply address must be able to reach you.;

Note: If any one of the four files are not sent, and sent as an attachment, your score will be zero.
         If the subject and the "from" are not exactly correct your score will be zero.
         If your source code files will not compile and execute correctly your score will be zero.
 
 

Timing of an event

include the standard library time.h
declare two variables, say StartTime and EndTime, as unsigned long variables.
Use the function time(0) to get the current time.

Example

unsigned long StartTime, EndTime, ElapsedTime;

StartTime = time(0);     // get starting time
SomeKindOfSort(A, N);    // call procedure to be timed
EndTime = time(0);       // get ending time

ElapsedTime = EndTime - StartTime;  // calculate the number of seconds from start to finish.
 

Sample SortRoutines.h file

template <class ItemType>
void BubbleSort(ItemType [], long );
 

template <class ItemType>
void InsertSort(float [], long );
 

template <class ItemType>
bool IsSorted(float [], long );

#include "SortRoutines.cpp"
 

Sample SortRoutines.cpp file

template <class ItemType>
void BubbleSort(ItemType A[], long N)
{ for(int pass = 1; pass < N; pass++)
    for (int J = 1; J < N; J++)
      if (A[J-1] > A[J])  // change > to < to go from largest to smallest
        {ItemType Temp = A[J-1];
         A[J-1] = A[J];
         A[J] = Temp;
         }
}

template <class ItemType>
void InsertSort(ItemType A[], long N)
{ for (int pass = 1; pass < N; pass++)
    { ItemType Temp = A[pass];
      int J = pass;
      while( (J > 0) && (A[J-1] > Temp)) // change < to > for smallest to largest
        {A[J] = A[J-1];
         J--;
        }
      A[J] = Temp;
    }
}
 

template <class ItemType>
bool IsSorted(ItemType A[], long N)
{ bool Sorted = true;
   for (int J = 1; J<N; J++)
      if (A[J-1] > A[J])
          Sorted = false;
   return Sorted;
}