Lab for Bubble Sort Algorithm - Application Programming | IST 256, Lab Reports of Information Technology

Material Type: Lab; Class: Application Programming for Information Systems; Subject: Information Studies; University: Syracuse University; Term: Fall 2008;

Typology: Lab Reports

Pre 2010

Uploaded on 08/09/2009

koofers-user-diu
koofers-user-diu 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
IST 256
Lab Week 15, Part 2 – December 3, 2008
1a. Write the piece of code that would declare a two-dimensional array of strings with 9
rows and 15 columns.
1b. Write the piece of code that would assign an empty string to each element of the two-
dimensional array declared in the previous question. Use two nested For loops; you do
not have to show the declarations of the index variables.
2. Suppose that we have a record structure that has a field called “name” of type String
and a field called “age” of type Integer, and a one-dimensional array of 12 elements that
are records. The record structure and the array are declared as follows:
Private Structure personrecord
Dim name as String
Dim age as Integer
End Structure
Dim persons ( 0 to 11 ) as personrecord
Assume that all 12 elements of the array have already been defined (by reading from a
file, for example). Write the code that would compute the average of all the values in the
age field in the array.
pf2

Partial preview of the text

Download Lab for Bubble Sort Algorithm - Application Programming | IST 256 and more Lab Reports Information Technology in PDF only on Docsity!

IST 256

Lab Week 15, Part 2 – December 3, 2008

1a. Write the piece of code that would declare a two-dimensional array of strings with 9 rows and 15 columns.

1b. Write the piece of code that would assign an empty string to each element of the two- dimensional array declared in the previous question. Use two nested For loops; you do not have to show the declarations of the index variables.

  1. Suppose that we have a record structure that has a field called “name” of type String and a field called “age” of type Integer, and a one-dimensional array of 12 elements that are records. The record structure and the array are declared as follows:

Private Structure personrecord Dim name as String Dim age as Integer End Structure

Dim persons ( 0 to 11 ) as personrecord

Assume that all 12 elements of the array have already been defined (by reading from a file, for example). Write the code that would compute the average of all the values in the age field in the array.

  1. Suppose that we want to write a Procedure that swaps two variables of type integer. Here is the procedure header: Private Sub swap(ByRef x as Integer, ByRef y as Integer) Write the rest of the procedure, that is, give the code that will swap the two variables x and y:
  2. Suppose that we have an array with 5 elements that is declared and initialized as follows: Dim numbers ( 0 to 4 ) as Integer numbers(0) = 24 numbers(1) = 81 numbers(2) = 23 numbers(3) = 18 numbers(4) = 32

Suppose that this program also has a version of the bubble sort that uses the above procedure to swap the array elements. Dim i, j as Integer

For i = 0 To 3 // if array has n elements, number of passes is n- For j = 0 To (3 – i) // number of comparisons If numbers(j) > numbers (j + 1) Then Call swap (numbers (j), numbers (j+1)) End If Next Next

Show the order of these array elements after the first, second and third passes of the bubble sort algorithm.

Initial value After 1st^ pass (i=0)

After 2nd^ pass (i=1)

After 3rd^ pass (i=2) numbers(0) numbers(1) numbers(2) numbers(3) numbers(4)