Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software Development Topic 3 High Level Language Constructs.

Similar presentations


Presentation on theme: "Software Development Topic 3 High Level Language Constructs."— Presentation transcript:

1 Software Development Topic 3 High Level Language Constructs

2 Resources Theory for the unit is covered in pages of How to Pass Higher Computing Throughout this topic you will be asked to complete practical tasks from the Software Development Using Visual Basic booklet

3 What you need to know Description and exemplification of a number of programming construct Features of high level languages Outline in pseudocode of high level language constructs

4 Re-cap – What you already know about data types A variable is used to store data in a program Variables can be of different types and must be declared at the start of the program String Real Integer Boolean Each data type has different memory requirements Declaring the data type allows a translator to allocate the correct amount of memory

5 Variable types used in Visual Basic Integer – Whole numbers from about -32,000 - +32,000 Long – Whole numbers from about -2,000,000,000 - +2,000,000,000 Single – Fractional numbers Double – Fractional numbers with more accuracy String – Text or words Boolean – Can have only 2 values T/F, Y/N, M/F

6 Practical Activity – 3 blocks Complete the practical activities for Topic 1 from the practical booklet. This is a revision topic and should be completed quickly

7 Practical Software Development Topic 2 Strings and Branches

8 What we will learn Enforced variable declarations String Functions

9 Enforced Variable Declarations You can set up visual basic to make sure you declare your variables in every program. If you do not declare your variables your program will not work correctly Tools, Options, Editor, Required Variable Declaration

10 String Functions LEN Ucase Lcase Asc Chr$ Each of these functions performs a task on a string. You will work out what each function does by creating a test program

11 Practical Activity – 1 block Beginning at Topic 2 read pages 1 – 5 Create the function test programs detailed on pages 6-7 – section 2.5 Report back by typing up a table of testing for each function. You should then write a sentence explaining what each function does. (bottom of page 7)

12 Parts of strings are extracted and used elsewhere in the program Extracts letters from the middle of a string Word = Computing, is, fun Keyword = Mid$(word, 7,5) PRINT Keyword What would the output of this program be? String Operations - Substrings

13 Word = Computing is fun Mid$(word, 7,5) PRINT Mid The code Mid$(word, 7,5) extracts 5 characters from the string variable called word, starting with the 7 th character. That means the output would be ing i Remember a space counts as a character

14 String Operations - Concatenation Concatenations means adding two strings together LET part1 = Man LET part2 = Chester LET whole = part1 & part2 PRINT whole What would be the output of this program?

15 Practical Activity Beginning on page 9 of Unit 2 in your practical software development book work through the practical task 2.7 – Devising User IDs Analysis and Design has been done for you Implementation has been party done You are wholly responsible for testing and evaluation Submit printouts for implementation, testing and evaluation

16 Practical Assessment Well done you are now ready to complete your first practical assessment. This will be done under assessment conditions. You may refer to previous programs you have created or to your programming manual You will be observed throughout the taskobserved throughout First Practical Assessment

17

18 Past paper questions on string operations A string variable mystring contains the word “elephant”. Using code from a programming environment with which you are familiar, show how you would extract the substring “ant” from mystring? 2006 paper, Q 4(b) 3 marks Describe what is meant by the string operation concatenation. 2006 paper, Q 4(a) 1 mark

19 Suggested Solutions Mid$(mystring, 6,3) extracts 3 characters from the string variable called mystring, starting with the 6 th character. That means the output from mystring “elephant” would be “ant” 1 mark for Mid$ function 1 mark for starting point (6) 1 mark for 3 characters (3) Concatenation is the process of joining strings together 1 mark

20 Formatting of Input and Output You should be familiar with writing programs using different input and output formats. Visual basic has a range of input and output formats Text boxes List boxes Radio buttons Image boxes It is not necessary for you to be able to use all of these but you should be aware of them

21 Multiple Outcome Selection Selection is used when a choice has to be made in a program. The simplest form of selection uses an IF statement IF 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

22 CASE STATEMENT CASE mark >= 70 PRINT “A” >=60 PRINT “B” >=50 PRINT “C” >=45 PRINT “D” CASE ELSE PRINT “No Award”

23 Repetition in Programs Fixed Loops – for ……….. Next Do …… Loop Until Do Until …….. Loop Do …… Loop While ……. Do While ……. Loop

