0% found this document useful (0 votes)
74 views2 pages

Unit 9 Key Programming Concepts: Homework 1 Data Types and Operations

This document is a homework assignment on data types and operations. It contains 4 questions: 1. Calculate the values of variables after various math operations like modulo and division. 2. Suggest appropriate data types like integer, string, boolean for variables based on their usage like age, name, true/false choice. 3. Explain the output of an algorithm using character code conversions and math operations on those code values. 4. Output the length, first substring, and last substring of a notice string after using length and substring functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views2 pages

Unit 9 Key Programming Concepts: Homework 1 Data Types and Operations

This document is a homework assignment on data types and operations. It contains 4 questions: 1. Calculate the values of variables after various math operations like modulo and division. 2. Suggest appropriate data types like integer, string, boolean for variables based on their usage like age, name, true/false choice. 3. Explain the output of an algorithm using character code conversions and math operations on those code values. 4. Output the length, first substring, and last substring of a notice string after using length and substring functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Homework 1 Data types and operations

Unit 9 Key programming concepts

Name:............................................................................ Class:................... Mark:................

1. State the values of a, b, c, d and e after the following operations are carried out: [5]

(a) a ← 26 MOD 5 ______________________________________________________

(b) b ← 142 DIV 7 ______________________________________________________

(c) c ← (7 + 3) * 4 – 1 ______________________________________________________

(d) d ← 15.6 / 3 + 4.8 / 2 ______________________________________________________

(e) e ← "4" + "56" ______________________________________________________

2. The following table shows a number of different variables and what they are used for.
Complete the table to suggest appropriate data types for each of the variables. The first row
has been completed for you.

Variable name Description of what the Data type


variable holds

Age A user’s age in years Integer

MenuChoice A single letter that will


determine a user’s choice

Height A height of a person in


metres – e.g. 1.73

LastName A user’s last name

PlayAgain True or False depending


on whether the user
wishes to play a game
again

1
Homework 1 Data types and operations
Unit 9 Key programming concepts

3. The function CHAR_TO_CODE('a') evaluates to 97, the ASCII value of the character ‘a’.
CODE_TO_CHAR(97) evaluates to 'a'.
State what is output by this algorithm: [4]

x ← CHAR_TO_CODE('b') ________________________________________________

y←x+1 ________________________________________________

z←x–1 ________________________________________________

w ← CODE_TO_CHAR(y) + CODE_TO_CHAR(z)_________________________________

OUTPUT x ________________________________________________

OUTPUT y ________________________________________________

OUTPUT z ________________________________________________

OUTPUT w ________________________________________________

4. What is output by the following algorithm? [3]


Notice ← "Please do not walk on the grass"
StringLength ← LENGTH(Notice)
Left ← SUBSTRING(Notice,1,11)
Right ← SUBSTRING(Notice, LENGTH(Notice)-10, 10)
OUTPUT StringLength
OUTPUT Left
OUTPUT Right

[Total 12 marks]

You might also like