pset6_sol

pset6_sol - C-14 Solutions 1. Package Design Data...

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

View Full Document Right Arrow Icon
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.
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 3 . -- 1. Create an array of 9 integers 4 . -- 2. Display the array as a 3x3 matrix 5 . -- i. assuming row-major order 6 . -- ii. assuming column-major order 7 . -- 3. Bubble Sort the 1-D array 8 . -- 9 . -- Specifier : Joe B 10 . -- Date Last Modified : 10/07/03 11 . ----------------------------------------- 12 . 13 . package My_Array_Package is 14 . 15 . type My_Array is array ( 1 .. 9 ) of Integer; 16 . 17 . 18 . function Create_Array return My_Array; 19 . 20 . procedure Display_Row_Major(Input_Array : in My_Array); 21 . 22 . 23 . procedure Display_Column_Major(Input_Array : in My_Array); 24 . 25 . 26 . procedure Bubble_Sort (Input_Array : in out My_Array); 27 . end My_Array_Package; 28 . 29 . 29 lines: No errors Package Body GNAT 3.13 p ( 20000509 ) Copyright 1992 - 2000 Free Software Foundation, Inc. Compiling: c:/docume~ 2 /joeb/desktop/ 16070 /codeso~ 1 /my_array_package.adb (source file time stamp: 2003 - 10 - 08 13 : 54 : 40 ) 1 . --------------------------------------------- 2 . -- Package implementation of My_Array_Package 3 . -- Programmer : Joe B
Background image of page 2
5 10 15 20 25 30 35 40 45 50 55 60 4 . -- Date Last Modified : 10/07/03 . -------------------------------------------- - 6 . 7 . with Ada.Text_Io; 8 . with Ada.Integer_Text_Io; 9 . . package body My_Array_Package is 11 . 12 . 13 . function Create_Array return My_Array is 14 . Output_Array : My_Array; . begin 16 . for I in 1 .. 9 loop 17 . Ada.Text_Io.Put( "Please Enter a number : " ); 18 . Ada.Integer_Text_Io.Get(Output_Array(I)); 19 . Ada.Text_Io.New_Line; . end loop ; 21 . return Output_Array; 22 . end Create_Array; 23 . 24
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the 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 / 16

pset6_sol - C-14 Solutions 1. Package Design Data...

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

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