arrays sort eas230

arrays sort eas230 - break; } default: return 0; } // end...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <string> using namespace std; //Functions - int presentMenu( ); void printAnyArray( char *anyArray[], int size ); void swapBirdArrayItems( int first, int second ); //Globals - const int arraySize = 8; char *birds[ arraySize ] = { "eagles", "hawks", "bluejays", "robins", "cardinals", "owls", "doves", "ducks" }; void main( ){ int x, y; // generic loopers int userChoice = 0; while (true ) { userChoice = presentMenu( ); switch (userChoice) { case 1: { cout << endl << "Our bird list: " << endl; printAnyArray( birds, arraySize ); break; } case 2: { // alphabetize: for (x=0; x<arraySize; x++) { for (y = x+1; y<arraySize; y++) { if (strcmpi( birds[x], birds[y] ) > 0)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
{ swapBirdArrayItems( x, y ); } // end if } // end for y } // end for x printAnyArray( birds, arraySize );
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: break; } default: return 0; } // end switch } // end while( true ) } // end main int presentMenu( ) { int selection = 0; cout &lt;&lt; &quot;**************&quot; &lt;&lt; endl; cout &lt;&lt; &quot; 1. Print Bird List &quot; &lt;&lt; endl; cout &lt;&lt; &quot; 2. Sort Alphabetically &quot; &lt;&lt; endl; cout &lt;&lt; &quot; 3. Exit &quot; &lt;&lt; endl; cout &lt;&lt; &quot;--------------&quot; &lt;&lt; endl; cout &lt;&lt; &quot; Enter choice: &quot;; cin &gt;&gt; selection; return selection; } void printAnyArray( char *anyArray, int size ) { for (int a = 0; a&lt;size; a++) { cout &lt;&lt; &quot; &quot; &lt;&lt; anyArray[ a ] &lt;&lt; endl; } cout &lt;&lt; endl &lt;&lt; endl; } // end function void swapBirdArrayItems( int first, int second ) { char *temp; temp = birds[ first ]; birds[ first ] = birds[ second ]; birds[ second ] = temp; } // end function swapArrayItems...
View Full Document

Page1 / 3

arrays sort eas230 - break; } default: return 0; } // end...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online