{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Assignment 8

Assignment 8 - For maxElement = arraySize – 1 To =...

This preview shows pages 1–2. Sign up to view the full content.

CIS 110 David Kegler 6/8/2011 Assignment 8 Module Main () //Declare constants for the array size Constant Integer SIZE = 10 //Golf score array getGS (GS, SIZE) //For sorting the golf scores bubbleSort (GS, SIZE) //Golf score display Display “Here are your golf scores” Display “sorted from lowest to highest” showGS (GS, SIZE) End Module //The GS module prompts the user to enter the golf scores Module GS(Integer Ref array[], Integer arraySize) //Counter variable Declare Integer index //Get the golf scores For index = 0 to arraySize – 1 Display “Please enter your score”, index + 1 Input array[index] End For End Module //The bubblesort module accepts and sorts the user inputs Module bubbleSort(Integer Ref array[], Integer arraySize) //The maxElement variable will contain the subscript of the last element in the array to compare Declare Integer maxElement //The index variable will be used as a counter in the inner loop Declare Integer index

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: For maxElement = arraySize – 1 To = Step -1 //The inner loop steps through the array, comparing each element For index = 0 To maxElement – 1 //Compares each element with its neighbor and swaps if necessary If array[index] > array[index + 1] Then Call swap(array[index, array[index + 1]) End If End For CIS 110 David Kegler 6/8/2011 Assignment 8 End For End Module //The swap module accepts two Integer arguments and swaps their contents Module swap(Integer Ref a, Integer Ref b) //Local variables for temp storage Declare Integer temp //Swap the values a and b Set temp = a Set a = b Set b = temp End Module //The showGS module displays the contents of the array that is passed as an argument. Module showGS(Integer array, Integer arraySize) //Counter variable Declare Integer index //Display the golf scores For index = 0 to arraySize – 1 Display array[index] End For End Module...
View Full Document

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern