0% found this document useful (0 votes)
265 views16 pages

10.1 As Record Data Types

Inqilab Patel is a computer teacher who has taught at several schools in Karachi. He is continuing his education with an MPhil in computer studies. Patel maintains a website to support students preparing for GCSE computer science exams. He contributes material to Cambridge's teacher support site and receives appreciation from users worldwide.
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)
265 views16 pages

10.1 As Record Data Types

Inqilab Patel is a computer teacher who has taught at several schools in Karachi. He is continuing his education with an MPhil in computer studies. Patel maintains a website to support students preparing for GCSE computer science exams. He contributes material to Cambridge's teacher support site and receives appreciation from users worldwide.
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/ 16

About the developer of this workbook

Inqilab Patel is an O & A Level Computer Teacher. Currently he is teaching A & O Level Computer Science
at The City School PAF Chapters, Hira Foundation School and Intellect. He has taught in many other
schools including Yaqeen Model School, Karachi Cadet School, KN Academy, Hexis A Level, Verge and
Nakhlah Boys Campus Society. Cambridge has selected him as a Member of Cambridge Editorial
Review Board. He is also associated with Aga Khan University Examination Board in the capacity of
Chief Examiner, Item Writer, E-Marker, Karachi Board of Secondary Education the capacity of
Deputy Head Examiner and Sindh Board of Technical Education.

His entire career path revolves around computer science; either he was a student or a teacher.
He got a chance to polish his skills of teaching and studying more about computers at various
levels which has given him great confidence in presenting himself for any senior level position of
transferring his knowledge to the youth.

He has not stopped; he is continuing with his education at the higher levels. It is his second
semester of MPhil computer studies from a well-known university of Pakistan; The Institute of
Business & Technology.

Inqilab Patel knows a lot of methods of teaching computers and has developed tutorial notes,
worksheets and assignments for my students. He also maintains a website
(www.inqilabpatel.com) which is specifically designed for the support of those who want to excel
in GCSE computer science. He also regularly contributes material to CIE teacher support website,
for which he receives appreciation from different people across the world.

He has also received various training in innovative and special methods of teaching this subject.

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
10.1 Record Data Type
Candidates should be able to: Notes and guidance
Show understanding of the purpose of a record Write pseudocode to define a record structure.
structure to hold a set of data of different data types Write pseudocode to read data from a record
under one identifier structure and save data to a record structure
Data types:
A data type is a classification that specifies which type of data a variable has and what type of
operations can be applied to it.
Most programming languages support various types of data, including integer, real, character or
string, and Boolean.
Before a variable can be used in a program, the variable’s data type has to be identified.
Built-in data types
Remember, for each built-in data type:
The programming language defines the range of possible values that can be assigned to a
variable when its type has been chosen.
The programming language defines the operations that are available for manipulating values
assigned to the variable.
User-defined data types
The term ‘user’ is regularly applied to someone who is provided with a ‘user interface’ by an operating
system – the ‘user’ is the person supplying input to a running program and receiving output from it.
However, when writing a program, a programmer becomes a ‘user’ of a programming language. The
term user-defined data type applies to this latter type of user.
A user-defined data type is a data type for which the programmer has included the definition in the
program. Once the data type has been defined, variables can be created and associated with the
user-defined data type. Note that, although the user-defined data type is not a built-in data type, using
the user-defined data type is only possible if a programming language offers support for the construct.
There are two types of user defined data types:
1. Composite Data Type
2. Non-Composite Data Type

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


1. Composite user-defined data types
A composite user-defined data type has a definition with reference to at least one other type.
There are two very important examples of composite user-defined data type.
i. Record
ii. Class
i. The record data type.
Although there could be built-in record data types the expectation is for a record data type to be user-
defined. This allows the programmer to create record data types with components that precisely
match the data requirements of the particular program. Note that Python is a language that does not
support the use of a record data type.
Definition of Record Data Type:
Syntax:
TYPE <Record Data Type Identifier>
DECLARE <Identifier> : <Data Type>
DECLARE <Identifier> : <Data Type>
….
END TYPE
Example: to create a record data type Student
TYPE TStudent
DECLARE RollNo : STRING
DECLARE Name : STRING
DECLARE Class : STRING
DECLARE Marks : ARRAY[1:6] OF REAL
END TYPE
Declaring variable of Record Data Type:
Syntax of creating record data type variable:
DECLARE <Identifier > : <Record Data Type>
Example:
DECLARE ALevel : TStudents
Assigning values:
ALevel.RollNo
ALevel.Name “Ahmed”

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
Input from user:
INPUT ALevel.RollNo
INPUT ALevel.Name
INPUT ALevel.Class
FOR Count 1 TO 6
INPUT ALevel.Marks[Count]
NEXT Count
Output on screen
OUTPUT ALevel.RollNo
OUTPUT ALevel.Name
OUTPUT ALevel.Class
FOR Count 1 TO 6
OUTPUT ALevel.Marks[Count]
NEXT Count
Arrays of User Defined data type:
Arrays can also be declared from user defined data types. Here is an example of arrays of 100,
including declaration, input and output.
TYPE TStaff
DECLARE StaffID: STRING
DECLARE Name : STRING
DECLARE BasicPay : REAL
END TYPE
DECLARE AdminStaff : ARRAY[1:100] OF TStaff
FOR Count 1 TO 100
INPUT AdminStaff[Count].StaffID
INPUT AdminStaff[Count].Name
INPUT AdminStaff[Count].BasicPay
NEXT Count
FOR Count 1 TO 100
PRINT AdminStaff[Count].StaffID
PRINT AdminStaff[Count].Name
PRINT AdminStaff[Count].BasicPay
NEXT Count

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


