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