10.1 Data Types and Record

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 36

10.

1 Data Types and Records


Syllabus
Topic which we have to cover
Data Types and sizes
Literal
Declaration
identifier
Identifier table
Calculate file size
Records
Data types
• a classification attributed to an item of data, which determines the
types of value it can take and how it can be used.
• In pseudocode and some programming language, before data can be
used, the type needs to be decided.
Built in data types
Identifier
• A name given to a variable, function, procedure or a program.
• Each data item is identified by a unique name, called an identifier.
Naming convention
• Always start with alphabet, example: sum, average
• Do not use special characters and spaces. example :N#me, student ID
• Do not use keywords
• Name length up to 255 character
Assignment(=,)
• Assignment operator() is used in pseudocode.
• (=) is used in programming language.
• When a value is assigned to a variable an assignment symbol is used.
• Assignment is always performed right to left
• Example: a5 correct but 5a is not correct
Literals
• The value or data which is being assigned to an identifier.
Currency
Identifier Literals
Rate 13.17
Price 138.23
Amount 900.00
Fee 5000.00
INTEGER
Identifier Literals
Class 7
Count 12
Marks 89
REAL
Identifier Literals
Weight 65.3
Height 12.6
length 52.2
Speed 60.0
Distance 200.5
Temp 12.7
CHARACTER
Identifier Literals
Grade ‘C’
Quality ‘A’
Gender ‘M’
STRING
Identifier Literals
Name “Ali”
Address “house# 233, B/A ,latifabad / hyderabad”
ID “STD-26”
CNIC “23453-3452345-4”
BOOLEAN
Identifier Literals
examPassed #YES#
FeePaid #FALSE#
Married #NO#
DATE/TIME
Identifier Literals
DOB #15-Feb-2021#
dateOfjoining #15-Feb-2021#
departTime #12 PM#
deliveryTime # 23:54#
Variables
• Variables are containers for storing data values.
Declaration in Pseudocode
• In computer science, variable declaration means when programmer
wants to hold data in main memory.

• In pseudocode a declaration statement takes this form:


DECLARE <identifier> : <data type>
• For example:
DECLARE myBirthday : DATE
Declaration (VB)
• In VB a declaration statement takes this form:
Dim <identifier> AS <data type>
• For example:
Dim myBirthday AS DATE
Dim
• Dim stands for “Declare in memory”
• And it is a command for computers to find space in memory
myBirthday
• myBirthday is an identifier that is used to refer to the location of
found space.
Date
• It is a data type which is used to allocate space
Declaration (Python)
• Python has no command for declaring a variable.
• A variable is created the moment you first assign a
value to it.
• Example:
x = 5
y = "John"
DECLARATION
1. Finds enough space in RAM and hold it as required until the current
program is executed
2. It make sure that the data that is being assigned to the reserved
space is as per the defined format
3. It maps the reserved space address to the chosen identifier.
Initialization
• Whenever a new variable is declared , it occupies some space in
computer’s memory
• This occupied space might already have some data from the previous
program loaded there.
• This already present data is then automatically assigned to the newly
created variable and regarded as garbage.
• this garbage data is unwanted and needs to be removed.
• The removal of garbage data before actually using a variable is called
initialization.
Initialization
Pseudocode VB Initialization Example
INTEGER Integer 0 total = 0
REAL Single 0 Weight=0
CURRENCY Decimal 0 Price=0
TEXT/STRING String “” Name=“ ”
CHAR Char ‘ ’(pseudp) , “”(VB) Result=‘ ’/ result=“ ”
BOOLEAN Boolean #FALSE# (PSEUDO), a = FALSE
True(VB)
DATE Date We do not initialize it; if
needed initialize it with
current date
TIME Time We do not initialize it; if
needed initialize it with
current time
Data type and Sizes
Data Type Sizes(Byte) Literal Declaration in Pseudocode

INTEGER 4 1,5,-9,-15 DECLARE count : INTEGER


REAL 4 1.5,-2.7,5.77 DECLARE height : REAL
CHAR 1 ‘a’, ‘b’, ‘z’ DECLARE grade : CHAR
STRING As many require “ hello world” DECALARE name : STRING
BOOLEAN 1 #TRUE#, #FALSE# DECLARE gender : BOOLEAN
DATE 8 #23-10-2015# DECLARE DOB : DATE
TIME 8 #9:50#
CURRENCY 8 75.67 DECLARE amount :
CURRENCY
Non composite Data type
• Are those which do not make use of other data type
• Like: primitive datatype such as String, Char, Int ,real , Date, time,
Boolean, Currency
Composite Data type
• Which make use of other data type
• Like: Record/Structure, set, class/object
RECORD
• Records are composite data types formed by the inclusion of several
related items that may be of different data types.
• This allows a programmer to refer to these items using the same
identifier, enabling a structured approach to using related items.
• A record will contain a fixed number of items.
• For example, a record for a book could include title, author, publisher,
number of pages, and whether it is fiction or non-fiction.
Syntax of Record in Pseudocode
TYPE
<Typename>
DECLARE <identifier> : <data type>
DECLARE <identifier> : <data type>
DECLARE <identifier> : <data type>
::
::
ENDTYPE
For example, the book record data type could be defined like
this:
TYPE TbookRecord
DECLARE title : STRING
DECLARE author : STRING
DECLARE publisher : STRING
DECLARE noPages : INTEGER
DECLARE fiction : BOOLEAN
ENDTYPE
The data type, TbookRecord, is now available for use and an identifier
may now be declared in the usual way:
• DECLARE Book : TbookRecord

• For example:
Book.author ← "David Watson"
Book.fiction ← FALSE
Example of Record

Declare
In VB Record are known as Structure
Structure StdRec
Dim stdID AS Integer
Dim name AS String
Dim class AS Integer
Dim add AS String
Dim fee AS Single
Dim grade AS Char
End Structure

DIM Std1 AS StuRec


Std1.stdID = 153
Std1.name = “ Khan”
Std1.class = “10”

You might also like