Internal Code : MAS4870
C Programming Assignment
Programming Code : A function that takes a number and returns it with the desired number of decimal places e. g: round Value will result
FUNCTION roundValue(value, decimalPlaces)
i = 0
magnitude = 1
for i = 0 TO decimalPlaces
magnitude = magnitude * 10
End For
value = value * magnitude) / magnitude
return value
END FUNCTION
' ----------------------------------------------------
' Main
MAIN
' Constants
# Define the constant you will need and ensure they are intitialised.
# Use upper case to define the constants#define the valiables to store the Display Values and asscoiated data
DECIMAL_PLACES = 3
MAX_ROWS = 20
MAX_COLUMNS = 20
' Variables
# Define the variables to store the Range Values and asscoiated data
# Define the variables to store the Maps and asscoiated data
# Initialise the data
' Set up the range bounds
rangeValue(1) = 1
.
.
.
' Set Display values
displayValue(1) = 1
.
.
.
.
' Initialise data and maps to have default values
FOR rowIndex = 1 TO MAX_ROWS
FOR columnIndex = 1 TOMAX_COLUMNS
#intitialise the Map variables (Map Arrays)
END FOR
END FOR
' ------ READ DATA FROM FILE ----------------------------------------------
' Read and store the data in the approriate data variables
OPEN FILE_NAME
READ FILE_NAME INTO rawData
' ------- PRINT RAW DATA --------------------------------------------
' Print out the rawdata array
PRINT " --- RAW DATA ---" NEWLINE
FOR rowIndex = 1 TO MAX_ROWS
' Read up until the last value
FOR columnIndex = 1 TO MAX_COLUMNS
# Display the Raw Data to the screen
END FOR
PRINT NEWLINE
END FOR
' ------- SEARCH STORE AND ADJUST FOR ERRORS ------------------------
' Create the Error Map
FOR rowIndex = 1 TO MAX_ROWS
FOR columnIndex = 1 TO MAX_COLUMNS
value = roundValue(rawData(rowIndex , columnIndex), DECIMAL_PLACES)
# Check for value > top Range and set to limit and store the error
# Check for value < lowest Range and set to limit and store the error
END FOR
END FOR
' ------- CALCULATE AVERAGES -----------------------------------
' Calculate and store the averages for each range
FOR rowIndex = 1 TO MAX_ROWS
FOR columnIndex = 1 TO MAX_COLUMNS
value = roundValue(rawData(rowIndex , columnIndex), DECIMAL_PLACES)
' Compare the value with the range array to find the display value
FOR range = 1 TO MAX_RANGE
# Calculate and store the total and count for each range
END FOR
END FOR
END FOR
' Calculate and store the averages for each range
FOR range = 1 TO MAX_RANGE
# Calculate and store the average for each range
END FOR
' ------- CREATE THE CLASSIFICATION MAP --------------------------
' Create the Classification Map
FOR rowIndex = 1 TO MAX_ROWS
FOR columnIndex = 1 TO MAX_COLUMNS
value = roundValue(rawData(rowIndex , columnIndex), DECIMAL_PLACES)
' Compare the value with the range array to find the display value
FOR range = 1 TO MAX_RANGE
' If the value is in the range
# Determine and store the Display Value in the Classification Map
# Compare the value in the raw data to the range average and then determine if it is < or >= to that average and record the approriate Display Value
END FOR
END FOR
END FOR
# Print the Classification Map
# CREATE THE PATTERN MAP
# Print each value in our patternMap array to the console
# Print out our the range table and associated display value and counts
# Print errors
END MAIN