CH 1-Data representation User define

Learn Like a GEM

Subject: (insert subject here)

Lesson: (insert lesson focus/topic here)

Date: (insert date here)

1 / 23
next
Slide 1: Slide
New lesson editor

This lesson contains 23 slides, with text slides.

Report this lesson

Items in this lesson

Learn Like a GEM

Subject: (insert subject here)

Lesson: (insert lesson focus/topic here)

Date: (insert date here)

LO: To understand and use different data types, including user-defined and composite types, in programs.




What are the basic (primitive) data types you’ve used before?
(e.g., integer, real, boolean, string)

Integer, real (float), string, Boolean, and character.


How would you store a list of fixed values like days of the week in your program?

Using a list or array, or preferably an enumerated type (enum) for fixed values to ensure only valid options are used.


Have you come across the term “pointer” before? What do you think it means in programming?

A pointer stores the memory address of another variable. It “points” to where data is stored in memory, often used for dynamic data structures.


Have you seen or used TYPE or class in pseudocode or Python before? What do you think it is used for?

Yes, TYPE in pseudocode or class in Python helps create a template to group related data (like in a record or object), making programs more organized and easier to manage.


LO: To understand and use different data types, including user-defined and composite types, in programs.

Feel: Starter

Grade C will be able to identify and explain the purpose of user-defined types in programming and distinguish them from non-composite data types.


Grade B will be able to use non-composite data types (e.g., integer, float, string, boolean) correctly within a program to store and manipulate data.


Grade A will be able to justify why a user-defined type is needed in a program instead of using standard non-composite types.


LO: To understand and use different data types, including user-defined and composite types, in programs.

Define : Lesson Outcomes

User defined data type

Composite data type

Non-composite data type

Set

Class

Enumerated

Pointer

using existing data types

combines multiple values of same

or different data types

holds a single value and does not include or reference any other data types.

Holds a single value at a time from a fixed list of possible values.

Holds one memory address pointing to a single data item

Record

Examples

Integer

score = 95

char

grade = 'A'

Non-Composite data type

TYPE Day = (Monday, Tuesday, Wednesday, Thursday, Friday)

DECLARE today : Day

today ← Wednesday

Enumerated data type

DECLARE number : INTEGER

DECLARE p : POINTER TO INTEGER

Pointer data type

LO: To understand and use different data types, including user-defined and composite types, in programs.

Examples

TYPE Book

Title : STRING

Author : STRING

YearPublished : INTEGER

ISBN : STRING

END TYPE

Composite data type

Example

LO: To understand and use different data types, including user-defined and composite types, in programs.

1.Explain, using examples, the difference between composite and non-composite data types.


2 Explain why programmers need to define user-defined data types. Use examples to illustrate your answers.


3 Choose an appropriate data type for the following situations. Give the reason for your choice in each case.

  1. A fixed number of colours to choose from.

  2. Data about each house that an estate agent has for sale.

  3. The addresses of integer data held in main memory

LO: To understand and use different data types, including user-defined and composite types, in programs.

Discover :Collaboration/Shared Activities

Answers

2. If a program deals with student data, instead of using separate variables like:

Name : STRING

Age : INTEGER

Grade : CHAR

We can define:

TYPE Student

Name : STRING

Age : INTEGER

Grade : CHAR

END TYPE

Now we can declare:

DECLARE s1 : Student

This makes the program cleaner, easier to manage, and allows the use of arrays of records, etc.


3. a and c – Non composite (Enumerated and Pointer)

b- composite (Record/class)

LO: To understand and use different data types, including user-defined and composite types, in programs.

Using the pseudocode declarations below, identify

  1. an enumerated data type [1]

  2. a composite data type [1]

  3. a non-composite data type [1]

  4. a user-defined data type. [1]

TYPE Tseason = (Spring, Summer, Autumn, Winter)

TYPE TJournalRecord

DECLARE title : STRING

DECLARE author : STRING

DECLARE publisher : STRING

DECLARE noPages : INTEGER

DECLARE season : Tseason

ENDTYPE

Answers :

i.Tseason

ii. TJournalRecord

iii. STRING / INTEGER

iv.Tseason / TJournalRecord

LO: To understand and use different data types, including user-defined and composite types, in programs.

AFL and Progress Check

Answers :

/ /Declare variable of type TJournalRecord

DECLARE Journal : TJournalRecord


// Assign values to the fields

Journal.title ← "Spring Flowers"

Journal.author ← "H Williams"

Journal.publisher ← "XYZ Press"

Journal.noPages ← 40

Journal.season ← Spring

Write pseudocode to declare a variable Journal of type TJournalRecord and assign the following values to the variable. [3]


Title – Spring Flowers

Author – H Williams

Publisher – XYZ Press

Number of pages – 40

Season – Spring

LO: To understand and use different data types, including user-defined and composite types, in programs.

PPQ

LO: To understand and use different data types, including user-defined and composite types, in programs.

Create : Independent Tasks/ Personalisation

LO: To understand and use different data types, including user-defined and composite types, in programs.

PPQ

LO: To understand and use different data types, including user-defined and composite types, in programs.

Create : Independent Tasks/ Personalisation

LO: To understand and use different data types, including user-defined and composite types, in programs.

PPQ

LO: To understand and use different data types, including user-defined and composite types, in programs.

Create : Independent Tasks/ Personalisation

LO: To understand and use different data types, including user-defined and composite types, in programs.

Thank you