24 Practical Activity – 1 block max To ensure your understanding of loops (repetition) and selection (IF and CASE) you should chose 2 programs from 2.8 – 2.11 which you should implement and test. Submit a structured listing for each program you implement

25 Topic 3 Loops (Revision)

26 Revision Remember we have already covered loops during Standard Grade so the following programs should be done as quickly as possible.

27 Practical Activity – 2 blocks max Revise counters by doing example 3.6.1 & 3.6.3 Revise for …. next loops by doing example 3.7 Revise Do …. Loop Until by doing example 3.12 Consolidate your learning by doing example 3.12.2 For each program you should submit a structured listing For one program you should also submit analysis, design, test table with screen shots and produce a user guide, technical guide and evaluation

28 Homework Exercise Complete homework exercise revising points covered so far Complete homework exercise revising points covered so far

29 Topic 4 1 Dimensional Arrays

30 Arrays The same type of data grouped together is called an array The array is given a meaningful name Each part of the array is called an element Each element is given a unique number

31 Declaring arrays You must declare the name and the number of elements in an array DIM name(9) as string DIM mark(9) as integer This tells the program the dimension of the array – ie the number of elements

32 Using Arrays in Visual Basic Visual basic array’s always start with element number 0 To set up an array to hold 5 names you would declare as follows DIM pupil_name(4) As String This instructs visual basic to set aside 5 elements to store 5 names

33 (Filling an array with 6 numbers entered by the user) Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Number(0)Number(1)Number(2)Number(3)Number(4)Number(5)

34 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 0 Number(0)Number(1)Number(2)Number(3)Number(4)Number(5)

35 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 0 Numbers(0) = inputbox(“ Please enter a number”) Number(0)Number(1)Number(2)Number(3)Number(4)Number(5)

36 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 0 Number(0) 8 Number(1)Number(2)Number(3)Number(4)Number(5)

37 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 0 Number(0) 8 Number(1)Number(2)Number(3)Number(4)Number(5)

38 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 1 Number(0) 8 Number(1)Number(2)Number(3)Number(4)Number(5)

39 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 1 Numbers(1) = inputbox(“ Please enter a number”) Number(0) 8 Number(1)Number(2)Number(3)Number(4)Number(5)

40 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 1 Number(0) 8 Number(1) 12 Number(2)Number(3)Number(4)Number(5)

41 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 1 Number(0) 8 Number(1) 12 Number(2)Number(3)Number(4)Number(5)

42 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 2 Number(0) 8 Number(1) 12 Number(2)Number(3)Number(4)Number(5)

43 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 2 Numbers(2) = inputbox(“ Please enter a number”) Number(0) 8 Number(1) 12 Number(2)Number(3)Number(4)Number(5)

44 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 2 Number(0) 8 Number(1) 12 Number(2) 1 Number(3)Number(4)Number(5)

45 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 2 Number(0) 8 Number(1) 12 Number(2) 1 Number(3)Number(4)Number(5)

46 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 3 Number(0) 8 Number(1) 12 Number(2) 1 Number(3)Number(4)Number(5)

47 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 3 Numbers(3) = inputbox(“ Please enter a number”) Number(0) 8 Number(1) 12 Number(2) 1 Number(3)Number(4)Number(5)

48 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 3 Number(0) 8 Number(1) 12 Number(2) 1 Number(3) 21 Number(4)Number(5)

49 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 3 Number(0) 8 Number(1) 12 Number(2) 1 Number(3) 21 Number(4)Number(5)

50 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 4 Number(0) 8 Number(1) 12 Number(2) 1 Number(3) 21 Number(4)Number(5)

51 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 4 Numbers(4) = inputbox(“ Please enter a number”) Number(0) 8 Number(1) 12 Number(2) 1 Number(3) 21 Number(4)Number(5)

52 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 4 Number(0) 8 Number(1) 12 Number(2) 1 Number(3) 21 Number(4) 17 Number(5)

53 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 4 Number(0) 8 Number(1) 12 Number(2) 1 Number(3) 21 Number(4) 17 Number(5)

54 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 5 Number(0) 8 Number(1) 12 Number(2) 1 Number(3) 21 Number(4) 17 Number(5)

