higher computing
DESCRIPTION
Higher Computing. Software Development High Level Language Constructs. What we will learn. Simple Data types Arrays Decision Making Modules and Parameter Passing. Simple Data Types. Some of the types of variables used include: String Real Integer Boolean. Strings. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/1.jpg)
I Power
Higher Computing
Software Development
High Level Language Constructs
![Page 2: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/2.jpg)
What we will learn
Simple Data types
Arrays
Decision Making
Modules and Parameter Passing
![Page 3: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/3.jpg)
Simple Data Types
Some of the types of variables used include:String
Real
Integer
Boolean
![Page 4: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/4.jpg)
Strings
String variables contain text and can take up a range of memory.
Two operations that can be applied are:Concatenation.
Substrings.
![Page 5: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/5.jpg)
Concatenation
Concatenation is the addition of two strings.
One string is placed at the end of the other.Forename$ = “Bob”
Surname$= “Jones”
Fullname$ = Forename$ + Surname$
The Variable Fullname$ will now contain:
“BobJones”
![Page 6: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/6.jpg)
Substrings
Substrings are often referred to as string slicing.This is where the part of the string is extracted.
A Variable Fullname$ may contain:
“BobJones”
Forename$ := Fullname$(1:3)
Surname$ := Fullname$(4:8)
Forename$ now contains “Bob” and
Surname$ now contains “Jones”
![Page 7: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/7.jpg)
Real
Real numbers are floating point numbers.
They usually use 32 bits of computer memory in a single memory location.
Remember:E.g. 20.125 = .20125 x 100 = .20125 x102
Any number can be represented in the form:
M x basee
Where M is the mantissa and e is the exponent.
![Page 8: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/8.jpg)
Integer
An Integer is any positive or negative whole number.
Integers usually use 32bits of computer memory.
All mathematical operations can be applied to these numbers.
E.g. + - x /
![Page 9: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/9.jpg)
Boolean
A Boolean value can have either the value True or False.
Their value is stored using one bit of memory.
Logical operators can be used on BooleansE.g. AND, OR, NOT.
![Page 10: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/10.jpg)
ArraysThis is a set of data items of the same type grouped together with a single variable name.Each Data item (Element) in the array is identified by the variable name and a subscript (index).
An array of names may look like this:
Name(1) Contains John
Name(2) Contains Helen
Name(2) Contains Peter
![Page 11: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/11.jpg)
Decision Making
All languages have some decision-making construct.
IF, where the execution of an action depends on a stated condition.
Most languages expand this to allow for a series of outcomes using:
IF…THEN…ELSE…
![Page 12: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/12.jpg)
Decision Making (Cont.)
The IF…THEN…ELSE… construct can be replaced with a CASE (SWITCH) statement.
The CASE statement is no different once translated to machine code.
The advantage is that it is clearer to read and understand.
![Page 13: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/13.jpg)
Decision Making (Cont.)Nested IFIF mark >= 70 then
PRINT “A”ELSE IF mark >= 60 then
PRINT “B”ELSE IF mark >= 50 then
PRINT “C”ELSE IF mark >= 45 then
PRINT “D”ELSE
PRINT “No Award”END IF
CASE StatementCASE mark OF
>= 70: Print “A”>= 60: Print “B”>= 50: Print “C”>= 45: Print “D”DEFAULT : Print “No
Award”END CASE
![Page 14: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/14.jpg)
Fixed Loops
A For loop can be used to execute one or more commands a known amount of times.For counter = 1 to total
execute this command
Next
![Page 15: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/15.jpg)
Conditional Loops
A Conditional Loop can be used when the programmer does not know how many times the code will have to be repeated.
The test to loop again can be done at the start or at the end.
![Page 16: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/16.jpg)
Conditional Loops
Do
Execute this command
Loop Until exit = TRUE
Do While exit = FALSE
Execute this command
Loop
![Page 17: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/17.jpg)
Modules
Well written code is often broken down into several modules
This allows different programmers to each write a separate part of the solution.
This also means that should you wish to change part of your code during the maintenance phase, the affected part can be lifted out and replaced without affecting the rest of the code.
![Page 18: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/18.jpg)
Modules (Cont.)
Modules can take many different form depending on the language.
The two main modules we need to know about are:
Subroutines (Procedures); This is a section of code designed to do a specific task. They are then called during the running of the code.
Functions; This is similar to a subroutine except that it has a value that can be assigned rather than returning a variable.
![Page 19: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/19.jpg)
Scope
The parts of the program that can see and use the variable are called the scope of the variable.
Local variables exist only within a single module and cannot be accessed from elsewhere in the code.
Global variables are created in the main part of the program and can be seen from any part of the program.
![Page 20: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/20.jpg)
Parameter passing by value(In Parameter)
When a parameter is passed by value into a subroutine an exact copy of current value of the original variable is used by the subroutine.
This allows one-way data transfer between the main program and the subroutine.
The programmer can then guarantee that the variable will still be suitable for other parts of the code.
![Page 21: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/21.jpg)
Passing by value (Example)The Value of the parameter stored at
location 5000 is passed by value.
Memory Locations
500050015002
A copy of the value is stored at location 5001
Simon
The subroutine is then free to change the value in 5001
The value of the original remains unchanged.
SimonPaul
![Page 22: Higher Computing](https://reader036.vdocuments.mx/reader036/viewer/2022062407/56812c28550346895d909e01/html5/thumbnails/22.jpg)
Parameter Passing by Reference(In/Out Parameter)
Parameter passing by reference allows the data that is passed into a subroutine to be changed, then passed back out to other parts of the program.
This allows a two way data transfer between the main program and the subroutine.