lesson 3 –key...

Post on 11-Jan-2020

5 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Lesson 3 – Key features

UNIT 6 - SOFTWARE DESIGN AND DEVELOPMENT

Last session

1. Language generations. 2. Reasons why languages are used by organisations.

1. Proprietary or open source.

2. Features and tools.

3. Availability of trained staff.

4. Reliability.

5. Development and maintenance costs.

6. Expandability

3. IPO

What is covered in this session

Key features of programming languages

Features of programming

Assignment 3 requires you to write a computer program. In order to write this program we need to understand key features of programming. These key features apply to all programming languages.

Features of programming sequence; selection eg

case, if … then … else;

iteration eg repeat – until, while .. do;

variables eg naming conventions, local and global variables,

logical operators; assignment statements; input statements; output statements

Code Structures It is important to have a logical structure to

programs. Programs should be organized so developers

and maintainers can easily determine what modules and routines perform what function.

In procedural paradigms the logical structure follows a top down approach.

Code sequences In all programming languages,

irrespective of programming paradigms, code must be executed in sequence.

One line at a time. This is the order of execution (the

order in which the code runs).

Code sequences

Normal code will run line by line. In VB.NET, the program starts with the public

class. In Scratch, the program starts at the top and

works downwards.

Task 10

Use Visual Studio to – Create a new (Visual Basic) VB.net Windows forms

application name this U06Exercise1. You should have a blank form in the design window. Now do Lab04 part a (only part a). What result did you get?

Selection statementsSelection is about decision making in your code. break the line-by-line reading tell the program to jump to another section. An example of this would be an IF statement. In VB.NET, you can make use of ‘for’ loops and ‘if’

statements. In Scratch, you can also use loops if a criteria is/isn’t

true.

Selection statements

If statements check for a true condition and then execute the dependant statements.

If a = b then….. End if

Is this true?

If so, do this!

Selection statements

What do these statements do? 1. If x > 0 and x < 5 then

Console.writeline(x.tostring) End if

2. If x > 0 then if x < 5 then

Console.writeline(x.tostring) End if

End if

Selection statements - Task

Add a button to your form named “btnSelection”, the text should say “Selection” Add a numericupdown control named “numNumber”. Change its max value property to 100. Now do Lab04 Part b. Make sure you add comments to the code.

Case statements

An alternative way to code multipleIf/elseifStatements.

Case statements. Example of If/elseif

If x = 0 then console.writeline(x.tostring())

Elseif x = 1 then console.writeline(x.tostring())

Elseif x = 2 then console.writeline(x.tostring())

etc

Example of If/elseif replaced with case.

Select Case x Case 0

console.writeline(x.tostring()) Case 1

console.writeline(x.tostring()) Case 2

console.writeline(x.tostring()) End Select

This is easier to read and maintain.

Case statements - Task

Add a button to your form named “btnCase”, the text on the button should read “Case”. Do Lab04 Part c. Comment the code. Is this code easier to read than that in part b?

Recap

sequence; selection eg

case,

if … then … else;

ParadigmsChoice of languagesKey features of programming languages

Visual studio

‘comments

Now we will cover

iteration eg repeat – until, while .. do;

Data typesAssignment 1b

variables eg naming

conventions, local and global

variables, logical operators;

assignment statements;

input statements; output statements

Iteration statements. (Loops)

Iteration in computing is the repetition of a block of statements within a computer program. Two types of loop. Fixed loops –

a sequence of statements is executed a fixed number of times.

Dim ant as int32 = 0

For ant = 0 to 5

….. Do something

Loop

An assignment statement

Iteration statements. (Loops)

The second type is a loop which continues until a condition is met or continues while a condition is true.Do while x > 0 and x < 5 …. Loop Example of a pre-check loop

condition

Loops - Task

Add a button to your form named “btnLoop”, the text on the button should read “Loop”.

Do Lab04 Part d. Comment the code.

Increment/decrement statements

Consider these statements –Dim x as int32 = 0 x = x + 1 what is the value of x?

As an alternative we could do this –x++

this produces the same result as the line above. However, it only increments by 1.

Increment/decrement statements

Consider these statements –Dim x as int32 = 0 x = x - 1 what is the value of x?

As an alternative we could do this –x--

this produces the same result as the line above. However, it only decrements by 1.

Increment/decrement statements

Consider these statements –Dim x as int32 = 12 x = x + 1 what is the value of x?

As an alternative we could do this –x++

this produces the same result as the line above. It still only increments by 1.

Assignment statements

Assign values to variables use = or := E.g. myVariable = 20

Can be combined with mathematical operator E.g. myVariable = 20 + subtotal

Mathematical Operators

myVariable = 20 + 2 * 3 What answer will this produce? Why? BIDMAS

Operator Meaning Example Precedence^ Exponentiation 2^3=8 1/ Division 10/2=5 2* Multiplication 2*3=6 3Mod Modular arithmetic

(remainders)5(mod)2=1 4

+ Addition 4+5=9 5- subtraction 7-4=3 6

Input and output statements

In visual programming input and output usually accomplished by controls. List boxes; text boxes; buttons

Procedures collect values entered into boxesE.g. MyText = txtMyInput.text

variable textbox

Input and output statements

Similarly for output Procedures enter values into boxesE.g. lblMyLabel.text = myText

String value could also be used.

label variable

Summary

So what have you learnt so far?

Next we will look at variables in more detail.

top related