arrays sort eas230

arrays sort eas230 - break default return 0 end switch 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 << "**************" << endl; cout << " 1. Print Bird List " << endl; cout << " 2. Sort Alphabetically " << endl; cout << " 3. Exit " << endl; cout << "--------------" << endl; cout << " Enter choice: "; cin >> selection; return selection; } void printAnyArray( char *anyArray, int size ) { for (int a = 0; a<size; a++) { cout << " " << anyArray[ a ] << endl; } cout << endl << 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

This document was uploaded on 12/05/2011.

Page1 / 3

arrays sort eas230 - break default return 0 end switch 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