VCE IT Theory Slideshows by Mark Kelly 2016-2019 study design By Mark Kelly, vceit.com, Begin.

Slides:



Advertisements
Similar presentations
VCE SD Theory Slideshows By Mark Kelly Vceit.com Debugging Techniques.
Advertisements

Control Structures Ranga Rodrigo. Control Structures in Brief C++ or JavaEiffel if-elseif-elseif-else-end caseinspect for, while, do-whilefrom-until-loop-end.
Macro Processor.
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
VCE IT Theory Slideshows By Mark Kelly Vceit.com Naming Conventions for solution elements.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Control Structures - Repetition Chapter 5 2 Chapter Topics Why Is Repetition Needed The Repetition Structure Counter Controlled Loops Sentinel Controlled.
Python quick start guide
Variables and Constants
INTRODUCTION TO PROGRAMMING STRUCTURE Chapter 4 1.
Structured Programming Defn: This is an approach to program development that produces programs of high quality that are easy to test, debug, modify and.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
VCE IT Theory Slideshows By Mark Kelly vceit.com Data Types 1 a.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
Procedures and Functions Computing Module 1. What is modular programming? Most programs written for companies will have thousands of lines of code. Most.
Chapter 2 User_defined Function. Chapter Goals In this chapter, you’ll learn all about PHP functions, including how : to create and invoke them, pass.
Functions, Procedures, and Abstraction Dr. José M. Reyes Álamo.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
Programming Logic and Design Using Methods. 2 Objectives Review how to use a simple method with local variables and constants Create a method that requires.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
CPS120: Introduction to Computer Science Lecture 14 Functions.
IT Applications Theory Slideshows By Mark Kelly Vceit.com Last modified : 6 Dec 2013 Databases II: Structure, naming, data types, data formats.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Introduction to Computer Programming
Procedural Programming Criteria: P2 Task: 1.2 Thomas Jazwinski.
I Power Higher Computing Software Development High Level Language Constructs.
VCE IT Theory Slideshows By Mark Kelly Vceit.com Arrays.
VCE IT Theory Slideshows by Mark Kelly study design By Mark Kelly, vceit.com, Begin.
VCE IT Theory Slideshows by Mark Kelly study design By Mark Kelly, vceit.com, Begin.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
VCE IT Theory Slideshows by Mark Kelly study design By Mark Kelly, vceit.com, Begin.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
VCE IT Theory Slideshows by Mark Kelly study design By Mark Kelly, vceit.com, Begin.
Controlling Program Flow with Decision Structures.
VCE IT Theory Slideshows by Mark Kelly study design By Mark Kelly, vceit.com, Begin.
VCE IT Theory Slideshows By Mark Kelly vceit.com Version 2 – updated for 2016 Data Types 1 a.
Programming Fundamentals Enumerations and Functions.
VCE IT Theory Slideshows by Mark Kelly study design By Mark Kelly, vceit.com, Begin.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 7 Using Methods.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
VCE IT Theory Slideshows
VCE IT Theory Slideshows
Programming Right from the Start with Visual Basic .NET 1/e
Chapter 9: Value-Returning Functions
VCE IT Theory Slideshows
Structured Programming
REPETITION CONTROL STRUCTURE
IT Applications Theory Slideshows
VCE IT Theory Slideshows by Mark Kelly study design
VCE IT Theory Slideshows by Mark Kelly study design
Chapter 5 - Functions Outline 5.1 Introduction
VISUAL BASIC.
Topics Introduction to File Input and Output
Structured Programming
Functions, Procedures, and Abstraction
Chapter 4 void Functions
VCE IT Theory Slideshows by Mark Kelly study design Test Data
VCE IT Theory Slideshows
Algorithm Discovery and Design
VCE IT Theory Slideshows
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
The structure of programming
Topics Introduction to File Input and Output
Presentation transcript:

VCE IT Theory Slideshows by Mark Kelly study design By Mark Kelly, vceit.com, Begin

Contents SD U3O1-KK06 - processing features of a programming language, including… instructions procedures methods functions control structures 2

