Presentation is loading. Please wait.

Presentation is loading. Please wait.

Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.

Similar presentations


Presentation on theme: "Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language."— Presentation transcript:

1 Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language. Features: String Operations Formatting input/output Control Structure (Sequence, repetition and selection) Data Storage (Local and Global variables, scope) Data Types (Real, Integer, boolean and one-dimensional arrays) Data flow (parameter passing)

2 String Operations (Concatenations and substrings)
String operations can process string data. String operations include: Concatenations Sub-String Concatenation Concatenations is joining two strings. Two strings in and one string out. Example: PRINT “House” & “boat” Result: Houseboat

3 Need to know coding for exam
Sub-String Selecting parts of string. VB uses Mid$ to extract a substring from a string. Example 1: “Hello higher Class” – Input string Mid$(string_in, 1, 1) Result: “H” Example 2: “I made him an offer he could not refuse” Mid$(string_in, 3, 8) “Made him” – starting at position 3 and counting 8 characters Need to know coding for exam

4 Formatting Input/output
The way the program displays the data on the screen when inputting and outputting. Input Methods for VB Input box Text box Output Methods for VB Message box Picture box List box Tab() function can be used to create tabs in the output program.

5 Three basic control constructs used to define the order in which the instructions in a program are executed. These control constructs are found in all classifications of programming languages to control the flow of execution of the program code. Control Structured programming is based on three constructs: sequence selection repetition Sequence Order in which you give instructions to the computer. In sequence, one instruction is executed after another. The purpose of sequence is to ensure that instructions given to the computer are executed in the correct order.

6 Example Algorithm to add two numbers Ask user for first number Take in first name Ask user for second number Take in second number Add two numbers to find total Display total This would work only if the steps are followed. What would happen if this was used?

7 Selection Based on one or more condition, used together with a control structure such as IF or CASE. Conditions have values, they are either true or false. The purpose of selection is to allow a choice to be made in a program. Common control structures: If Mark >= 50 THEN Picdisplay.print “Pass” Else Picdisplay.print “Fail” End if Select Case Mark Case Mark >= 50 Picdisplay.print “Pass” Case Mark < 49 Picdisplay.print “Fail” End Select

8 Control Structured programming is based on three constructs:
sequence selection repetition Repetition Involves using loops. Loops may be either conditional or Unconditional (Fixed) The purpose of repetition is to allows statements in a program to be repeated as many times as is necessary.

9 Types of Loops Unconditional Loops (Fixed Loops) Repeat a set of program statements for predetermined number of times. Fixed loops are controlled by a variable called a loop counter. Example: FOR counter equal starts number TO finish number Do something NEXT

10 Repeats instructions until a condition is satisfied. Advantage
Conditional Loop Repeats instructions until a condition is satisfied. Advantage Amount of data to be processed need not be known in advance A mathematical calculation can continue until answered Example Do mark1 = InputBox("Please enter mark 1") If mark1 > 10 Or mark1 < 0 Then MsgBox ("Please enter a mark between 1 and 10") End If Loop Until mark1 >= 0 And mark1 <= 10

11 42 Mark Data Storage Variables
Data is stored in a computers memory in storage locations. Each storage location in the computers memory has a unique address. By using variable names a programmer can store, retrieve and handle data without knowing what the data will be. Types of variables Local Global Mark Dim Mark as Integer 42

12 Global Variables Can be referred to from anywhere in a program. Can be changed by any subprogram in the program. Modern programming practice recommends against the excessive use of global variables. They can lead to poor program structure, and tend to clog up the available name space. Local Variables Only exists within the subprogram in which it is declared. Will not be recognised by any other subprogram. Scope of variables The variable the sub program is used in. There is no need to worry about having the similar variable names when using different sub programs, since they cannot have any effect outside their scope.

13 Data Type String – may include letters, digits and punctuations. Integer – may consist of whole numbers Single/Real – may consist of whole number and real numbers (fractional) Boolean – may have two values, true or false.

14 Structured Data Types Related data items can be stored together using arrays. A data structure is a way of storing data in a computer in an organised way. One of the simplest data structures used in computer programming is called an array and is an example of a static data structure because it is of a fixed size within memory as defined within the structure of the program. Array A set of data items of the same type grouped together using a single variable name. Allows program to be more reliable and efficient. Example Wanted a program to take in 20 names and 20 test marks. Without an array you would need to declare 20 variables for name and 20 variables for mark.

15 Data Flow The movement of data between subprograms is implemented by using parameters. IN/OUT parameters Variables that are changed or updated IN parameters Variables that only pass data into a subprogram. OUT parameters Variables which only pass data out of subprogram. Parameters Information about a data item being supplied to a subprogram (Function or procedure) when called into use. When the sub-program is used this is known as parameter passing.

16 Parameters can be passed by either value or reference.
Deciding which method to use depends on whether the parameter is going into or in/out of a procedure. By Value When a parameter is passed into a procedure When a parameter is passed by value into a subroutine, an exact copy of the current value of the variable is used. The value does not change. Allows one-way transfer between the main program and the subroutines or functions.

17 By Reference When a parameter is passed into a procedure, updated and passed back out again. Two-way data transfer between the main program and the subroutine. **Problem Arrays are always passed byref when using visual basic programming.

18 Importance of Data flow
It is necessary to describe the data flow in a program in order to work out how the parameters should be passed between the main program and any subprograms.


Download ppt "Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language."

Similar presentations


Ads by Google