Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CONVERTING PROGRAM TO TEMPLATE FUNCTION. PLEASE HELP!!

Status
Not open for further replies.

DonCL

Programmer
Jul 16, 2001
43
US
Hello, I really need help with this program. There are three parts, which i am having a problem understanding. If anyone has any suggestions or solutions, i would really appreciate it. Thanks. Here it is:

A driver generates two different arrays (integers and float numbers) and calls template function. Then it puts sorted arrays in a file.

a. Input Phase: within the driver, use a random generator to generate 100 integers and 100 float numbers (w/ single decimal).

b. Processing Phase: convert the following program to template function:
// This program puts values into an array, sorts the values into ascending order, and proints the resulting array.

#include <iostream>
using std::cout;
using std::endl;
#include <iomanip>
using std::setw;

void bubbleSort( int*, const int);

int main()
{
const int arraySize=10;
int a[arraySize] = {2,6,4,8,10,12,89,68,45,37};
int i;
cout << &quot;Data items in original order\n&quot;;
for (i=0; i<arraySize; i++)
cout << setw(4)<< a;
bubbleSort(a, arraySize); //sort the array
cout << &quot;\nData items in ascending order\n&quot;;
for (i=0; i<arraySize; i++)
cout << setw(4) << a;
cout << endl;
return 0;
}

void bubbleSort(int *array, const int size)
{
void swap (int *const, int *const);
for (int pass = 0; pass < size - 1; pass++)
for int j=0; j< size -1; j++)
if (array[j] > array[j+1])
swap( &array[j], &array[j+1]);
}

void swap (int *const element1Ptr, int *const element2Ptr)
{
int hold = *element1Ptr;
*element1Ptr = *element2Ptr;
*element2Ptr = hold;
}
_______
c. Output phase: a file created by driver contains with 100 sorted integers and 100 sorted float numbers.


Thanks to all for your help!!!
 
see in MicrosoftC++ forum John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top