Instruction - a statement that describes an action that a program should carry out. e.g. Total  Price + Tax 3VCE IT slideshows © Mark Kelly, vceit.com

Procedure - a self-contained group of instructions that, together, carry out a specific task. Also may be known as a routine, subroutine, module. e.g. a procedure that sorts the items in an array might be called from several locations in a program. 4VCE IT slideshows © Mark Kelly, vceit.com

Modular programming - breaking large sections of code into procedures – is good. makes debugging easier since errors can be more easily located in small pieces of code avoids duplication of code. One procedure may be called on many times useful procedures can be re-used in later programs 5VCE IT slideshows © Mark Kelly, vceit.com

An important feature of procedures is that is variables are entirely local and have no effect on similarly-named variables in the main program or other procedures. 6VCE IT slideshows © Mark Kelly, vceit.com

This prevents accidental changes to values elsewhere in the program - which is very likely since procedures are often pre-written and re-used. Having to check each variable to see if it is used in any other part of the code would be a huge and painful task. 7VCE IT slideshows © Mark Kelly, vceit.com

Only global variables can be seen and changed in any part of the code or in any procedure. Use global variables rarely, reluctantly, and very carefully. They are potential land mines in a program. 8VCE IT slideshows © Mark Kelly, vceit.com

Methods - an action that can be carried out on an object of a given class. Objects have pre-defined methods, and custom methods can be added to classes. 9VCE IT slideshows © Mark Kelly, vceit.com

.Show - to make the object visible.BringToFront - to bring the object in front of other objects.SetFocus - to make the object the active control on a form.Close - to close a window object.Move - to move an object to a set of coordinates.Refresh - to redraw the object and show recent changes to its appearance 10VCE IT slideshows © Mark Kelly, vceit.com

Function - a procedure that calculates and returns a value. Typical examples are square root and MID (which returns a subset of a string). A function needs to be passed the value [parameter] to process, e.g. what is the number that needs to be square rooted? A function needs to know what value to send back to the code that invoked the function. 11VCE IT slideshows © Mark Kelly, vceit.com

A function is distinguished from a procedure by the presence of a pair of parentheses after its name. E.g. MID(), SQRT() The parentheses contain the values (parameters) that are passed to the function. 12VCE IT slideshows © Mark Kelly, vceit.com

All programming languages come with built-in pre-written functions for commonly-used tasks, E.g. – Convert text to uppercase – Calculate a cosine Lesser-used functions may be provided in a separate function library (e.g. for obscure mathematical or financial functions) 13VCE IT slideshows © Mark Kelly, vceit.com

User-defined functions are created by a programmer to carry out operations that are unique to a program. E.g. to return the first numeric digit in a string… 14VCE IT slideshows © Mark Kelly, vceit.com

User-defined functions are created by a programmer to carry out operations that are unique to a program. E.g. a program may need to return the first numeric digit in a string… 15VCE IT slideshows © Mark Kelly, vceit.com

BEGIN strString  “ABC123” // Use the FindDigit() function // to find the first digit in strString // Store the returned value in char. char  FindDigit(strString) SHOW char END 16VCE IT slideshows © Mark Kelly, vceit.com

BEGIN strString  “ABC123” // Use the FindDigit() function // to find the first digit in strString // Store the returned value in char. char  FindDigit(strString) SHOW char END 17VCE IT slideshows © Mark Kelly, vceit.com Parameter

BEGIN strString  “ABC123” // Use the FindDigit() function // to find the first digit in strString // Store the returned value in char. char  FindDigit(strString) SHOW char END 18VCE IT slideshows © Mark Kelly, vceit.com Function name

BEGIN strString  “ABC123” // Use the FindDigit() function // to find the first digit in strString // Store the returned value in char. char  FindDigit(strString) SHOW char END 19VCE IT slideshows © Mark Kelly, vceit.com Returned value stored in this variable

20VCE IT slideshows © Mark Kelly, vceit.com Begin function definition End function definition FUNCTION FindDigit(strParameter) L  Length(strParameter) If L = 0 then Return "-1" For counter  1 to L c = Mid(strParameter, counter, 1) if c >="0" and c<="9" then return c end if next counter Return "0" END FUNCTION

