0% found this document useful (0 votes)
139 views7 pages

Problem Solving: Data Types

Here are the answers to the homework questions: 1. The three main categories of data are: numbers, characters, and logical values. 2. A string is a sequence of characters like "hello world" that is treated as a single unit of data. 3. Calculations cannot be performed on textual data because operations like addition and subtraction only make sense for numerical values, not text. 4. A real number can contain decimal places while an integer is a whole number without decimals. 5. Examples of constants: - 25 (integer constant) - 3.14 (real constant) - 'a' (character constant) - true (logical constant) Examples of variables:
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
139 views7 pages

Problem Solving: Data Types

Here are the answers to the homework questions: 1. The three main categories of data are: numbers, characters, and logical values. 2. A string is a sequence of characters like "hello world" that is treated as a single unit of data. 3. Calculations cannot be performed on textual data because operations like addition and subtraction only make sense for numerical values, not text. 4. A real number can contain decimal places while an integer is a whole number without decimals. 5. Examples of constants: - 25 (integer constant) - 3.14 (real constant) - 'a' (character constant) - true (logical constant) Examples of variables:
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Problem Solving

Data Types
Data Types

All variables require a data type. The data type is used to define the type of data that the
variable will hold in memory. Different data types have different rules about how the data can
be used.
Data is classified into types, such as a set of whole numbers (also known as integers) or a set
of printing characters.
Different types of data are represented in different ways inside a computer and need varying
amounts of memory to store them. They also have different operations that can be performed
upon them. All values that belong to the same data type will be represented in the same way.
There are five data types that you need to know and understand.
Data Types

Data type Example Size

Integer (whole number) 4, 27, 65535 1 to 8 bytes


The most commonly supported data types in programming languages are:
Floating point/Real (decimal
4.2, 27.4, 5.63 4 to 8 bytes
number)

Character a, F, 3, $, £, # 1 byte

Limited to the amount that can


String abc, hello world
be stored in main memory

Boolean true or false 1 bit


Data Types

Some operations that can be applied to values of one


data type obviously do not make sense when applied to
values of another type. For example, we can calculate
the square root of the integer 4, but not of the string
"hello world".
Data types may be different in different languages. The
main data types are grouped under hierarchies. They
are either numbers, characters or logical. There are
several types of number values, including a distinction
between whole numbers and floating-point numbers.
Data Types
Identifier name Constant/variable Datatype Value or rangeOf values Operations to be performed
Data types used in the BVI boat hire program program
will store or utilise

Evaluation:
Costper hour Constant 25.00 constant

Numberofhours Variable 1-24 Multiplication and addition

Totalcost Variable 25-600 Multiplication and addition


Data types

Questions:
See attached document
Homework

What are three categories of data?


What is a string?
Why can't you perform calculations on textual data?
What is the difference between a real number and an integer?
What is the difference between a constant and a variable? Five examples of each

You might also like