Monday, May 24, 2010

C++: How would I find the 5 middle numbers in a group of 7 numbers and then have the program arrange them in?

order from lowest to greatest of the 5 middle numbers.





Example: 9.7, 8.6, 8.7, 8.6, 9.8, 5.9, 7.8


The middle numbers are: 5.9 7.8 8.6 8.6 8.7

C++: How would I find the 5 middle numbers in a group of 7 numbers and then have the program arrange them in?
Algorithm:





get the list


sort the list


pick off the first and last elements and display the rest





Program: all you need to do is fill in the function bodies :)





#include%26lt;iostream%26gt;


using namespace std;





void populateList(int [], int);


void sortList(int [], int);


void displayMiddle(int [], int);





int main(){


  int numEntries = 7;


  int * theList = new int[numEntries];


  populateList(theList, numEntries);


  sortList(theList, numEntries);


  displayMiddle(theList, numEntries);


  return EXIT_SUCCESS;


}





void populateList(int [] theList, int s){ // your code goes here }


void sortList(int [] theList, int s){ // your code goes here }


void displayMiddle(int [] theList, int s){ // your code goes here }

savage garden

No comments:

Post a Comment