how to pass a function to another function

im trying to pass two funtion one is call void sort arrys which would sort the arrays and the other is call void print arrays which would print arrays. so far i only mange to print out the unsorted arrays.

#include <iomanip>
#include <iostream>
#include <fstream>

using namespace std;
# define ARSIZE 30

int buildArrays( int[], int[], int[], double[] );
void printArrays( int[], int[], int[], double[], int );
void sortArrays( int[], int[], int[], double[], int );
string familyName( int);

int main()
{
 int family[ARSIZE], item[ARSIZE], quantity[ARSIZE];
 double price[ARSIZE], amount[ARSIZE]; 
 int sale, sort;
 
 float garageSale[ARSIZE];
 
 sale=buildArrays(family,item,quantity,price);
 
 printArrays(family,item,quantity,price,sale);
 
 

 

 
    
system ("pause");
return 0;
}

/***************************************************************
Function: buildArrays

Use:      read the file of data and fill the four arrays.

Arguments: 1t takes three integer array and one double array

Returns:   It returns the number of valid sales.
***************************************************************/
int buildArrays( int family[], int item[], int quantity[], double price[] )
	{
ifstream inFile;

int  holdVal,storeVal=0, numSales;

double holdNum; 

inFile.open( "data7.txt" );

if ( inFile.fail() )
   {
   cout << "input file did not open";
   exit(0);
   }
	
    inFile >> holdVal;


while (!inFile.eof())
	 {
     
     family[storeVal] = holdVal;
     
     inFile >> holdVal;
     
     item[storeVal] = holdVal;
     
     inFile >> holdVal;
     
     quantity[storeVal] = holdVal;
     
     inFile >> holdNum;
     
     price[storeVal] = holdNum;
     
     storeVal ++;
     
     inFile >> holdVal;
     
     }
              
    numSales = storeVal;	
 
inFile.close();

return   storeVal;
	}

/***************************************************************
Function: printArrays

Use:      display the information for the garage sale. 
		  For each sale, display the family name, item ID number, 
		  sale price for one item, quantity sold, and the amount of the sale.

Arguments: 1t takes an arguments of the four arrays and the number of elements in the arrays
           also one argument to calculate the sale amount.

Returns:   nothing, just print out the the display of the family name, item ID number, 
		   sale price for one item, quantity sold, and the amount of the sale.
***************************************************************/
void printArrays( int family[], int item[], int quantity[], double price[], int numSales )
	{
	
    
     
	
	cout << "                          Annual Garage Sale                                  " << endl;
	cout << endl;
	cout << "------------------------------------------------------------------------------" << endl;
	cout << "Family              Item Id #     Sale Price     Quantity Sold     Sale Amount" << endl;
	for(int i=0;i<numSales;i++)
		{
		int send;
		string name;
		double saleamount ;
		saleamount = price[i] * quantity[i];
	     
		name = familyName(family[i]);
		    
		cout <<left <<setw(10)<<name <<setw(15) <<right <<item[i]<<"          "<<price[i]<< "               " <<fixed <<showpoint<<setprecision(2)<<right<<quantity[i]  <<setw(15)<<saleamount  << endl;
		}
		
		
	}
/***************************************************************
Function: sortArrays

Use:      sort the arrays in ASCENDING order based on the family code.

Arguments: 1t takes an arguments of the four arrays and the number of elements in the arrays

Returns:   nothing just sort the arrays in ASCENDING order based on the family code.
***************************************************************/
void sortArrays( int family[], int item[], int quantity[], double price[], int numSales )
	{
	 int temp, topsub, lastsub, worksub, smallsub; 
	 double hold;
	 for (topsub=0;topsub < lastsub; topsub ++ )
     {
	     for (worksub = topsub, smallsub = topsub; worksub<=lastsub; worksub++)  
	     {
	     if (family[worksub] < family[smallsub])
	     smallsub = worksub;
	     }
     temp = family[topsub];   
     family[topsub]= family[smallsub];
     family[smallsub] = temp;
	 
	 temp = item[topsub];   
     item[topsub]= item[smallsub];
     item[smallsub] = temp;
	 
	 temp = quantity[topsub];   
     quantity[topsub]= quantity[smallsub];
     quantity[smallsub] = temp;
	 
	 hold = price[topsub];   
     price[topsub]= price[smallsub];
     price[smallsub] = hold;
	 
	 }
     

	}
/***************************************************************
Function: familyName

Use:      find a family name

Arguments: arguments a family code

Returns:   name of the family that corresponds with the integer code
***************************************************************/
string familyName( int familyCode )

{
string name;

	switch (familyCode)
	{
	case 0:
	name = "Drake";
	break;
	case 1:
	name = "Spencer";
	break;
	case 2:
	name = "Morgan";
	break;
	case 3:
	name = "Corinthos";
	break;
	case 4:
	name = "Webber";
	break;
	case 5:
	name = "Quartermaine";
	break;
	case 6:
	name = "Davis";
	break;
	default:
	name = "invalid";
	}
	
	return name; 
}

You are never calling sortArrays
Topic archived. No new replies allowed.