c14_ps06_sol

C14_ps06_sol - C-14 Solutions 1 Package Design Data Structures An array of nine integers Subprograms Function to accept 9 integers Procedure to

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: C-14 Solutions 1. Package Design Data Structures An array of nine integers Subprograms Function to accept 9 integers Procedure to display the array in row major order Procedure to display the array in column major order Procedure to sort the array using the bubble sort algorithm Algorithms Accept_Numbers: For I in 1 .. 9 Accept an integer Store it in an array Row_Major_Display: For I in 1 .. 9 Display Element in Array(I); If I mod 3 = 0 then New_Line Given the elements are in row-major order, the position locations are sequential. Column_Major_Display: For I in 1 .. 3 For J in 1 .. 3 Location_In_Array := I + (J-1)*3 Display Element in Array(Location_In_Array) New_Line If the elements are in column-major order, the locations in the one-dimensional array have to be computed. Bubble_Sort: For I in 1 .. Array’Value(1)-1 For J in I+1 .. Array’Value(1) If Array(I) > Array(J) Swap the values Note that the algorithm will sort the array in ascending order. 2. Code Listing Package Listing Package Specification GNAT 3.13 p ( 20000509 ) Copyright 1992- 2000 Free Software Foundation, Inc. Checking: c:/docume~ 2 /joeb/desktop/ 16070 /codeso~ 1 /my_array_package.ads (source file time stamp: 2003- 10- 08 13 : 48 : 58 ) 1 . ----------------------------------------- 2 . -- Package specification of a package to...
View Full Document

This note was uploaded on 01/28/2012 for the course AERO 16.01 taught by Professor Markdrela during the Fall '05 term at MIT.

Page1 / 4

C14_ps06_sol - C-14 Solutions 1 Package Design Data Structures An array of nine integers Subprograms Function to accept 9 integers Procedure to

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