55 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 5 Numbers(5) = inputbox(“ Please enter a number”) Number(0) 8 Number(1) 12 Number(2) 1 Number(3) 21 Number(4) 17 Number(5)

56 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 5 Number(0) 8 Number(1) 12 Number(2) 1 Number(3) 21 Number(4) 17 Number(5) 5

57 Dim Numbers(5) as integer For counter = 0 to 5 Numbers(counter) = inputbox(“ Please enter a number”) Next counter Counter 5 Number(0) 8 Number(1) 12 Number(2) 1 Number(3) 21 Number(4) 17 Number(5) 5

58 Glossary Definitions At the back of your jotter write a glossary definition of Array Element

59 Practical Activity You should now complete Topic 4 from the practical booklet

60 Modularity Code should be broken into manageable sections. Visual basic used two ways of breaking up a program Subroutines Functions

61 Subroutines Sections of code which do a specific task Can be called during the running of the program

62 Functions A function is a sub-program which returns a result Functions can be pre-defined or user-defined Pre-defined functions we have already met: LEN RND UCASE LCASE

63 User defined functions You must know The name of the function The type of result it will return What input data is needed (type)

64 Benefits of User defined functions Keeps main code simpler and more readable Same function can be reused elsewhere in the code Can be saved in a module library

65 Functions Like a subroutine but has a value which can be assigned to a variable These variables can be Local variables Global variables

66 Practical Activity Complete the practical activities for Topic 5 this is straight forward topic and should be completed quickly 5.5.1 5.5.3 Either 5.5.4 or 5.5.5 5.5.6 – full analysis, design, implementation, testing and evaluation (all but implementation and testing can be done at home) If you cannot complete all of this within class time you must catch up at home

67 Written Questions Answer questions 23 – 26 on pages 57 and 58 of How to pass Higher Computing Complete Homework Revision Ex 2Homework Revision Ex 2

68 Section 6 Modular Programming

69 Real life programming Examples so far have been short, simple programs Higher level programming requires the use of modules and parameters

70 Using variables in Higher programming You need to be familiar with and be able to use the following types of variables Local variable Global variable Variables (parameters) passed by reference Variables (parameters) passed by value

71 Local Variables We have already used local variables in the functions we created earlier A local variable is defined for use in one part of a program It can only be assigned a value inside a procedure, sub-routine or function Using local variables reduces the chances of a variable being changed accidentally if the same variable is used in other parts of a program

72 Global Variables Can be assigned a value anywhere in a program Should only be used for data that needs to be shared between different procedures Should be used with care due to the fact that they have the ability to change a value throughout a whole program

73 Glossary Definition At the back of your jotter write a glossary definition for Variable Local Variable Global Variable

74 Data Flow Variables which represent data can be used in many different parts of a program  Programs are divided into sub-routines (also called modules)  The movement of data between subroutines is controlled by using Parameters

75 Parameters A parameter is a variable or value that is passed into or out of a subroutine. Parameters are used to control data flow in a program When a subroutine is used within a program, the calling program must pass parameters to it. This is called Parameter Passing

76 Practical Task Create the program on pages 5 – 7 of your practical booklet (Topic 6) 6.5.1

77 Parameter Passing Parameters can be passed (called): Called/Passed by Reference or Called/Passed by Value

78 Passed by Value (in) The current value is passed into the subroutine Any changes made do not affect the program Used when the variable content does not need passed out.

79 The actual variable is passed into the subroutine The variable may be updated and the new value passed out. Used when the variable content needs to be passed out. Pass by Reference (out)

80 Diagram: Data Flow Area of Rectangle Enter Length Enter Breadth Calculate Area Display Area OUT: breadth OUT: area IN: length length breadth area PARAMETERS OUT: length IN: breadth IN: area

81 Algorithm showing Data Flow 1. Get length of rectangle (OUT: length) 2. Get breadth of rectangle (OUT: breadth) 3. Calculate the area (IN: length,breadth OUT: area) 4. Display the area (IN: area)

82 Glossary definitions At the back of your jotter, write a glossary definition of Passing a parameter by reference Passing a parameter by value

83 Using a structured chart to show data flow Your teacher will take you through the data flow diagram on pages 8 – 10 An alternative method is shown on pages 10 - 11

84 6.5.2.2 You should now add the parameters to the code you created earlier

