VRS

Data Types


Definition

A data type is a formal description of the kind of data used in a computer program.


Why do we need data types?

How an item of data is stored an manipulated within a program depends on it's data type. It allows the computer to allocate memory according to data type


Declaring variables

This is when the locations for storing specific data are created and initialised. When declaring a variable there are two bits of information which need to be supplied, in most languages:


Common data types




Data Structures


Definition

These ate methods of storing more than one item of data together under a single identifier


There are two main ways of doing this, using either records or arrays.


Arrays

An array contains several items of similar data.

An array contains a number of elements, which are the items of data.

They must all be of the same data type.

Therefore they take up the same space in memory, and can be stored next to each other.

An array has an index containing a list of the addresses of all the elements.

The lowest and highest values of the index are the bounds of the array.

It is also possible to have multi-dimensional arrays.


Advantages of arrays:


Records

Records can be used to store several different data items of different types but all related to one thing, like details on a particular customer.

The individual items inside a record are called fields.



File Organisation

How records are organised into files.


Serial file

In a serial file the data is stored in the order it arrives.

New data is added to the end of the file

This is called appending

To delete an item of data:

To search for an item of data:


Sequential File

The data is stored according to a key field in the data.

A key field in each record can be used to identify that record

To add a new item into a record:

Deleting from a sequential file is the same as deleting from a serial file


Indexed Sequential Files

A sequential file where the data is arranged according to a key field in the record, but also has an index that allows records to be found directly.

This is useful where sometimes it is necessary to process all records in sequential order, or if you want to look up an individual record the index can be used.


Direct Access Files

If the records in a sequential file have a fixed length, it can be possible to read the contents of the file from knowing it's position.


Random Files

Where the data can be stored anywhere in a dedicated area of the disk, depending on the result of a calculation called a hash algorithm.



Estimating the Size of a File

  1. Determine the size of each field in the record in bytes

  2. Add the field sizes to calculate the size of one record

  3. Multiply the size of one record by the size of one record by the number of records in the file

  4. Add 10% on for overheads

  5. Divide by 1000 to get kb, 1000 again for mb and so on



Title


Data Types and Data Structures.html

Type


web

Download


Back


Switch to New Version