S215   11 0921

Lab KI21-30 Three-Dimensional Array
15 points

ELT 215

Back to Main Page

Below is some partial code for the primary loop of  a program that will display elements from a three-dimensional array. This array has 2 rows and 3 columns, and inside each "slot" specified by a row and a column, there are 4 elements (numbers).

A function in our library called TDArray will get a particular element from a three-dimensional array. We need to send a row number, column number, and element number to the TDArray function. Once TDArray has gotten a number from the array, we send it to DispFP, which will display the number in the alphanumeric display.

Your job is to write code that will do the following:
  1. Get row number, column number, and element number from the switches.
    • You'll need to use the bitwise AND operator (&) and the right-shift operator (>>) to do this.
  2. Check for numbers that are too large. If a number is too large, a while loop will keep checking the switches until a valid number is put into them.
Before you start writing code,  do the following:

  1. Download the partial program by right-clicking here.
  2. Download s215-library23-f46-d.lib and  s215-header23-f46-NWDT.h
    • This new library file contains TDArray and some other new functions.
  3. In the window labeled s215-workspace-f46-d.mcw, remove the old library 22 file, and add the new library 23 file.














/*
Switches 7 and 6 select the row.
Switches 3 and 2 select the column.
Switches 1 and 0 select the element.

|   7  |   6  |   5  |   4  |   3  |   2  |   1  |   0  |
|<=== Row ===>|             |<==== Col ==>|<== Element=>|  
*/

row = Put switches 7 and 6 into row
column = Put switches 3 and 2 into column.
element = Put switches 1 and 0 into element.

//If "row" is too large, display "Error" and keep getting
//
numbers from switches 7 and 6 until "row" contains a number
//that's OK.
while (row > 1)
{   Error();
    row = 
Put switches 7 and 6 into row
}

//If "column" is too large, display "Error" and keep getting
//
numbers from switches 3 and 2 until "column" contains a 
//
number that's OK.
while (          )
{  

}

//If "element" is too large, display "Error" and keep getting
//
numbers from switches 1 and 0 until "element" contains a
//number that's OK.
while (          )
{  

}

number = TDArray(row, column, element, XARRAY);
DispFP(number, 0);


 
Back to Main Page