14
1 Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan Simple Data Types Integer: An integer value may be any positive or negative whole number, e.g. 24, - 6. Real: A real value is taken to mean a number with a fractional part, e.g. 3.65. String: A string is any single or group of characters, e.g. “Peter” Boolean: A boolean value is a two-state value. It can either be True or False

Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer

Embed Size (px)

Citation preview

Page 1: Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer

1

Higher Grade Computing Studies3. High Level Language Constructs

Higher Computing Software Development

S. McCrossan

Simple Data Types

• Integer: An integer value may be any positive or negative whole number, e.g. 24, -6.• Real: A real value is taken to mean a number with a fractional part, e.g. 3.65.

• String: A string is any single or group of characters, e.g. “Peter”

• Boolean: A boolean value is a two-state value. It can either be True or False

Page 2: Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer

2

Higher Grade Computing Studies3. High Level Language Constructs

Higher Computing Software Development

S. McCrossan

Structured Data Types

• Array: An array is a set of data all sharing the same variable name which can be accessed by means of a subscript.

Page 3: Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer

3

Higher Grade Computing Studies3. High Level Language Constructs

Higher Computing Software Development

S. McCrossan

Modularity

• Modularity is a feature of well written code and it means to divide a larger program into parts that work together to complete the program’s task.

• Subroutines (also known as subprograms or procedures) and functions allow programs to be written in modular form.

Page 4: Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer

4

Higher Grade Computing Studies3. High Level Language Constructs

Higher Computing Software Development

S. McCrossan

Modularity

• Procedures are sections of code which do a specific set of tasks in the program, and which have been grouped separately so that they are called (brought into use) during the running of the program.

• A function is similar to a procedure in that it is also a section of code which does a specific task in the program, and which is called (brought into use) during the running of the program.

• The difference between a procedure and a function is that:• a procedure produces an effect, whereas • a function produces a single value.

Page 5: Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer

5

Higher Grade Computing Studies3. High Level Language Constructs

Higher Computing Software Development

S. McCrossan

Parameters

• Parameters are used to pass data to/from subprograms. The statement :

calculate_volume(l, b, h)

means that the subprogram calculate_volume uses as its data the variables l, b and h.

• l,b and h are known as the actual parameters because they are the ones passed into the procedure.

Page 6: Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer

6

Higher Grade Computing Studies3. High Level Language Constructs

Higher Computing Software Development

S. McCrossan

Parameters

• The procedure to do the calculation will start like this :

procedure calculate_volume(length,breadth,height)

• length,breadth and height are known as the formal parameters because they are the ones used by the procedure.

Page 7: Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer

7

Higher Grade Computing Studies3. High Level Language Constructs

Higher Computing Software Development

S. McCrossan

Parameters

• Value parameters result in a copy of the original. They cannot be passed out of the subprogram and used elsewhere. They are safer to use as the original is unaffected and so it cannot be accidentally altered.

• If a value parameter has its value changed within a procedure, this change of value will not be passed back out of the procedure. It will revert back to the value it had before entering the procedure.

Page 8: Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer

8

Higher Grade Computing Studies3. High Level Language Constructs

Higher Computing Software Development

S. McCrossan

Parameters

• Reference parameters alter the value of the variables themselves. They can be passed out and used elsewhere but can result in accidental alteration of a variable.

• If a reference parameter has its value changed within a procedure, this change of value will be passed back out of the procedure.

Page 9: Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer

9

Higher Grade Computing Studies3. High Level Language Constructs

Higher Computing Software Development

S. McCrossan

Scope of variables

Local Variables• Local variables are variables which exist only within a subprogram. They cannot be accessed or assigned a value except within that subprogram.

Global Variables• Global variables are variables which are used in any and every part of a program, including subprograms. They should always be used with care and preferably should not be used within subprograms if at all possible.

Page 10: Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer

10

Higher Grade Computing Studies3. High Level Language Constructs

Higher Computing Software Development

S. McCrossan

Scope of variables

The scope of a variable is the parts of the program it can be used in. If a variable is used throughout the whole program, both in the main program and procedures, then its scope is global. If the variable, however, can only be used within one procedure then its scope is only within that procedure.

Page 11: Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer

11

Higher Grade Computing Studies3. High Level Language Constructs

Higher Computing Software Development

S. McCrossan

String Operations

• Concatenation is a process where a string is joined to another string to make a larger string, e.g. “sauce” + “pan” = “saucepan”.

Page 12: Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer

12

Higher Grade Computing Studies3. High Level Language Constructs

Higher Computing Software Development

S. McCrossan

String Operations

• Substrings are parts of larger strings that can be ‘pulled out’ and used.

Page 13: Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer

13

Higher Grade Computing Studies3. High Level Language Constructs

Higher Computing Software Development

S. McCrossan

Formatting Input and Output

• Languages can have a range of sophisticated input methods (ways of letting the user enter data) such as text boxes, radio buttons, spin boxes, drop down menus, etc, or it may just be limited to keyboard input.

• You may also be able to change the way text looks on screen by altering the colour, font, size, style and alignment of text.

Page 14: Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer

14

Higher Grade Computing Studies3. High Level Language Constructs

Higher Computing Software Development

S. McCrossan

CASE statements

• The CASE statement allows for multiple outcomes. It removes the need for many IF…THEN…ELSE statements and is clearer for the programmer, or whoever is reading the programming code, to understand.