85 Exemplar 1 (Parameter Passing) Software Specification Design, implement and test a program that will ask the user to enter the radius and height of a cylinder. The volume will then be calculated and displayed. You should use a structured chart to show the data flow before you do the algorithm in pseudocode

86 Diagram: Data Flow Volume of Cylinder Get Input Calculate Volume Display Volume OUT: height OUT: Volume IN: radius radius height volume PARAMETERS OUT: radius IN: height IN: Volume

87 Exemplar 1 Algorithm (With Data Flow) 1. Declare Variables 2. Get Input Out: radius, height 2.1 Get and store Radius 2.2 Get and store Height 3. Calculate Volume in: radius, height out: Volume 3.1 Volume = 3.14*radius*radius*height 4. Display Volume in: Volume 4.1 Display Volume of the cylinder

88 Implementation – Main Program Private Sub CmdRun_Click() !Declare the variables – Step 1. of Algorithm Dim radius As Single, height As Single, Volume As Single !Main part of the program – Steps 2. 3. & 4.of Algorithm Call Get_input (radius, height) Call Calculate_Volume (radius, height, Volume) Call Display_Volume (Volume) End

89 Sub Routines – refinements of Algorithm Private Sub Get_input (ByRef radius As single, height As single) radius = InputBox ("Enter the radius") (step 2.1 of algorithm) height = InputBox ("Enter the Height") (step 2.2 of algorithm) End Sub Private Sub Calculate_Volume(ByVal radius as Single, height As Single, ByRef Volume as Single) Volume = 3.14 * radius * radius * height (step 3.1 of algorithm) End Sub Private Sub Display_Volume(ByVal Volume As Single) PicDisplay.Print Volume (step 4.1 of algorithm) End Sub

90 Exemplar 2 (Parameter Passing) Using the previous example complete the following task Design implement and test a program that will ask the user to enter the distance travelled and the time taken for a journey. The speed will then be calculated and displayed.

91 Exemplar 3 (Parameter Passing) Software Specification Design, implement and test a program that will ask the user to enter the name of a pupil followed by four exam marks (out of 100). The average mark will then be calculated and the pupil name and average mark should be displayed.

92 Exemplar 3 – Suggested Solution

93 Data flow is important to ensure  correct data types are used  data does not get mixed up in a program  data only gets changed if desired  the correct data is used in the correct sub-routine (module)

94 Homework Exercise 3

95 Practical Activity To ensure you understand what happens in a program when a program is passed by value or passed by reference you should complete practical task 6.6.1 and 6.6.2

96 Actual and Formal Parameters

97 Past paper questions on variables A program uses global variables and local variables. Explain each of these terms. (2006 Past Paper, Q5) 2 marks

98 Suggested answer

99 Past paper question (2002, Q18) A program is used to analyse the number of road traffic accidents in six areas. The names of the areas and the number of accidents are stored in 2 separate arrays. Here is a possible algorithm for the part of the program which finds the area with highest number of accidents 2. Find area with highest number of accidents 2.1find position of maximum number of accidents in the array 2.2print name from corresponding position in area array

100 Part (a) of question Step 1 requires 2 parameters. Identify these parameters and state their data types and methods of parameter passing Break this question down before attempting to answer it identify the parameters state their data types state methods of parameter passing

101 Suggested solution part (a) A variable to store the position of the maximum number of accidents will be needed (Position) As this variable will store the position of the variable maximum the variable must be a whole number therefore the data type must be an integer It is presumed the position must be passed to other parts of the program (eg display) so therefore this variable should be passed by reference

102 Written Task Answer questions 17 – 22 on page 57 of How to Pass Higher Computing

103 End of Topic Activities Complete end of topic evaluation sheet Complete end of topic ActiVote Assessment

104 Learning Outcomes - High level programming language constructs Description and exemplification of the following constructs in pseudocode and an appropriate high level language: string operations (concatenation and substrings), CASE (or equivalent multiple outcome selection) Description and exemplification of real, integer and boolean variables; and 1-D arrays Description and exemplification of procedures/subroutines/subprograms, user- defined functions, modularity, parameter passing (in, out, in/out), call by reference/value, local and global variables, scope of a variable


Download ppt "Software Development Topic 3 High Level Language Constructs."

Similar presentations


Ads by Google