Q 1) Specimen Paper
5 A company keeps details of its product items in a 1D array, Stock. The array consists of 1000
elements of type StockItem.
The record fields of StockItem are:
Field Typical value
ProductCode "BGR24-C"
Price 102.76
NumberInStock 15
(a) Write pseudocode to declare the record structure StockItem.
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [3]
(b) Write pseudocode to declare the Stock array.
...................................................................................................................................................
.............................................................................................................................................. [3]
(c) Write pseudocode to modify the values to element 20 as follows:

...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
(d) A stock report program is developed.
Write pseudocode to output the information for each stock item that has a price of at least 100.
Output the information as follows:
Product Code: BGR24-C Number in Stock: 15
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [4]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
S15 Paper 33
4 (a) A particular programming language allows the programmer to define their own data types.
An example of a user-defined data type for an address is:
TYPE ThisAddress
DECLARE ThisHouseNo : INTEGER
DECLARE ThisStreet : STRING
DECLARE ThisTown : STRING
ENDTYPE
A variable of this new type is declared as follows:
DECLARE HomeAddress : ThisAddress
Write the statement that assigns the house number 34 to HomeAddress.
.......................................................................................................................................[1]
Write the statement that input street and town and stores in HomeAddress.
.......................................................................................................................................[1]
(b) Temperature data from a number of weather stations are to be processed by a program.
The following data are to be stored:
• weather station ID (a unique four-letter code)
• latitude (to 2 decimal places)
• average temperature (to the nearest whole number) for each year from 2001 to 2015 inclusive
A programmer designs a composite data type WeatherStation. A variable of this type can be used to
store all the data for one particular station.

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


(i) Write the definition for the user-defined data type WeatherStation.

...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[5]

1 (a) Consider the following pseudocode user-defined data type:


TYPE MyContactDetail
DECLARE Name : STRING
DECLARE HouseNumber : INTEGER
ENDTYPE
(i) Write a pseudocode statement to declare a variable, NewFriend, of type MyContactDetail.
.......................................................................................................................................[1]
(ii) Write a pseudocode statement that assigns 129 to the HouseNumber of NewFriend.
.......................................................................................................................................[1]
Q 3) Specimen Paper
5 A company keeps details of its product items in a 1D array, Stock. The array consists of 1000
elements of type StockItem.
The record fields of StockItem are:
Field Typical value
ProductCode "BGR24-C"
Price 102.76
NumberInStock 15

(a) Write pseudocode to declare the record structure StockItem.


...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [3]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
(b) Write pseudocode to declare the Stock array.
...................................................................................................................................................
.............................................................................................................................................. [3]
(c) Write pseudocode to modify the values to element 20 as follows:
• set the price to 105.99
• increase the number in stock by 12
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
(d) A stock report program is developed.
Write pseudocode to output the information for each stock item that has a price of at least 100.
Output the information as follows:
Product Code: BGR24-C Number in Stock: 15
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [4]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


Q 4) Winter 21 P21
3 A programmer is writing a program to help manage clubs in a school.
Data will be stored about each student in the school and each student may join up to three clubs.
The data will be held in a record structure of type Student.
The programmer has started to define the fields that will be needed as shown in the following table.
Field Typical value Comment
StudentID "CF1234" Unique to each student
Email "[email protected]" Contains letters, numbers and certain symbols
Club_1 1 Any value in the range 1 to 99 inclusive
Club_2 14 Any value in the range 1 to 99 inclusive
Club_3 27 Any value in the range 1 to 99 inclusive
(a) (i) Write pseudocode to declare the record structure for type Student.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
(ii) A 1D array Membership containing 3000 elements will be used to store the student data.
Write pseudocode to declare the Membership array.
...........................................................................................................................................
..................................................................................................................................... [2]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
(iii) Some of the elements of the array will be unused.
Give an appropriate way of indicating an unused array element.
...........................................................................................................................................
..................................................................................................................................... [1]
(iv) Some students are members of less than three clubs.
State one way of indicating an unused club field.
...........................................................................................................................................
..................................................................................................................................... [1]
(b) A procedure GetIDs() will:
• prompt and input the number of a club.
• output the StudentID of all the students who are members of that club.
• output a count of all students in the given club.
Write pseudocode for the procedure GetIDs().
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [7]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/
COMPUTER SCIENCE WITH INQILAB PATEL

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


3c 9618 S22 P23
5 A program will store attendance data about each employee of a company.
The data will be held in a record structure of type Employee. The fields that will be needed are as
shown:
Field Typical value Comment
EmployeeNumber 123 A numeric value starting from 1
Name "Smith,Eric" Format: <last name>','<first name>
Department "1B" May contain letters and numbers
Born 13/02/2006 Must not be before 04/02/1957
Attendance 97.40 Represents a percentage
(a) (i) Write pseudocode to declare the record structure for type Employee.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [4]

(ii) A 1D array Staff containing 500 elements will be used to store the employee records.
Write pseudocode to declare the Staff array.
...........................................................................................................................................
..................................................................................................................................... [2]
(b) There may be more records in the array than there are employees in the company. In this case,
some records of the array will be unused.
(i) State why it is good practice to have a standard way to indicate unused array elements.
...........................................................................................................................................
..................................................................................................................................... [1]
(ii) Give one way of indicating an unused record in the Staff array.
...........................................................................................................................................
..................................................................................................................................... [1]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


COMPUTER SCIENCE WITH INQILAB PATEL
(c) A procedure Absentees() will output the EmployeeNumber and the Name of all employees who
have an Attendance value of 90.00 or less.
Write pseudocode for the procedure Absentees().
Assume that the Staff array is global.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/


+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/
COMPUTER SCIENCE WITH INQILAB PATEL

+92 300 2724734 /inqilabpatel https://www.inqilabpatel.com/

You might also like