Software Development Topic 3 High Level Language Constructs.

Slides:



Advertisements
Similar presentations
Software development process. Explanation of the iterative nature of the software development process.
Advertisements

Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
JAVA Coursework (the same for 2A and 2B). Fundamental Information The coursework is 30 marks in your O’Level = 15% of the exam Must be word processed.
Software Development Sub Procedures, Functions and Parameters.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Modular Programming Splitting your program into functions and procedures.
Chapter 2 - Problem Solving
Chapter 2 - Problem Solving
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
String Variables Visual Basic for Applications 4.
Program Design and Development
Developing Software Applications Introduction to Programming Fundamentals Scoping in VB Simple Ifs in VB.
CS 201 Functions Debzani Deb.
Introduction to a Programming Environment
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Chapter 1 Program Design
Chapter 3 Planning Your Solution
The Project AH Computing. Functional Requirements  What the product must do!  Examples attractive welcome screen all options available as clickable.
Fundamentals of Python: From First Programs Through Data Structures
Python quick start guide
High Level Programming Language Constructs Higher Computing Unit 2 – Software Development.
Creating Embedded Formative Assessment Dr. Steve Broskoske Misericordia University EDU 533 Computer-based Education.
Fundamentals of Python: First Programs
Languages and Environments Higher Computing Unit 2 – Software Development.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Programming.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
07/10/ Strings ASCII& Processing Strings with the Functions - Locate (Instr), Mid, Length (Len), Char (ChrW) & ASCII (Asc)
E0001 Computers in Engineering Procedures: subprograms and functions.
Procedures and Functions Computing Module 1. What is modular programming? Most programs written for companies will have thousands of lines of code. Most.
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
By the end of this session you should be able to...
19/10/20151 Data Structures Arrays. 219/10/2015 Learning Objectives Explain initialising arrays and reading data into arrays. Design and write routine/s.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Developing an Algorithm
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
I Power Higher Computing Software Development The Software Development Process.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
Visual Basic Programming
Higher Grade Computing Studies 3. High Level Language Constructs Higher Computing Software Development S. McCrossan 1 Simple Data Types Integer: An integer.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
22/11/ Selection If selection construct.
Advanced Work with Embedded and Summative Assessment Dr. Steve Broskoske Misericordia University EDU 533 Computer-based Education.
The Software Development Process
I Power Higher Computing Software Development High Level Language Constructs.
COPYRIGHT 2010: Dr. David Scanlan, CSUS OBJECTIVES: How to write classes How to create an object from a class using the "New" keyword. How to communicate.
Top-down approach / Stepwise Refinement & Procedures & Functions.
Intermediate 2 Computing Unit 2 - Software Development.
1 Writing Software Kashef Mughal. 2 Algorithms  The term algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem.  An Algorithm.
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
Higher Computing Software Development -So Far- 5/10/10.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Controlling Program Flow with Decision Structures.
Programming Constructs Notes Software Design & Development: Computational Constructs, Data Types & Structures, Algorithm Specification.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
Unit 2 Technology Systems
3.1 Fundamentals of algorithms
COMPUTATIONAL CONSTRUCTS
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Learning to Program in Python
Coding Concepts (Basics)
4.1 Strings ASCII & Processing Strings with the Functions
Sub Procedures and Functions
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Software development process
Basic Concepts of Algorithm
Introduction to Computer Programming IT-104
Presentation transcript:

Software Development Topic 3 High Level Language Constructs

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

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

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

Variable types used in Visual Basic Integer – Whole numbers from about -32, ,000 Long – Whole numbers from about -2,000,000, ,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

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

Practical Software Development Topic 2 Strings and Branches

What we will learn Enforced variable declarations String Functions

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

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

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)

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

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

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?

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

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

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 paper, Q 4(a) 1 mark

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

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

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

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

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

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

Topic 3 Loops (Revision)

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

Practical Activity – 2 blocks max Revise counters by doing example & Revise for …. next loops by doing example 3.7 Revise Do …. Loop Until by doing example 3.12 Consolidate your learning by doing example 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

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

Topic 4 1 Dimensional Arrays

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

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

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

(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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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

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

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

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

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

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

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

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

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

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

Practical Activity Complete the practical activities for Topic 5 this is straight forward topic and should be completed quickly Either or – 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

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

Section 6 Modular Programming

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

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

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

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

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

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

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

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

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

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.

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)

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

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)

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

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

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

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

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

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

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 & 4.of Algorithm Call Get_input (radius, height) Call Calculate_Volume (radius, height, Volume) Call Display_Volume (Volume) End

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

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.

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.

Exemplar 3 – Suggested Solution

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)

Homework Exercise 3

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 and 6.6.2

Actual and Formal Parameters

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

Suggested answer

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

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

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

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

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

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