21VCE IT slideshows © Mark Kelly, vceit.com The value (“ABC123”) sent by the invoking statement is stored in this local variable. ‘Local’ means that no code outside of this function can see or change the value of strParameter.

FUNCTION FindDigit(strParameter) L  Length(strParameter) If L = 0 then Return "-1" For counter  1 to L c = Mid(strParameter, counter, 1) if c >="0" and c<="9" then return c end if next counter Return "0" END FUNCTION 22VCE IT slideshows © Mark Kelly, vceit.com Length( ) is another function – it may be inherent (pre- packaged with the programming language), or user- defined. The length of the incoming string is stored in variable L.

FUNCTION FindDigit(strParameter) L  Length(strParameter) If L = 0 then Return "-1" For counter  1 to L c = Mid(strParameter, counter, 1) if c >="0" and c<="9" then return c end if next counter Return "0" END FUNCTION 23VCE IT slideshows © Mark Kelly, vceit.com It’s important to validate incoming data. In this case, if the parameter is empty, return the value -1 to warn the invoking code of the error.

FUNCTION FindDigit(strParameter) L  Length(strParameter) If L = 0 then Return "-1" For counter  1 to L c = Mid(strParameter, counter, 1) if c >="0" and c<="9" then return c end if next counter Return "0" END FUNCTION 24VCE IT slideshows © Mark Kelly, vceit.com Start a loop to check each character in the string.

FUNCTION FindDigit(strParameter) L  Length(strParameter) If L = 0 then Return "-1" For counter  1 to L c = Mid(strParameter, counter, 1) if c >="0" and c<="9" then return c end if next counter Return "0" END FUNCTION 25VCE IT slideshows © Mark Kelly, vceit.com MID() is yet another function. It requires 3 parameters: MID(X, Y, Z) It returns Z characters starting at position Y from string X.

FUNCTION FindDigit(strParameter) L  Length(strParameter) If L = 0 then Return "-1" For counter  1 to L c = Mid(strParameter, counter, 1) if c >="0" and c<="9" then return c end if next counter Return "0" END FUNCTION 26VCE IT slideshows © Mark Kelly, vceit.com It’s vital that the values in the parameters are of the right data types (in this case string, integer, integer) and in the right order.

FUNCTION FindDigit(strParameter) L  Length(strParameter) If L = 0 then Return "-1" For counter  1 to L c = Mid(strParameter, counter, 1) if c >="0" and c<="9" then return c end if next counter Return "0" END FUNCTION 27VCE IT slideshows © Mark Kelly, vceit.com Notice how the parameters can be variables (e.g. counter) or constants (e.g. 1)

FUNCTION FindDigit(strParameter) L  Length(strParameter) If L = 0 then Return "-1" For counter  1 to L c = Mid(strParameter, counter, 1) if c >="0" and c<="9" then return c end if next counter Return "0" END FUNCTION 28VCE IT slideshows © Mark Kelly, vceit.com When MID( ) returns the single character at position counter from strParameter, the character is stored in variable c.

FUNCTION FindDigit(strParameter) L  Length(strParameter) If L = 0 then Return "-1" For counter  1 to L c = Mid(strParameter, counter, 1) if c >="0" and c<="9" then return c end if next counter Return "0" END FUNCTION 29VCE IT slideshows © Mark Kelly, vceit.com If the character is a digit…

FUNCTION FindDigit(strParameter) L  Length(strParameter) If L = 0 then Return "-1" For counter  1 to L c = Mid(strParameter, counter, 1) if c >="0" and c<="9" then return c end if next counter Return "0" END FUNCTION 30VCE IT slideshows © Mark Kelly, vceit.com Send the character back to the statement that invoked the FindDigit function.

FUNCTION FindDigit(strParameter) L  Length(strParameter) If L = 0 then Return "-1" For counter  1 to L c = Mid(strParameter, counter, 1) if c >="0" and c<="9" then return c end if next counter Return "0" END FUNCTION 31VCE IT slideshows © Mark Kelly, vceit.com When the first digit character is found you might want to exit the function to skip pointless further searching. Some languages offer EXIT statements to do this.

