13 - data representation Flashcards
user defined data type
a data type based on an existing data type or other data types that have been defined by a programmer
why use user defined data types
- built in types arent sufficient to represent data
- store data of same or diff types (flexible)
- can be encapsulated which ensures consistency and uniformity
- Can be reused
non-composite data type
a data type that doesnt reference other data types
eg enumerated, pointer
enumerated data type
non composite data type
defined by a list of all possible values with an implied order
eg TSeasons = (Spring ,Summer, Autumn, Winter)
DECLARE thisSeason : TSeasons
TYPE <identifier> = (value1, value2, value3...)</identifier>
pointer data type
non composite
references a memory location
TYPE <pointer> = ^<Typename>
eg TYPE TmonthPointer = ^Tmonth
DECLARE monthPointer : TmonthPointer</Typename></pointer>
set data type
composite
- a list of unordered elements that can use set theory operations eg intersection, union, difference
- Contains values that are not organised
- Cant have duplicate values
TYPE <set> = SET OF <basetype>
DEFINE <identifier> (value1, value2...) : <set>
eg TYPE Sletter = SET OF CHAR
DEFINE vowel ('a', 'e', 'i', 'o', 'u') : letters</set></identifier></basetype></set>
composite data type
uses multiple built in data types
eg record, class, set
record data type
TYPE <idenfiier>
DECLARE <identifier> : STRING
....</identifier></idenfiier>
class data type
composite
includes variables of given data types and methods
an object is defined from a class
serial files
records of data are stored in a file, one after another, in the order they were added to the file
- new records appended to the end
eg meter readings, customer transactions
sequential files
records of data are stored in a file, one after another, in a given order (defined by the key field)
eg store all bank transactions
random files
records of data are stored in a file in any available position
the location of any record in the file is found by using a hashing algorithm on the key field of a record
hashing algorithm
mathematical formula used to perform a calculation on the key field of the record;
the result of the calculation gives the address where the record should be found
hasing collision
eg hash is to divide by 100
102 and 202 will give the same remainder so there is a collision
deal with it by:
- open hash - using the next free space
- closed hash - using the next free space in a give pre set up overflow area
when reading records if key fields dont match when the hash is calculated then all following records need to be read or the overflow area needs to be searches
sequential access
records are searched one after another
from the physical start of the file until the required record is found
- used when every record needs to be processed
direct access
a record can be physically found in a file without physically reading other records
- used to find records quickly when an individual record needs to be processed
use hashing or index table
file access
the method used to physically find a record in the file.
- sequential
- random
mantissa
fractional part of floating point num
exponent
the power of 2 that the mantissa is raised to
binary floating point number
a binary number in the form M*2^E
M- mantissa
E - exponent
overflow
the result of carrying out a calculation which produces a value too large for the computer’s allocated word size
underflow
the result of carrying out a calculation which produces a value too small for the computer’s allocated word size.
converting to floating point
convert to binary
shift to have 1.0 or 0.1 (mantissa)
exponent = amount shifted by
to convert back take exponent and convert - shift by that amount
then convert mantissa to denary
fixed point number
- overall number of bits chosen with a defined number for the whole part + remainder for fractional part
- MSB for sign, next 5 for whole number, last two for fractional part
- Eg 011111.11 = 37.75 - largest possible value
Eg 000000.01 = 0.01 0.25 - smallest positive value
rounding errors
some numbers can only be represented as an approximate value (accuracy of which determined by no. b in mantissa)
eg 0.1 will lead to a rounding error has its impossible to convert
reduce error by increasing size of mantissa
if you add rounded numbers it increases the error
normalisation
for a + num mantissa starts with 0.1
for a - num mantissa starts with 1.0
accuracy and range of numbers
accuracy is increases by increasing no b for mantissa
range of numbers is increases by increasing no b for exponent
both these increase storage needed
max/ min numbers using 8b 8b (when normalised)
max positive
01111111 01111111
min positive
01000000 10000000
min negative
10111111 10000000
max negative
10000000 01111111