FUNCTION FindDigit(strParameter) L  Length(strParameter) If L = 0 then Return "-1" For counter  1 to L c = Mid(strParameter, counter, 1) if c >="0" and c<="9" then return c end if next counter Return "0" END FUNCTION 32VCE IT slideshows © Mark Kelly, vceit.com Move to the next character in the string

FUNCTION FindDigit(strParameter) L  Length(strParameter) If L = 0 then Return "-1" For counter  1 to L c = Mid(strParameter, counter, 1) if c >="0" and c<="9" then return c end if next counter Return "0" END FUNCTION 33VCE IT slideshows © Mark Kelly, vceit.com The last character has been checked. Returning a special value of zero is a flag that no digit was found.

BEGIN strString  “ABC123” // Use the FindDigit() function // to find the first digit in strString // Store the returned value in char. char  FindDigit(strString) SHOW char END 34VCE IT slideshows © Mark Kelly, vceit.com Let’s improve this

BEGIN strString  “ABC123” char  FindDigit(strString) if char = “-1” then SHOW “String is empty!” elseif char = “0” then SHOW “No digit found in “ & strString else SHOW “First digit found was” & char end if END 35VCE IT slideshows © Mark Kelly, vceit.com

Functions may require several parameters – like the MID() function. A more sophisticated FindDigit function might be able to search only part of the string, and optionally search starting at the end of the string. 36VCE IT slideshows © Mark Kelly, vceit.com

That function might look like this: FindDigitAdv(strString, intStart, intEnd, boolReverse) 37VCE IT slideshows © Mark Kelly, vceit.com

FindDigitAdv(strString, intStart, intEnd, boolReverse) The new function is passed one string, 2 integers and a Boolean value. The data types of the parameters that are passed must align with the data types of the parameters listed in the function. The use of Hungarian Notation (e.g. intStart) is vital to remind programmers of the data types being passed and received. 38VCE IT slideshows © Mark Kelly, vceit.com

FUNCTION FindDigitAdv(strString,intGo,intWhoa,boolRev) // start/end values of 0 mean “start at 1, end at the end” L  Length(strString) If L = 0 then Return "-1" if intGo = 0 then intGo  1 if intWhoa = 0 then intWhoa  L intStep  1 //default step value if boolRev = TRUE then // work backwards SWAP intGo, intWhoa intStep  -1 end if For counter  intGo to IntWhoa step intStep c = Mid(strParameter, counter, 1) if c >="0" and c<="9" then return c exit function end if next counter Return "0" END FUNCTION 39VCE IT slideshows © Mark Kelly, vceit.com

40VCE IT slideshows © Mark Kelly, vceit.com A block of code that controls which lines of code will be executed. The main varieties of control structures: Sequence Selection Iteration

41VCE IT slideshows © Mark Kelly, vceit.com Selection structure - The most obvious example is the IF/THEN/ENDIF structure which decides whether to execute code based on a defined condition, e.g. If AGE < 18 Then Print Junior Certificate End if Printing only happens if the Age < 18 test is true.

42VCE IT slideshows © Mark Kelly, vceit.com Iteration structure - any looping structure such as FOR/NEXT, DO/WHILE, WHILE/WEND, REPEAT/UNTIL.

43VCE IT slideshows © Mark Kelly, vceit.com Sequence simply means that lines are executed in the order they appear. Yeah - pretty basic. Includes statements like GOTO (which is deprecated* nowadays) and EXIT (to force an end to a procedure, function or loop) * Considered to be a bad idea

Mark Kelly vceit.com These slideshows may be freely used, modified or distributed by teachers and students anywhere but they may NOT be sold. they must NOT be redistributed if you modify them. This is not a VCAA publication and does not speak for VCAA. Portions (e.g. exam questions, study design extracts, glossary terms) may be copyright Victorian Curriculum and Assessment Authority and are used with permission for educational purposes. Thanks, guys! VCE IT THEORY SLIDESHOWS study design 44 VCE IT slideshows © Mark Kelly, vceit.com

Because you’ve been so good, here’s a picture you can look at while your teacher works out what to do next Visit vceit.com for more goodies 45