Home
        Software development process
         Contents
1.                                    r  Ls  first_project   Microsoft Visual Basic 2005 Express Edition BAX  File Edit View Project Build Debug Data Tools Window Community Help  MAERA  at   4 Ga   ak a Se DS     3  Fa ot  Toolbox  ix Form1 vb  Design     Start Page   xX    Solution Explorer  ax    All Windows F         2    1 i  A Commen con ay H first project  R Pointer S  j My Project   2b  Button ES  Form1 vb  v  CheckBox    rs    2 4 CheckedListBox       ComboBox  TA DateTimePicker  A Label  n   A LinkLabel      ListBox  222 ListView Solution Explorer g Data Sources      MaskedTextBox Properties  ix  waa  MonthCalendar Form1 System Windows Forms For v  Tal NotifyIcon   A  Z   13  NumericUpDown nm          o fay jowInTaskbar True    3  P  al geese Size 427  301      ProgressBar mi SizeGripStyle Auto  Error List vI  amp  StartPosition WindowsDefaultL  7  7 z a Tag  0 Errors     t  0 Warnings      i  0 Messages   O o Erors   D     7 Text My first Progra  Description File Line Column Project TopMost False p7  Text  The text assog    ted with the control   Ready                e Change the caption of the form from    Form 1    to    My first program in VB      by changing the text property in the properties window     e Add the    Enter your name    label  To do this  double click the label    icon from the toolbar     A blank label should appear on your form               All Windows F       h Pointer    ab  Button  CheckBox   2 9 CheckedListBox  G2 ComboBox    e Change its tex
2.                   Hello  world   Mid                       Hello  world   Mid  string_in  5  4       Write a brief statement summarising the effect of the mid  function           74 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                   HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          Testing the Asc function       Change     string_out   Mid  string_in 1 1     into   number_out   Asc string_in   and change    Dim string_out as String  to     Dim number_out as Integer    Run the program to test the Asc function     Edit the coding of the String Function Tester program   Like Len  Asc is another function that takes a string as its input   and returns a number  so make the following changes            You will also have to  change the  reference to  string_out in the final  line of code         Record the results in a table like the one below  adding a few tests of your  own until you are sure you understand what Asc does        Asc predefined function       Input string   Output number       A                   olol   lolo                      Write a brief statement summarising the effect of the Asc function           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  75             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED            hope you realised that the numbers produced by the  Asc function are the ASCII codes for the characters  you input  As you should know from the C
3.        Alter the coding like this     You will also need to alter the labels on   the form to prompt for a word rather than  a letter  and to enlarge the text boxes to  hold a word        uncoded_word   txtln text  length_of_word   Len uncoded_word   coded_word                                For counter   1 To length_of_word  uncoded_char   Mid  uncoded_word counter 1   ascii_uncoded   Asc uncoded_char    ascii_coded   ascii_uncoded   1   coded_char   Chr ascii_coded    If uncoded_char      Z    Then coded_char      A      If uncoded_char      z    Then coded_char      a     coded_word coded_word   coded_char   Next   txtOut  Text   coded_word   End Sub    ew Stage 4   testing    Devise some test data  This should include   e some normal data  e some extreme data    e some exceptional data     Run the program  using your test data  and record the results in a table           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  111             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          xy l  7 l  A Stages 5 and 6   Documentation and evaluation    As usual  you should     e print out hard copies of your form and the coding   e write a short user guide and technical guide   e write a brief evaluation of the program in terms of its fitness for purpose   user interface and readability     4 12 Do    Loop Until    We have used For    Next loops to repeat a section of program a set number  of times  This is fine if we know how many 
4.       HIGH LEVEL LANGUAGE PROGRAMMING     STANDARD ALGORITHMS       Next  we design the list of steps  pseudocode  and then the coding for the  command button     Pseudocode Visual BASIC coding   1  Do the following 10 times Fori 0To9   1 1  prompt the user to enter a name   Stored_name i    InputBox    Enter a  1 2  store the name in an array name       2  Next Next   3  Select a random number between   Randomize   1 and 10 Number                   4  Display the selected array TxtWinner Text     element Stored_name number     Variables required   i and number  both integers   stored_name Q   array of strings      Stage 3     Implementation       e Start a new Visual BASIC project    e Create a form as above    e Name the command button btnStart and the textbox txtWinner   e Enter the code for btnStart  declare the 2 variables and the array    e Save the project and form in a new folder     Stage 4     Testing  Run the program to make sure it works correctly  selecting a different winner    every time  To save time  you can enter the names as Q  W  E  R  T  etc  from  the top row of the keyboard           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  143          Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING     STANDARD ALGORITHMS          Lucky Prize Draw  version 2   Program specification    Design  write and test a program which prompts the user to enter four names  and four prizes     The program should select a lucky winner at random and 
5.       Here is the list of steps  pseudocode  required  Copy and complete the coding    yourself   Pseudocode    1  Set up variables to store the  three numbers and the loop  counter    2  Clear the list box   3  Store the multiplier entered by  the user   4  Repeat the following from 1 to  12   4 1  Calculate the answer   4 2  Assemble the message   4 3  Display the message   5  Next       Visual BASIC coding    Ol Sie i ive meme Step             answer   counter   multiplier  MESSAQE    Aeiyet tivses deere wuss    Si reitet Items Add  message   Next    Stage 3     Implementation    e Start a new Visual BASIC project  called Tables     e Create a form as above     e Give the command button  list box and text box appropriate names   e Enter the code for the command button     e Save all     2    F   A Stages 4  5 and 6     Testing  documentation and evaluation    Complete the testing  documentation and evaluation of the program in the    usual way           108 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING      BASIC CONSTRUCTS          4 10 For   Next tasks    Choose one  or more  of the following program specifications  and design   implement and test a program to fulfil the specification  Work through all the  stages of the software development process from analysis to evaluation for  your chosen task     Remember  A dragon in the dungeon eradicates mice    Times tables  advanced version  
6.     Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS             Stage 2     Design a gt  multiple greetings  Joey    We want the user interface to look like this     It has a button  a label and a list box     Toolbox 1x    All Windows F          Common Con         Pointer    ab  Button    V  CheckBox   2 4 CheckedListBox   j   ComboBox    tl  TA DateTimePicker   A Label          To create a list box   click on this icon                                  MaskedTextBox   Next  we design the list of steps  pseudocode  and then the coding for the  button    Pseudocode Visual BASIC coding   1  Do the following 25 times For Counter   1 to 25    2  Add the word    Hello    to the list box LstGreeti ems Add     Hello  Hello  Hello       Next           Note  It is usual to indent  the code within the loop to  improve readability     Stage 3     Implementation       e Start a new Visual BASIC project    e Create a form as above    e Name the button btnStart    e Name the listbox IstGreeting    e Enter the code for the button  declare a variable Counter as Integer      Make sure you save all           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  99             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          Stage 4   Testing    Run the program to make sure it works correctly  There is no  need for a table of testing for a simple program like this        It is tricky to be sure that th
7.     Programmer  e two text boxes for output 22 12 03 Total cost      7    e one button        Stage 2     Design     pseudocode  Here is a list of steps  pseudocode  to describe what this program has to do     store the number of slabs wide   store the number of slabs deep   store the cost of one slab   calculate the number of slabs required  calculate the total cost   display the number of slabs required  display the total cost         At the implementation  stage  we will turn  each of these steps  into VB code     SO GIB QOD    Stage 3     Implementation     creating the form    Start a new Visual BASIC project  give it a suitable name and  create a form to match the one above        e Set the caption  text property  of the form to be Belinda   s Slab Calculator    e Add the six labels    e Add five text boxes and position them on the form    e Name the textboxes  from top to bottom   txtWide  txtDeep   txtCost  txtTotalNumber  txtTotalCost    e Add a button  and position it on the form    e Change the name of the button to btnCalculate    e Change the text on the button to    Calculate slabs and cost                   If you can t  remember how to  do these  look   back to pages 41  to 42     Before going any further  make sure you have saved your work      e          SOFTWARE DEVELOPMENT  INT 2  COMPUTING  55             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED             Stage 3     Implementation     coding Don t w
8.    BEG oe  ry Now that your program is complete  write     e auser guide  e a technical guide     Stage 6     Evaluation    Pre  cw Write a brief evaluation of the program     e Is it fit for purpose   e Does it have a good user interface  e ls the code readable           70 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          3 12 Predefined string functions    In Section 3 10  we looked at the predefined functions Int  Cint  Round  Sqrt  and Sin  These functions are all designed to work with numbers  There are  also some useful predefined functions for manipulating strings  We are going  to examine UCase  LCase  Len  Mid   Asc and Chr        Make anew function tester v      program similar to the one  3 String Function Tester aax  you used in Section 3 10           Enter a string       e Start a new project  calling it String  Function Tester    e Create a form like this    e Enter the following code for the Apply  Function button     Result   by A  Programmer  Clear Apply 18 10 07  Function    Add code for the  clear button  as   you did in Section  3 7                Bam          Private Sub btnFunction_Click   di    Dim string_in As String   Dim string_out As String              string_in   txtEnter Text  string_out   UCase string_in     txtResult Text   string _out O  End Sub            SOFTWARE DEVELOPMENT  INT 2  COMPUTING  71             Learning and Teaching Scotla
9.    e Prompt the user to enter their type of membership in a club   Membership codes are J  for Junior      for Intermediate  and S  for  Senior      e Prompt the user to enter Yes or No   The program should accept    YES        Yes        yes        NO        No    or    no       e Prompt the user to enter a name   The program should only accept a name beginning with the letter    A       Hint  Use Mid      e Prompt the user to enter a password  which can include letters and  numbers   The program should only accept a password that is at least 6 characters  long   Hint  Use Len           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  133          Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING     STANDARD ALGORITHMS          5 3 Other standard algorithms    There are many other standard algorithms used by programmers  For this unit   you need to     e beable to recognise and code the standard algorithm for input validation  e know about four other standard algorithms  and understand where and  when they might be used      You don t need to be able to code these other standard algorithms unless you  study the Higher Software Development unit     The other standard algorithms you need to know about are     e finding a minimum   e finding a maximum   e counting occurrences  e linear search     All of these algorithms apply to a list of data items stored in a computer  system  These could be lists of names or lists of numbers  student marks  for  exam
10.   36  49  64  81  100  Hint  These are all numbers  squared    7  2 4  8  16  32  64  128  256  512  1024  2048  Hint  These are powers  of 2     Example 4 9 2 General Purpose Counting Program  Stage 1     Analysis    Program specification Data flow diagram   copy and complete         Design  write and test a program to       display any list of numbers  given the   starting number  lower limit   the final DER  number  upper limit  and the step   size     Stage 2     Design      arte General counting program  Sketch a user interface  something like  this  lower limit       It should have a command button  labels  upper limit     three text boxes for input and a list box C     for the output              104 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING      BASIC CONSTRUCTS       A list of steps  pseudocode  is shown below  Copy and complete the coding  yourself     Pseudocode Visual BASIC coding  1  Set up variables to store the three Dim        numbers and the loop counter Dim         Dim         Dim         2  Clear the list box EE  ltems Clear  3  Store the lower limit entered by lower   txt             Text  the user  4  Store the upper limit entered by Upper   ssedecceout terns  the user  5  Store the step size entered by the Stepsize                     user  6  Repeat the following  starting at 20   see geen Ko haere ay Step             lower limit  and going up to upper  limit in st
11.   4  15 6 4  0 4  0 100  5  1 56 5  299 5  0 020  6  28 3 6  929 6  0 111  7  23 8 7     922 7  0 001  8  2 38 8  99 8  0 002  9  15 6 9   99 9  0 200  10  99 3 10  299 10  0 120    What value would each of the following standard algorithms return  numbers  in brackets refer to columns 2 and 3       find minimum     find maximum     count occurrence of 15 6  99   0 001     linear search for 2 38  929   0 111      Which standard algorithm would be used by the national census organisation  to            cD    find out how many people called Mary live in the UK   find out the oldest person living in the UK   discover whether or not there was an individual called    Stan D  Ard al   Gorithm    in the UK          O             136 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING     STANDARD ALGORITHMS          5 4 Using arrays    All of the standard algorithms which you met in the last section operate on a  list of data items  In this section  we will see how a computer program can    store a list of items     Suppose a program was required which would prompt the user to enter and  store the names and test marks for three students  Let   s try     Stage 1     Analysis     data flow diagram    three names    e    three sets of test         gt        Stage 2     Design  We want the user interface to look like this   It has a single command button  and a title     We will use input boxes to enter the 
12.   A primary school teacher wants a program which will allow a pupil to  type in any whole number  The program will then display the relevant    times table  up to a maximum multiplier set by the pupil  The display  should be in the format        5 times 1 equals 5  5 times 2 equals 10  5 times 3 equals 15 and so on     Cost and weight calculator    A greengrocer needs a program which will allow him to type in the price i  of 1 kg of any item  The program should then display the cost of 1  0 1   0 2 up to 1 8  1 9  2 0 kg of the item   gt y  The output might look something like this  NV       0 kg costs   0   0 1 kg costs   0 20   0 2 kg costs   0 40   0 3 kg costs   0 60 and so on     Cubic numbers    A mathematician wants a list of cubic numbers  1  8  27  64  125        starting  and finishing at any point on the list  The results should be displayed like this     2 cubed   8  3 cubed   27  4 cubed   64 and so on           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  109             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          Quadratic function calculator    A pupil has been asked to draw a graph of the function y   3x    4   She needs a table of the values of the function between    5 and  5   She is not sure about the step size between points  so wants the  program to allow her to choose any step size        The results should be displayed like this     X 1  gt  gt  gt  gt  gt  gt  gt  gt  y 7  X 2  gt  gt  gt  gt 
13.   and write pseudocode instructions and draw a structure  diagram for each one         Don   t make it too complicated  In the tea example    broke    making tea    into  five steps  You could have broken it into many more detailed steps  For  example  getting a mug out of the cupboard could be broken down into smaller  steps     walk across to the cupboard  open the door  choose a mug  lift it out   close the door  walk back across the room  Try to break the task down into  between four and eight steps     We will use pseudocode in Section 3 when we start to develop our own  computer programs     There are other graphical methods of representing the structure of a program   These include structure charts and flowcharts  Some use a variety of    boxes     to represent different types of instruction  For example  you might see     to represent a repeated action    to represent a choice    to represent a step which will be broken down into  smaller steps          SOFTWARE DEVELOPMENT  INT 2  COMPUTING  17          Learning and Teaching Scotland 2009                SOFTWARE DEVELOPMENT PROCESS       1 6 Implementation    In software development  implementation is the process of converting a  program design into a suitable programming language     There are thousands of different programming languages out there  all with  their own advantages and disadvantages  For the purposes of this course  you  only need to know about two main groups  machine code and high level  languages  Y
14.   hidden spaces in the input text box  as this will affect your results        Len predefined function       Input string Output string Comment       Hello  world       HELLO  WORLD       123 One Two Three        28        A                   Write a brief statement summarising the effect of the Len function           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  73          Learning and Teaching Scotland 2009                      HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       Note  The Len function takes a string input  and returns a numeric output  so  really we should make a further change to the program     Dim string _out as String  should be changed to  Dim number_out as Integer     with other references to string_out also changed to number_oult      Testing the Mid  function    Edit the coding of the String Function Tester program        Change     string_out   Len string_in   into  string_out   Mid  string_in  1  1     Run the program to test the Mid  function  This time  you will need to edit the  Mid  line of code each time you run the program     Record the results in a table like the one below  adding a few tests of your  own until you are sure you understand how Mid  works        Mid  predefined function       Input    string Coding used Output string   Comment       Hello  world   Mid  string_in  1  1       Hello  world   Mid   string_in  2  1       string_in  3  1       Hello  world   Mid   string_in  1  2       Hello  world   Mid  string_in  1  3           
15.   trigonometric functions  sine  cosine and tangent   If you complete this unit   then continue to Higher Software Development  you will also learn to create  your own functions  so that you are not limited to the predefined ones provided  by Visual BASIC     If you want to experiment with the trigonometric functions  the code you need  is     result   System Math Sin  number 3 141 28 180  to get the Sine of a  number  in degrees     result   System Math Cos  number 3 14128 180  to get the Cosine of  a number    result   System Math Tan  number 3 14128 180  to get the Tangent of  number    Your table of testing might look like this                       Input Expected output   Actual output Comment  0 0   90 1   180 0   30 0 5                Important  Make sure you save this function tester program as you will use it  again later in the course           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  65          Learning and Teaching Scotland 2009                   HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          3 11 Working with words and numbers     example    The next example program uses all three data types     integer  single and  string     The problem   A basketball team manager wants a program which will input a player   s  name  squad number and points scored in the first three games of the  season  It should then calculate the player   s average score  to the nearest    whole number  and display a summary of the player   s details     Stage 1     Analysis     p
16.  55 Macro  Macro recorded 07 01 2804    You should be able to  recognise the actions you  Keyboard Shortcut  Ctrl Shiftt k took        Range   Ai    Select 7 x   With    electing Font For example  the first section    Name  arial  records the macro   s name   Size   18 and shortcut key      Strikethrough   alse  Superscript   False   Subscript   False Next comes the action of   OutlineFont   False selecting cell Al  changing   Shadow   False the font to18 point  making it    Underline   xlUnderlineStyleNoe bold  and so on    ColorIndex   xlautomatic   End With   Selection Font Bold   True   Range   A3 D13    Select   Range   D13    Activate       The macro is actually coded in a scripting language called Visual BASIC for  Applications  or VBA for short     What use is a macro   e Keep course 2 xls open     e Open course_copy xls   e Hold down Ctrl   Shift   K        The file course_copy xls should be automatically formatted by the macro to  be the same as course2 xls     If the user had several similar unformatted spreadsheets and wanted them all  formatted in this way  he could save a great deal of time by using the macro     A macro is a time saving program written in a scripting language which can be  activated by a series of key strokes for repeated use  A macro cannot exist  alone     it only works with an application program  in this case  Excel   In this  example  we have seen a macro being used with a spreadsheet  Macros can  be used with many other application packag
17.  7  Dim question as Integer       This new variable here is the loop  counter for the For    Next loop      Here is the For     Next loop to    Randomize   repeat the next section six times     For question   1 To 6  first   Int Rnd     10    1  second   Int Rnd     10    1  counter   0  correct_answer   first   second          This adds the Question number  as a title for the Input Box    Do  user_answer   InputBox    What is      amp  first  amp            amp  second  amp              Question      amp  question   counter   counter   1  If user_answer  lt  gt  correct_answer Then MsgBox    Wrong  try again       Loop Until user_answer   correct_answer  MsgBox    Well done  You took      amp  counter  amp      tries      Next  End Sub    You now have a loop within a loop  The technical term for this is nested  loops     e Make the above changes to the coding   e Alter the form to call this version 4   e Save the revised form and project        Carry out some thorough testing of your program  using normal   extreme and exceptional data           120 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          Now export your program as a template  so that you can keep the original  and  create a new final version based on the template     Modify the program so that it    e asks multiplication questions rather than addition   e uses random numbers between 1 and 12   e asks five q
18.  A gt B   BoC   Hello  gt  Ifmmp   Visual BASIC  gt  Wjtvom CBTJD  and so on          Let   s create a simple program to generate this type of code  It only works for  single letters  In Section 4 11 you will see how to code whole words or even  sentences     Stage 1     Analysis     program specification    Design  write and test a program to take any character in the alphabet  and  code it using the system A     B  etc     Stage 1     Analysis     data flow diagram       coded letter        any letter    Stage 2     Design     user interface Simple character coding program    We will use a simple design  with text  boxes for both the input and output  letters  a    code    command button  and a     clear    command button     Enter a character code         Coded character    by A  Programmer 19 10 07             SOFTWARE DEVELOPMENT  INT 2  COMPUTING  79             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          Stage 2     Design     pseudocode  The program must carry out the following steps     enter and store the input character  convert it to an ASCII code   add 1 to the code   convert it back to a character  display the character     OV  gt  ISS    Stage 3     Implementation    e Start a new project called AB_code    e Create a form like the one above    e Name the text boxes txtIn and txtOut    e Name the buttons btnCode and btnClear        The variables needed will be     A string variable to hold the input cha
19.  Alison Alison  Bill Albert alison  Cliff Bill end  Doris Bert END  Sarah Ahmed  Comment                      You should have noticed three problems with the program     e it doesn   t count names which start with a lower case    a     e it doesn   t stop when you enter    end    in lower case  e it adds the word END to the list     You should be able to modify your code to solve these problems   Hints     e Use the function UCase in step 3 4   e Make step 3 2 conditional  If name  lt  gt     END       e Make the end of loop condition into a complex condition using OR     FAY    St 5and6 D tati S  valia  A ages 9 an ocumentation and evaluation    As usual  you should     e print out hard copies of your form and the coding   e save your program and tidy up the files into a folder   e write a short user guide and technical guide   e write a brief evaluation of the program in terms of its fitness for purpose   user interface and readability           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  123          Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          Example 4 15 2 Password protection    Design  write and test a program for a bank cash machine  The  program should prompt the user to enter their PIN  If the PIN is  correct  it should display    Welcome to the VB Bank     message 1    If not  it should notify the user that their PIN was entered wrongly   message 2  and let them try again  but only allow three tries  I
20.  Print it     Saving your program    e Choose Save all from the File menu to save any changes you have made           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  45             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED                            When you exit  you may be   first_project cog  prompted to save changes to He Edt yew Favorites Toda ey w  both the project file and the form   O   E   sets a  ile Ds  file  Click Yes to both of these  FleandroiderTasis      in CF  trom   Other Places    emia  Visual BASIC will have created arr  s Ai e E  several files to store your project first project Va Fom Designer vb a  which will be found in a single Bele  a  folder  Do not delete any of VES  Vile source fie  these                       ew User guide User guide     Start the program by double  Write a couple of sentences describing clicking ow the first_project icon   how to use your program  Click ow the start icon on the merw    bar   Enter your name in the text box   Click the button     A message should appear     IYN Technical 3  Technical guide  QA g  Hardware used   Write a note of the types of hardware and Compaq Presario  2100 laptop    software you have used  Operating Systemi  MS Windows XP  Software used   Visual BASIC 2005 EE             46 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       Stage 6     Evaluation    
21.  Q2  Macros are written in scripting languages like VBA    Q3  They allow automation of frequently repeated complicated combinations  of actions    Q4  For automating a complex set of formatting commands in a word  processor or automating a complex query in a database    148 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                ANSWERS TO QUESTIONS       After Section 3 1    Q1  A command button  a text box  a label   Q2  This icon starts the execution of a program   Q3  Clicking on a command button is a common VB event     After Section 3 12    Q1     Description Predefined function    Returns the ASCII code of a  character   Selects a group of characters out  of a string   Turns any character into upper    Lcase   case  Takes an ACII code and returns     Ucase  the character it represents  Changes any character into lower ia  case  Counts the number of characters    Mid     Asc      l Chr  in a string  Q2  Mid  sentence 1 1    W   Mid  sentence 1 4    What   Mid  sentence 9 2    25   Mid  sentence 19 1       Q3    any letter ASCII code   gt     ASCII code character           string no  of characters          SOFTWARE DEVELOPMENT  INT 2  COMPUTING  149          Learning and Teaching Scotland 2009                ANSWERS TO QUESTIONS                         Section 4 9   a  For counter   3 To 36 Step 3   b  For counter   0 To 99 Step 9   c  For counter   10 To 0 Step    1   d  For counter   0 To 4 5 Step 0 75   e  For counter   50 
22.  Section 3  High level programming     getting started    3 1  3 2  3 3  3 4  3 5  3 6  3 7  3 8  3 9  3 10  3 11    Introducing Visual BASIC   Input and output     example   Input and output     tasks   Other forms of output   Declaring variables   Working with numbers     example  Adding a Clear button  Arithmetical expressions  Working with numbers     tasks  Predefined numeric functions  Working with words and numbers     example    10  13  15  16  18  18  18  19  20    22  22  25  26  26  27  29    35  38  48  49  51  53  60  61  62  63  66          SOFTWARE DEVELOPMENT  INT 2  COMPUTING     3          Learning and Teaching Scotland 2009             CONTENTS       3 12  3 13    Predefined string functions  Example program using Chr and Asc    71  79    Section 4  High level language programming     basic constructs    4 1  4 2  4 3  4 4  4 5  4 6  4 7  4 8  4 9  4 10  4 11  4 12  4 13  4 14  4 15  4 16    Making choices   If    Then    Else   Multiple Ifs   Using AND     example   Using And     task   Complex conditions   Repetition   Repetition using For    Next  Counting using For    Next   For    Next tasks   Using loops to work with strings  Do    Loop Until   Random numbers   Arithmetic tester   More examples using Do    Loop Until  Other forms of conditional loop    Section 5  High level language programming     standard    algorithms   5 1 Input validation   5 2 Input validation tasks   5 3 Other standard algorithms  5 4 Using arrays   55 Examples using arrays    
23.  Task 2     a  Work through the stages of the software development process following  the example on the previous pages as a model      b  The data flow diagram will look something like this  incomplete      Name Message  including    name and age         Age a     c  You will need two text boxes on your form  one for each of the inputs   and each with a different name      d  You will need two variables to store  the two items of data  so your code  will begin something like this     Private Sub btnMessage_Click     Dim name As String  Dim age As String    Note  Age is a number so we should  really store itas a number rather than as  a string  but it doesn   t matter here  because we are not going to do any  calculations with it     name   txtName  Text  age   txtAge Text             48 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          3 4 Other forms of output    In the    Welcome to VB    program  the output message appeared in a message  box  The line of code to do this was    MsgBox    welcome to VB       amp  name   It is also possible to make the output message appear either     e directly on the form in a label  or  e ina text box on the form     Output to a label  Two changes are needed to the program     Firstly  add a label on the form  and name it IbIMessage        Secondly  change the line of code from   MsgBox    welcome to VB       amp  name   to     IbIMes
24.  check  if over 75      Design  implement and test a program to solve the problem given above           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  95          Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          4 6 Complex conditions    In Section 4 4  we used a conditional statement with an AND in it     If percent  gt   60 And percent  lt  70 Then grade      B       This is an example of a complex condition  Complex conditions use a  combination of the terms AND  OR and NOT in logical combinations  Here are  some examples        If age  gt  60 And gender      F    Then pension      true      If country      UK    Or country      USA    Then language      English      If  temp  lt  12 And heat      T     Or  heat      X     Then turn_heating_on  If Not password   correct_password  Then MsgBox     Try again       If age  lt  5 Or Age  gt  85 Then eligible      No     If Not age  gt  5 And age  lt  85  Then eligible      No     If Not txtInput Text      Y     Then MsgBox     Are you sure       If Ans      Too    Or Ans      Two    Or Ans      To    Then Correct      True              Note  These two  examples are equivalent  to each other        Programming Task     Colour changer    Design  write and test a program which asks the user to enter a letter  and  turns the form     red if R or D is entered  green if Gor N is entered  blue if B or E is entered  yellow if Y or W is entered  black if C  A or K is entered     T
25.  correct answer    7  Display message  You took counter tries to get that right         Gio hes    The code for this is  counter   counter   1         Turn the pseudocode into Visual BASIC  and adapt your program accordingly   Edit the changes into your program  and check that it works           Improvement 3  The third improvement would be if the program could be made to  ask a different question each time  instead of always asking 2   2   To do this  we need to use VB   s random number generator                114 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING      BASIC CONSTRUCTS       4 13 Random numbers    Visual BASIC provides the programmer with a predefined  function Rnd to generate random numbers  Before we use it in  the Arithmetic Tester program  we will use a simple program with  a For    Next loop to learn how the Rnd function operates        Enter the following coding for the    Set up a form like this  command bunor    w  random numbers  Of x   Private Sub btnStart_Click              generates lists of random number       Dim number as Single  Dim counter As Integer    by A  Programmer 02 01 04 IstRandoms  tems Clear       For counter   1 To 10    number   Rnd    e Name the command button IstRandoms Items Add  number     btnStart Next  e Name the list box IstRandoms End Sub    Run this program  Write down the list of 10 random numbers produced     The Rnd function produces random
26.  gt  gt  gt  gt  y  16  X 3  gt  gt  gt  gt  gt  gt  gt  gt  y 31 andsoon       4 11 Using loops to work with strings    So far  we have only used the loop counter variable to display numbers   However  it can be used to do other things too     Example 4 11 1     Adapting the AB_coder program to code whole words    Version 2 of the AB_coder program from Section 4 3 can code single  characters  We can use a For    Next loop to adapt the program to code whole  words instead of single characters     Here is how it works  in pseudocode      Prompt the user to enter a word    Check how many characters there are in the word   Create a new    empty    coded word    Repeat the following for each letter in the word   4 1 1 extract the letter from the word   4 1 2 code it   4 1 3 add it on to the new coded word    Next letter    6  Display coded word     Fe I    o             110 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          and here is the code                  Private Sub btnCode_Click           adapted coding for the Code button     by A  Programmer on 19 10 07        Make a copy of the AB_code_v2  project  and call it AB_code_v3       Dim uncoded_char  coded_char As String  Dim uncoded_word As String   Dim length_of_word As Integer   Dim coded_word As Siring   Dim ascii_uncoded  ascii_coded As Integer  Dim counter As Integer             check how to do this on page 90      
27.  in any process  Pseudocode is read from top  to bottom  a structure diagram is read from left to right     A user guide tells you the features of the software  how to use it and  possibly a tutorial  The technical guide gives information on installation  and the technical specification of the computer required to run the  program     Normal  extreme and exceptional testing     A game could have bugs fixed  or new features added           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  147             Learning and Teaching Scotland 2009          ANSWERS TO QUESTIONS       After Section 2 1    Q1     Q2     Q3     Q4     Q5     Q6     High level is easier to understand    High level is easier to correct    Machine code and assembler are low level languages    Pascal and BASIC are two high level languages  there are many more      High level languages are designed to be understood by humans  LLLs  are designed to be understood by computers     High level languages are more readable  easier to fix bugs  designed for  problem solving     After Section 2 4    Q1     Q2     Q3     Q4     Interpreters and compilers   A compiler translates a whole program before executing it   An interpreter translates line by line     Compiled programs run more quickly because they are already in  machine code  so don   t need to be translated     After Section 2 6          Q1  Amacro is a program to automate a process in an application  it can be  activated by a combination of keys whenever it is needed   
28.  is easier to spot and correct  errors           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  23          Learning and Teaching Scotland 2009                LANGUAGES AND ENVIRONMENT       Here is a simple program written in a number of high  and low level    languages     10 Number   1   20 Answer   Number   1  30 PRINT Answer   40 END        The first three are all examples  of high level languages  BASIC   Logo and Pascal   All use words             that are understandable to  humans            make    number 1  make    answer    number   1  sav    answer       This is a low level    language called LDA  1    PROGRAM adder     fee 6502 assembler     STA 1000  VAR answer number  real  not so easy to LDA 1000  BEGIN understand         ADC  STA 1001  JSR OSWRCH    Number  1   Answer  number 1   WRITELN answer         This final one is 6502 machine code  which is  completely unintelligible to  most  humans     10101001 00000001  10000101 01110000    10100101 01110000  In fact  all five of these programs do more or less the    same job    think you will agree that high level  languages are much more practical for writing  programs than machine code     01101001 00000001  10000101 01110001  00100000 11101110                24 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009          LANGUAGES AND ENVIRONMENT          Questions     Which type of language  high  or low level  is easier to understand   Which type would be easiest to correct if it had 
29.  less than or equal to     equal to    lt  gt  not equal to                4 2 If    Then    Else  Example 1  Credit limit    The problem  When you try to take money out of an ATM   automatic teller machine  commonly called a    hole in the wall       you are only allowed to withdraw cash up to your credit limit  For  example  if your credit limit is   100 and you try to withdraw   50   then it should work fine  However  if you try to withdraw   150   you will not be allowed to and a message will appear on the  screen advising you that this is over your credit limit        Stage 1     Analysis     program specification   Design  write and test a program to    e take a number entered by the user   e compare it with a credit limit  100    e report    over the credit limit    if the number is over 100     Stage 1     Analysis     data flow diagram       over credit limit message on  screen if appropriate       any number              SOFTWARE DEVELOPMENT  INT 2  COMPUTING  83          Learning and Teaching Scotland 2009                   HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          Stage 2     Design     user interface ATM     credit limit check  The user interface will use a text box for data    entry  with two buttons  and use a message ah men do you      box for the response  wish to withdraw     Stage 2     Design     pseudocode Click to confirm       by A  Programmer 19 10 07       There are only two steps for the OK command  button  When it is clicked     
30.  number   Next   End Sub       For example  to produce     e random numbers between 1 and 20  change it to  number   Int  Rnd     20    1    e random numbers between 51 and 60  change it to  number   Int  Rnd     10    51    e random even numbers between 0 and 10  change it to  number   2   Int  Rnd     6              116 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING      BASIC CONSTRUCTS          Try experimenting with this line until you understand how it works   Sometimes it take a little thought to work out exactly what  numbers to put in  so that you get the right range and don t miss  out the highest or lowest number        Test your program with the following lines of code  In each case  make a note  of the results  and explain what you get                                      Line of code Results Explanation  number   Int Rnd     a   number   Int Rnd     20      number   eae   i n   2000   number   2    Int Rnd     50    1    number   2    Int Rnd     8    1    Tasks     e Modify your program so that when you click on the button  it  produces a single dice roll  a random number between 1 and 6    Hint  You won t need a For    Next loop        e Modify your program so that it produces a double dice roll  and  displays the number on each dice and the total score  Hint  You  will need to generate two random numbers every time you click the button           SOFTWARE DEVELOPMENT  INT 2  COMPUTI
31.  numbers between 0 and 1  To produce  random whole numbers between 1 and 10  we need to do three things to the  line number   Rnd       e First  we need to multiply by 10 to produce a random fraction between 0  and 10    e Then we need to    chop off    the fraction part using the function Int  see  Section 3 10     e Finally  we need to add 1  otherwise the highest number will always be 9   as it is rounded down by the Int function     Change the line  number   Rnd      into  number   Int  Rnd     10    1          SOFTWARE DEVELOPMENT  INT 2  COMPUTING  115          Learning and Teaching Scotland 2009                   HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS       Now run the program again  Write down the list of random numbers  This time  they should all be whole numbers between 1 and 10     Stop the program  Then run the program again  And again    You will notice that it always generates the same list of    random    numbers  To  make them really random  you need to add the keyword Randomize at the  start of the program  anywhere before the keyword Rnd      The coding for your random number generator should now look like this     Private Sub btnStart_Click           generates lists of random number    Dim number as Single  Dim counter As Integer    Randomize    IstRandoms  tems Clear            You can adapt this line ina  variety of ways to produce  other sets of random numbers        For counter   1 To 10  number   Int  Rnd     10    1  IstRandoms Items Add
32.  of the Chr function           SOFTWARE DEVELOPMENT  INT 2  COMPUTING     77          Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       Questions    1  Match these predefined functions to their descriptions  one has been  done for you      Description Predefined function    Returns the ASCII code of a    character eon    Selects a group of characters out    Asc  of a string  Turns any character into upper nate  case  Takes an ACII code and returns    Ucase  the character it represents  Changes any character into lower rae  case  Counts the number of characters Chr  in a string  2  If sentence      What is 25 times 8      what would be the output from    a  Mid  sentence 1 1    b  Mid  sentence 1 4    c  Mid  sentence 9 2    d  Mid  sentence  19 1     3    Which predefined functions are represented by these data flow  diagrams        ASCII code        any letter    ASCII code character          string No  of characters             78 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          3 13 Example program using Chr and Asc    Using these two predefined functions you can manipulate strings in all sorts of  interesting ways     Maybe when you were younger  you tried communicating with  your friends using codes  The simplest code is the one which  replaces each letter with the following letter from the alphabet  so    
33.  on an older one           90 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING      BASIC CONSTRUCTS          4 4 Using AND   example  Example  Exam Mark Grader    The problem  A program is required that can be used to assign  grades to exam marks automatically  Over 70  is an A  over 60   is a B  over 50  is a C  over 45  is a D and less than 45  is a  fail        Stage 1     Analysis     program specification  Design  write and test a program to     e prompt the user to enter the highest possible score for an exam  e g  80   e prompt the user to enter a student   s name  first name an surname    e prompt the user to enter the student   s mark  e g  63    e calculate the percentage mark   e display a message giving the student   s initials  percentage and grade     Stage 1     Analysis     data flow diagram        exam out of     message on screen  including    student name  percentage mark  student name      student mark es  Stage 2     Design     user interface    The user interface will use text Eyam Mark Grader    boxes for data entry  with two  command buttons  and use a    Enter possible score  message box for the response     Enter student   s first name    Enter student   s surname     J    K clear  Click to confirm       by A  Programmer 19 10 07    Enter students score             SOFTWARE DEVELOPMENT  INT 2  COMPUTING  91             Learning and Teaching Scotland 2009          HIGH LE
34.  program we developed in Section 3 13  for  coding letters using the A   gt  B code  When you tested it  you  should have discovered that it works well for every letter  except  Z  The problem is that if you add one to the ASCII code for Z you  get the ASCII code for a bracket symbol        We can correct this by using two  conditional statements to cover the two  special cases     upper case and lower case  Z     Private Sub btnCode_Click      adapted coding for the Code button  version 2      py A  Programmer on 19 10 07    Dim uncoded_char  coded_char As String    e Load the program AB_code  Dim ascii_uncoded  ascii_coded As Integer    e Select Export Template from the File  menu    e Choose Project Template as the  project type    e Click Finish to save your AB_code  project as a template     uncoded_char   txtIn text  ascii_uncoded   Asc uncoded_char     ascii_coded   ascii_uncoded   1    e Select New Project from the File menu  coded_char   Chr ascii_coded   e Instead of Windows Application  select  the template you have just created     special case for Z and z  e Name the new project AB_codev2  If uncoded_char      Z    Then coded_char      A     e Alter the coding as shown  changes in If uncoded_char      z    Then coded_char      a     bold    e Run the program  carefully testing that it txtOut text   coded_char  handles Z and z correctly  End Sub       e Save all changes         Note  Follow the steps above carefully whenever you  want to create a new program based
35.  programmer 15 09 07                   It   s a good idea at this stage to save your work  by selecting Save all from the File menu  It will be saved using the name you  gave it when you started           Save Project  Name  first_project   Location  C  My Documents  Visual Studio 2005 Projects v  Solution Name  first_project Create directory for solution                   Now you can try to run your program     e Todo this  either choose start from the run menu  or just click on the   m        start icon on the menu bar  pee    Note  VB uses a built in interpreter to translate your program into machine  code line by line as it executes the program  Some versions of VB also have a  compiler which lets you convert completed VB programs into stand alone  executable files          42 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED              The form should appear  with a cursor in    the text box  Nothing happens             That   s because we have only  created the form  We need to  write program code for what is to  happen when someone clicks  the command button  an event     e Click on the end icon to return to th _  editing environment  SH f      Stage 3     Implementation     coding    e Enter your name and click the  command button     We need to implement Formi vb     Start Page   Form1 vb  Design     x  the coding for the button   binMessage v      Click v  E Public Cla
36.  student_ student_    namel N   name 1  nameal     name 3  name 4        Similarly  Dim mark 4  as Integer sets up an array that can store five integers        pe A A   A A             140 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     STANDARD ALGORITHMS          The really useful thing about an array is that the program can refer to the  whole array at once  or to any single element     Now let   s see how using arrays lets us simplify the program we have been  working on     Here is the version that doesn   t work  adapted for five students      Private Sub btnDataEntry_Click             Dim student_name As String   Dim mark As Integer   Dim i as Integer    Fori 1to5   student_name   InputBox    Enter a name      mark   InputBox    and their mark       Next    Fori 1to5  IstOutput ltems Add  student_name   IstOutput ltems Add  mark    Next   End Sub    and here is a version that does work  using arrays        Private Sub btnDataEntry_Click            Dim student_name 4  As String   Dim mark 4  As Integer   Dim i as Integer             Fori 0to4  student_name i    InputBox    Enter a name      mark i    InputBox    and their mark      Next    Fori 0to4  IstOutput ltems Add  student_name i    IstOutput ltems Add  mark i     Next   End Sub       box     The first time through the  loop  i   0  so the first name  and mark are stored in array  elements student_name 0   and mark 0   Next time  
37.  the menus  commands and options are supposed to do  Could it  be improved in any way     The third aspect of evaluation that we will consider is readability  This is of no  direct concern to the user of the software  but is important for any  programmer who may need to understand how the program works  It is to do  with the way that the coding has been implemented  Is it possible for the  program code to be read and understood by another programmer  perhaps at  a later date when the program is being updated in some way  In Section 3 we  will see some techniques for improving the readability of a program           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  19          Learning and Teaching Scotland 2009                SOFTWARE DEVELOPMENT PROCESS       1 10 Maintenance    This final phase happens after the program has been put  into use  There are different types of maintenance that  might be required  These are called corrective  maintenance  perfective maintenance and adaptive  maintenance  You don   t need to know these names until  Higher level  but it is useful to think about what they mean     Corrective maintenance means fixing any bugs that appear once the  program is in use  Of course  these should all have been discovered during  testing  However  most programs  but not the ones you will be writing  are so  huge and complex that some bugs are bound to slip through unnoticed  If the  bugs are serious in nature  the software company might issue a free    patch     on its
38.  the original PIN program  but use it to begin the  new program        Select Export Template from the File menu  Choose Project Template as the template type   Leave all the default settings on the next page  and click Finish  VB    will save the PIN program as a template    Select New Project from the File menu   Instead of Windows Application  select the template you have just  created    Give the new project a name  e g  Password_program   and continue  as normal              126 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS       4 16 Other forms of conditional loop    There are four variations of conditional loop in Visual BASIC  So far  we have  only used the Do    Loop Until form of loop  In some high level languages  this  is the only kind of conditional loop  and it is possible to manage without the  other kinds  However  for completeness  here is a brief summary of all four                 Type of loop Syntax Comments  Do Always executed at least  Line s  of code to be once  as condition is  Do    Loop Until tested at the end  stops  repeated a    z when the condition  Loop Until condition  becomes true  Do amall Conaion Only executed if the  i Line s  of code to be ee    ate  Do    Until Loop condition is true  as it is  repeated ence  tested at the beginning  Loop  Do Loops while the  l Line s  of code to be condition is true  and  Poa EROP ANIG repeated Sto
39.  website so that users can download the patch and install it with the  software  so fixing the bug  If it is a minor bug  they may not bother     Perfective maintenance is adding new features to the software  These might  be suggested as a result of the evaluation stage or they might be suggested  by users  These new features will then be added to the software and re issued  as a new version  That   s why software often has version numbers    Each version results from corrective and perfective maintenance of the earlier  versions  So  for example  BloggProg 3 2 will be similar to BloggProg 3 1  but  with bugs fixed and some new features added     The third type of maintenance is adaptive maintenance  This is where the  software has to be changed to take account of new conditions  The most  obvious example is when a new operating system comes out  Perhaps  BloggProg 3 2 was designed to run under Windows 2000  When Windows XP  came along  changes had to be made to BloggProg so that it would work  under the new operating system           20 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                SOFTWARE DEVELOPMENT PROCESS       Questions    1    Match up these descriptions of the stages of the software development  process with the correct names  one has been done for you      Stage    Evaluation    Testing    Implementation    Design    Documentation    Analysis    Maintenance    Description    Writing a user guide and technical gui
40.  what the program should do    Finally  run the program using your chosen test data and compare the actual  results with the expected results  If they agree  all is well  If not  you may need  to go back and de bug the program     Table of testing for Belinda   s slab calculator                               Inputs Expected outputs Actual outputs   Comment  Cost    Total Total Total  Wide Deep   of Total cost  number number cost  slab  4 5 2 00 20 40 00  N    orma    o   20  199 200 398 00  data  4 5 5 9 2 99 20 59 80  10000   9000   2 00   90000000   180000000  Exirem 0 an an 0 0  e data y y   5  4 2 50 20 50 00                                     58 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009             HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       Activity  SiGe Add some other examples of normal and extreme data to the  I  A table  then test the program to make sure it handles them all    correctly     Finally run some exceptional data tests and note the results  either in the table  or as notes below it      Summarise your testing        The program carries out all calculations according to the specification  when supplied with sensible data  However  the program does give  results when supplied with negative data  without generating an error  message  Also  the program does not display the total cost in the  standard format  e g    59 80 is displayed as 59 8     Stage 5     Documentation    Print the form image and c
41. 1  store the number entered by the user  2  if itis over 100  display the warning message     There is only one variable required     a numeric variable to store the amount  entered by the user  As this could be something like 23 50  it needs to be a  single rather than an integer     Stage 3     Implementation    e Start a new project  called ATM    e Create a form as shown above    e Name the text box txtInput    e Name the buttons btnOK and btnClear        e Enter the coding for the OK command button  as shown below   Private Sub btnOK_Click                 coding for the OK command button     warns the user if the amount is over the credit limit    100      written by A  Programmer on 19 10 07  Dim Number as Single  Number   txtInput Text  If Number  gt  100 Then MsgBox Number  amp     is over your credit  limit      End Sub    e Enter the coding for the Clear button as usual           84 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS       ewe Stage 4     Testing      gt     Devise some test data  This should include     e some normal data  for example   20  clearly under the limit   120  clearly over the limit   e some extreme data  for example   99 99  just under the limit   100 00  exactly on the limit   100 01  just over the limit   e some exceptional data  for example     5  a negative number   999999 9999  a ridiculously large number   A  a letter when a number is ex
42. Answers to questions    82  83  86  91  95  96  97  98  101  109  110  112  115  118  121  127    129  133  134  137  142    146          4 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                INTRODUCTION       Introduction  Tutor guide    This teaching and learning material is designed to cover all of the content  needed by a learner to pass the Software Development unit of Intermediate 2  Computing  However  it is the responsibility of the tutor to check the content  coverage against the SQA unit specification     The pack covers the knowledge and understanding required for Outcome 1  assessment  and the practical skills required for Outcome 2  There are many  opportunities throughout the unit  especially in Sections 3  4 and 5  for  students to demonstrate the practical skills required  and generate the  required evidence     For unit assessment  use should be made of the NAB assessment materials  provided by SQA  multiple choice test and practical skills checklist      Note that learners completing this unit as part of the Intermediate 2 Computing  course should be given opportunities to develop the higher order problem   solving skills required for the external course assessments  examination and  practical coursework tasks   This can be done by providing past exam paper  questions and further programming tasks  such as the specimen coursework  task provided by SQA     The pack has not been designed for a student to use uns
43. Do    Loop Until   make use of the loop counter within a loop   create nested loops  a loop within a loop    create and use a Project Template     Check all the items on this list  If you are not sure  look back through this  section to remind yourself  When you are sure you understand all of these  items  you are ready to move on to Section 5           128    SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING     STANDARD ALGORITHMS          Section 5  High level language programming      standard algorithms    5 1 Input validation  There is a saying in computing  which goes   Garbage in  garbage out   or just GIGO     You have probably heard stories about people who have  received a gas bill for   1 000 000 or similar  Usually the  company will blame this on a    computer error     However   computers very rarely make mistakes  More often  the  problem is that the computer has been fed with the wrong  data to start with  If you feed in wrong data  then the  answer that comes out of the system will be wrong too        wrong data in wrong answer out         A well designed program should prevent  or at least reduce the likelihood  of  wrong data being entered into a system     For example  there was a program in Section 4 4 which took in a student   s  exam mark and worked out their grade  Suppose a student scored 59  so  should have been given a    B     but the teacher was in a hurry  and the m
44. ELOPMENT  INT 2  COMPUTING  13          Learning and Teaching Scotland 2009          SOFTWARE DEVELOPMENT PROCESS       Check your answers below     You should have the following                                Stage Description  1  Analysis B  Deciding what type of game you want to create and  what features you want it to have   F  Working out the details of what the screens will look  2  Design like  what menus and functions there will be  and  other detailed aspects of the program   3  Implementation   D  Actually writing all the program code   4  Testing G  Getting users to try out the program to make sure it  works under most conditions   BS DCRmGniatian A  Writing a user guide and technical guide for the  software  E  Checking that the program does what it is supposed  6  Evaluation to do  is easy to use and can be fixed if there is a  problem   C  Adapting the game to run on a different type of    7  Maintenance       computer              14 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                   SOFTWARE DEVELOPMENT PROCESS          In this course  especially in Section 3  onward  you will be putting this  software development process into  practice when you produce some  simple programs in a high level  computer programming language           For the moment  it is worth trying to  learn the steps in the correct order     usually use a silly mnemonic for this   like     A Dragon In The  Dungeon Eradicates  Mice    Impleme
45. FORTRAN was  designed for carrying out mathematical and scientific calculations  Prolog is  good for developing programs in artificial intelligence  COBOL is for  developing commercial data processing programs     Activity  ee  Make a list of six or so programming languages  you can find    y A J   these in textbooks or on websites   For each one  write down  LAN where it gets its name from and what it is    good    for     Here are some examples to get you started                          Name Source of name Used for   Ada After Countess Lovelace   US military systems  Logo Greek for    thought    Education   FORTRAN FORmula TRANslation Early scientific language       All these languages are what we call high level languages  That is to  distinguish them from low level languages  What do we mean     2 2 High  and low level languages    Inside every computer  there is a processor  This is a chip containing digital  electronic circuits  These circuits work with tiny pulses of electricity and  electronic components  The pulses of electricity can be represented by the  digits 1 and 0  Every item of data  and every instruction for the processor  is  represented by a group of these binary digits     Processors only    understand    these binary digits  The only inputs you can  make to a processor are groups of binary digits  The only output that a  processor can make is a group of binary digits           22 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Sco
46. Hardware is the items of equipment that make up a computer system     Q2  Examples of software include any application packages  e g  Microsoft  Word   any operating system  e g  Windows 97  or any document or file                                                  Q3   Item Hardware Software  monitor y  database y  Windows 97  scanner y  an email  Internet Explorer y  mouse y  modem y  a computer game y  a word processor  digital camera y             146 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                ANSWERS TO QUESTIONS          After Section 1 10    Q1     Q2     Q3     Q4     Q5     Q6     Stage Description   Evaluation Writing a user guide and technical guide for the  software   Testing Working out the details of what the screens will    look like  what menus and functions there will  be  and other detailed aspects of the program     Implementation Deciding what type of game you want to  create  and what features you want it to have     Design Actually writing all the program code    Documentation Adapting the game to run on a different type of  computer    Analysis Checking that the program does what it is    supposed to do  is easy to use and can be  fixed if there is a problem     Maintenance Getting users to try out the program to make  sure it works under most conditions   The three criteria used to evaluate software in this unit are fitness for    purpose  user interface and readability     Both show the main steps
47. NATIONAL QUALIFICATIONS CURRICULUM SUPPORT    Computing  Software Development    using VB2005 2008 EE     INTERMEDIATE 2           The Scottish Qualifications Authority regularly reviews  the arrangements for National Qualifications  Users of  all NQ support materials  whether published by Learning  and Teaching Scotland or others  are reminded that it is  their responsibility to check that the support materials  correspond to the requirements of the current  arrangements              Acknowledgement  Learning and Teaching Scotland gratefully acknowledges this contribution to the  National Qualifications support programme for Computing        Learning and Teaching Scotland 2009    This resource may be reproduced in whole or in part for educational purposes by  educational establishments in Scotland provided that no profit accrues at any stage           2 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009       Contents    Introduction  Tutor guide    Student guide    Section 1  Software development process    1 1  1 2  1 3  1 4  1 5  1 6  1 7  1 8  1 9  1 10    Software   The development process   A dragon in the dungeon eradicates mice   Analysis   Design   Implementation   Testing   Documentation   Evaluation   Maintenance    Section 2  Languages and environments    2 1  2 2  2 3  2 4  2 5  2 6  2 7    Computer languages   High and low level languages  Translators   Interpreters   Compilers   Text editors   Scripting languages and macros   
48. NG  117             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS       4 14 Arithmetic tester       We can now combine what we have learned     Arithmetic tester  Joe          about random numbers with our arithmetic  tester program from Section 4 12     Here is the current version of the form and  coding for the command button     by A  Programmer 13 03 09    Arithmetic tester v 2                      Coding for command button    Private Sub btnQuestion_Click                generates a question to the user     and waits for the correct answer    Dim user_answer As Integer  Dim correct_answer As Integer  Dim counter as Integer           Make sure you have  added the extra    counter   0 lines of code here    correct_answer   4    Do  user_answer   InputBox    What is 2   2       counter   counter   1  If user_answer  lt  gt  correct_answer Then MsgBox    Wrong  try again    Loop Until user_answer   correct_answer  MsgBox    Well done  You took      amp  counter  amp      tries      End Sub          118 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009             HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          e Change the label on the form to read version 3   e Modify the coding as below  changes in bold         Private Sub btnQuestion_Click                generates a random question to the user     and waits for the correct answer            The variables first and second  
49. ONMENT       2 4 Interpreters    Option 1 is to go to the conference yourself and deliver your speech in English  one sentence at a time  After each sentence  a professional translator  who  can understand English and also speaks fluent Japanese  will turn your  sentence into Japanese  This will continue right through your lecture  with the  interpreter translating each sentence as you go along     Computer interpreter programs work in the same way  The interpreter takes  each line of high level language code  translates it into machine code and  passes it to the processor to carry out that instruction  It works its way through  the high level language program one line at a time in this way     This works fine  but it has a couple of important  AALY disadvantages  Think about the analogy again  Your 1   a J      f KL hour lecture will take 2 hours to deliver  as each  od ME ney sentence is spoken by you in English  then by the  ee    interpreter in Japanese  The other disadvantage is that  if you are then asked to deliver your lecture again in       iJ another Japanese city  you will need to have it  translated all over again as you are delivering it the  second time     The same problem is true of computer interpreters  The process of translating  the high level language program slows down the running of the program   Secondly  the high level language program needs to be translated every time  it is used  This is a waste of computer resources and means that the user  must al
50. Scotland 2009                SOFTWARE DEVELOPMENT PROCESS          1 3 A dragon in the dungeon eradicates mice     Exactly the same process goes into the production of a piece of software  The  software engineers and their colleagues carry out all the stages of the  software development process in order     analysis  design  implementation   testing  documentation  evaluation  maintenance     BENS    e Activit   IK Activity   Consider the production of a new game program by a software company   Here are descriptions of the seven stages  but they are in the wrong order   Copy and complete another table like the one above  and slot the stages into  the correct places     A  Writing a user guide and technical guide for the software     B  Deciding what type of game you want to create and what features you  want it to have     C  Adapting the game to run on a different type of computer   D  Actually writing all the program code     E  Checking that the program does what it is supposed to do  is easy to use  and can be fixed if there is a problem     F  Working out the details of what the screens will look like  what menus and  functions there will be  and other detailed aspects of the program     G  Getting users to try out the program to make sure it works under most conditions        Stage description       1  Analysis         Design         Implementation         Testing            Evaluation          2  3  4  5  Documentation  6  7      Maintenance                SOFTWARE DEV
51. Teaching Scotland 2009                SOFTWARE DEVELOPMENT PROCESS       containing all the instructions about how to work the new TV  and probably a  technical manual for repair engineers     Stage 6  Evaluation    Once the model is in production  the company will want to evaluate the new  product  Does it do what it is supposed to do  Is it easy to use  And  from the  engineer   s point of view  is it easy to repair     Stage 7  Maintenance    Stage 6 should be the end of the story  but in the real world there needs to be  Stage 7  Maintenance  There are different kinds of maintenance  fixing faults  that turn up once it is being used regularly  improving the design to make it  even better or making changes for other situations  like making a version that  will work in another country      These seven stages are required for the production process     TAN   ee Ok  let   s see if you have got the idea        Choose any type of manufactured object     it could be a car   an item of clothing  a ready made meal  a toy  a piece of  furniture  a building  etc     N       Now copy and complete this table  writing one sentence to describe each of  the seven stages in the production of your chosen object              Object chosen           Stage Description       1  Analysis       2  Design       3  Implementation       4  Testing       5  Documentation       6  Evaluation       7  Maintenance                12 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching 
52. The evaluation of your program should answer the  following questions     e ls the program fit for purpose   Does it do what is  required by the specification     e ls the user interface good to use  Could it be improved    e ls the program coding readable  so that another programmer could  understand how it works      Your answers might look like this     Evaluation    The program fulfils the specification  If yow enter a name  it  responds with aw appropriate message     The user interface ix easy to use   it prompty for input  and the  command button iy clearly labelled     The coding hay comment lines and wey sensible variable  names to make it readable     Stage 7     Maintenance    Maintenance might involve making the change suggested  above or adapting the program to run on a different type  of computer system  You don   t need to do either of these  for Intermediate 2                   SOFTWARE DEVELOPMENT  INT 2  COMPUTING     47          Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          3 3 Input and output     tasks  Task 1     A similar program  Develop a similar program to the one you have already written to    output a personalised Happy Birthday message  Obtain hard  copies of the form and code for your new program        Develop a new program which asks the user to enter their name  and age  and displays a message saying something like    Bryan   how does it feel to be 17 years old           Hints for
53. To  50 Step    10   f  For counter   1 To 10 with counter   2   g  For counter   1 To 11 with 2 counter  Section 5 3  Q1   Column 1 Column 2 Column 3  Finding minimum   1 56  922 0 001  Finding 99 3 999 0 200  maximum  Count  15 6  3  99  1  0 001  2  occurrences  Linear search  2 38  8  929  6  0 111  6                Q2      a  Count occurrences   b  Finding maximum  or minimum if searching dates of birth      c  Linear search          150 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009             
54. UTING  63             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          Testing the INT function       Input Expected output   Actual output   Comment       2 5       9 999       9 001        5 5           9 001                   Testing the CINT function  Edit the coding of the program  to change     result   Int number  into result   Cint number        Run the program again and complete a similar table of testing to the one above   Can you summarise the difference between INT and CINT   Testing the ROUND function    Edit the coding of the program  to change        Run the program again and complete a similar table of testing to the one above     Experiment with different numbers instead of 2  Summarise how this function  works     Testing the SQRT function    Edit the coding of the program  to change        result   Cint number  into result   System Math Sqrt  number   Run the program again and complete a similar table of testing to the one above     What happens when you enter a negative number  Can you explain this     result   CInt number  into result   System Math Round  number 2     What happens when you enter a number like 0 000000001  What does this mean              64 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       Other predefined functions    Visual BASIC provides many other predefined functions  including the
55. VEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          Example 4 9 3 Multiplication tables  Stage 1     Analysis    Program specification Data flow diagram   copy and complete         Design  write and test a program to  display any multiplication table   chosen by the user  in the form  1 x 5    5 2x5 10andso on as far as 12  x 5   60    Stage 2     Design    Sketch a user interface  something like Multiplication tables    Which table do you want        this     It should have a button  labels  a text box  for inputting the user   s choice of table and  a list box to display the output                                   Each line that   appears in the 1 X 5 5 10   list box should the   look like this t   the piliplier 4h Hi ee   made up of symbol X   chosen by   symbol   a  five parts    1 2 3     ee multiplier        To do this  we need several variables     e the counter  an integer    e the multiplier  an integer supplied by the user    e the answer  an integer calculated by the program     e astring variable  which we ll call    message     which links together the five  parts shown above  and stores them as a single message to be displayed  in each line of the list box     The line of code to assemble this message will look like     message   counter  amp      x      amp  multiplier  amp            amp  answer             SOFTWARE DEVELOPMENT  INT 2  COMPUTING  107          Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS 
56. VEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          Stage 2     Design     pseudocode    There are several steps for the OK button  When it is clicked     ORO  OE ee    store the possible score for the exam   store the student   s first name   store the student   s surname   store the student   s mark   calculate the percentage mark   calculate the grade   extract the initial letter from the first name   extract the initial letter from the surname   display an appropriate message box  showing initials  percentage and  grade     The program will use several variables  It is useful to write them down as a table                                Variable name Variable type Used to store   Max_mark Integer What the exam is out of  e g 80   First_name String Student s first name  e g  Albert   Surname String Student   s surname  e g  Einstein   Mark Integer Student   s actual mark  e g  63   Percent Single Student   s percentage  e g  53 7   Grade String Student   s grade  e g  D    Init1 String Student s first initial  e g  A    Init2 String Student   s second initial  e g  E                 Converting these into variable declarations  and the pseudocode into VB code   we should get the following code for the OK button     First  the initial comment lines and variable declarations     Private Sub btnOK_Click                code for the OK button     by A  Programmer 19 10 07       variable declarations   Dim max_mark As Integer   Dim first_name  surname As String  Dim mark As Int
57. You should keep a folio of  evidence  this should include documentation of all the stages of the software  development process     You will see the following icons throughout these notes     Computer based practical task     you will need access to a  computer with Visual BASIC 2005 EE  or similar  installed for this  task    Questions for you to answer     you can check your own  answers against the sample answers given at the end of this pack       LE Activity  not computer based      this will usually require some    SN A written work    You should ask your teacher or lecturer to check your work whenever you  complete a computer based practical task or a non computer based activity              SOFTWARE DEVELOPMENT  INT 2  COMPUTING  7          Learning and Teaching Scotland 2009          SOFTWARE DEVELOPMENT PROCESS          Section 1  Software development process    1 1 Software    This unit is about software  What is software  You  should already know that any computer system is  made up of hardware and software     The term hardware is fairly easy to understand  because you can see it  It is all the pieces of  equipment that make up the system     the  processor  monitor  keyboard  mouse  printer  scanner and so on        Software is not so obvious  It is all the programs  instructions and data that  allow the hardware to do something useful and interesting     Think about all the different items of software that you have used in the last  week or so     Here is the li
58. a mistake in it   Name two low level languages    Name two high level languages    Explain the main differences between high  and low level languages  Write down two advantages of high level languages     O3 COn ee    It looks like high level languages have all the advantages compared to  machine code  However  there is one major problem     processors don   t  understand high level languages at all  To get round this problem  computer  scientists have developed translator programs which can translate high level  languages  written by humans  into machine code  understood by  processors            High level  language    Machine    Translator code    program    2 3 Translators    There are two main types of translator program that you need to know  something about  These are called interpreters and compilers     To understand the difference  it is useful to think about an analogy from the     non computer    world     Imagine that you were the world expert in some obscure  subject  like    the anatomy of the microscopic tube worms  of the steppes of Knazakstan     You have been invited to  present a lecture on this subject at a conference to be  held in Japan  Most of the delegates at the conference do  not speak or understand English  and you do not know  any Japanese  How are you going to communicate        There are two options that you can take           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  25             Learning and Teaching Scotland 2009          LANGUAGES AND ENVIR
59. a new Visual BASIC project    Create a form as above    Name the button btnDataEntry    Enter the code for the button  declaring all required variables    Save the project and form in a new folder     Stage 4     Testing       Test the program with some normal test data            You might well be thinking  that this is a very tedious  example and that there  should be an easier way of  implementing the program              You are right  You should be  thinking    Loop       This is an ideal situation to  employ a For    Next loop  as  the same action has to be  repeated three times            ee    lt 2             138 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009             HIGH LEVEL LANGUAGE PROGRAMMING      STANDARD ALGORITHMS          Here is simpler version using two For  Next loops     Private Sub btnDataEntry_Click               Dim student_name As String   Dim mark As Integer  Dim i as Integer       Fori 1to3  Student_name   InputBox    Enter a name      mark   InputBox    and their mark       Next    Note  we can   t call the  variable    name    as     name    is a VB object  property  so we use     student_name    instead          Fori 1to3   IstOutput ltems Add  student_name   IstOutput ltems Add  mark    Next   End Sub    Implement and test this new version        There is a problem  The program has only stored the last name and mark we  entered  Each name  and mark  has been stored in the same variable  each  time over
60. age 1     Analysis  Program specification    Design  write and test a program to  display 1  2  3  4  5       99  100     Stage 2     Design    We want the user interface to look like this     It has a command button  a label and a list box     called IstNumbers      Here is the list of steps  pseudocode     and then the coding for the button     Pseudocode    1  Clear the list box  2  Do the following 100 times  3  Display the counter in the list box    example of    fixed loops     This  times the action is executed is    programmer  using the value            Later  we will see  that it is possible to  construct loops  where the number of  times the action is  executed is NOT  known in advance     WDA  0 1 Oy TE    Data flow diagram    1  2  3      99  100  on the screen        Counting program    click  to  start    by A   Programmer       Visual BASIC coding    LstNumbers Items Clear   For counter   1 to 100  LstNumbers Items Add  counter   Next              Instead of    message    being displayed in the  list box  the current value of counter is  displayed instead          102 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          Stage 3     Implementation    e Start a new Visual BASIC project  called Counter    e Create a form as above    e Name the command button btnStart    e Name the listbox IstNumbers    e Enter the code for the button  declare a variable Count
61. ar  we are going to  make it pop up in a separate message box     Stage 2     Design     pseudocode    Pseudocode is just a fancy name for a list of steps that the program should  carry out every time you run it  You write it in a sort of cross between English  and computer language  It lets you think about the steps carefully without  getting bogged down in the actual coding  Another advantage of pseudocode  is that it can then be easily converted into almost any high level language you  want     in our case  Visual BASIC     Here is a list of steps for our program  pseudocode      e Store the name   e Display the message     That   s it  That is all our program is supposed to do           40 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          Stage 3     Implementation     creating a form    Now we are ready to start coding  Start  up Visual BASIC on your computer        Choose File  New Project  and select Windows  Application  Name it first_project     Your screen should now display the VB environment        New Project       Templates   Visual Studio installed templates    AS  amp 2       Windows Class Library Console My Movie Screen Saver  Application Application Collecti    Starter Kit  My Templates  Search Online    Templates       A project for creating an application with a Windows user interface    Name  first_project                                           
62. ark  was entered as 599 by mistake  The computer doesn   t have any    common  sense     so it processes the data it is given  and awards the student an    A      Garbage in  garbage out     You could prevent this sort of error by making it impossible to enter a mark of  over 100  We would describe a mark of over 100 as being invalid  Invalid data  is data which couldn t possibly be correct or which doesn   t make sense in the  context     To prevent the input of invalid data  we can put the coding for input of data  inside a conditional loop  which only proceeds if the data entered is valid  A             SOFTWARE DEVELOPMENT  INT 2  COMPUTING  129          Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING      STANDARD ALGORITHMS          conditional  If  statement can also be inserted to warn the user if invalid data is  entered  In VB  it could look like this     Do   mark   InputBox    Enter a mark  up to 100       If mark  gt  100 then MsgBox     Too high      Loop Until mark  lt  100          e Create a form like the one shown here  le     ay o   e Name the textbox txtValidMark               amx  e Enter the code above for the button click          click to  event  enter a  i     mark  e Add a variable declaration for the variable     mark        e Add the line txtValidMark Text   mark to Student mark  display the valid mark in the text box on  the form                    Run the program to test that it prevents the user from entering an inva
63. arn  T    f3 how to deal with these in Section 4 3     Congratulations  You have completed Section 3     Here is a summary of what you should be able to do using VB     D VA 4   lt     design and create a form   e add text boxes  buttons  labels and captions   e add code for a button   e change the properties of an object   e analyse a problem using a data flow diagram   e write pseudocode and convert it into VB code   e declare string  integer and single real  variables   e use text boxes for both input and output   e use message boxes for output   e use input boxes for input   e write VB code for simple calculations   e testa program using normal  extreme and exceptional data   e use Int  Cint  Round  Sqrt and Sin predefined functions   e use Ucase  Lcase  Len  Mid   Asc and Chr predefined functions  e write brief user guides and technical guides for simple programs  e evaluate a program in terms of fitness for purpose  user interface and  readability     Check all the items on this list  If you are not sure  look back through this  section to remind yourself  When you are sure you understand all of these  items  you are ready to move on to Section 4           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  81          Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          Section 4  High level language programming      basic constructs    4 1 Making choices    So far  all the programs you have written follow the  same list 
64. assign them a prize  chosen at random  The program should then display the name of the winner  and the chosen prize     Work through all the stages of the software development  process for this program     analysis  design  implementation   testing  documentation and evaluation              144 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     STANDARD ALGORITHMS          Congratulations  You have completed Section 5     Here is a Summary of what you should now be able to do using  VB     Sy   lt     e everything from the Section 3 checklist   e everything from the Section 4 checklist   e write the pseudocode for the input validation standard algorithm  e write VB coding for a standard input validation algorithm   e use complex conditions  using Or and And  for input validation  e declare arrays   e use For  Next loops to handle arrays             You have now completed the whole unit on  software development  By working your way  through all the example programs and tasks in  this package  you should have demonstrated all  the practical skills required to pass the unit  and  have enough evidence to support this              You should also now  be ready to sit the   multiple choice NAB  for this unit     Good luck                SOFTWARE DEVELOPMENT  INT 2  COMPUTING  145             Learning and Teaching Scotland 2009          ANSWERS TO QUESTIONS       Answers to questions  Section 1 1  Q1  
65. core  rounded to the nearest whole number      9  Ol Go  Nes    Stage 3     Implementation     creating a form    e Create a new form matching your design   e Name the text boxes txtDetails and txtAverage   e Name the button btnStart           a3 Basketball Team manager ee x        Player  details     Average  score     by A  programmer 1810 07                SOFTWARE DEVELOPMENT  INT 2  COMPUTING  67          Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       Stage 3     Implementation     coding the start button    First  think about the variables that will be needed to store the six items of  data     e players_name will be a string variable  e g  Belinda McSporran   e squad_number will be an integer as it will be a whole number  e g  73   e game_1 game_2 and game_3 will be integers  e g  3  2 and 0   e average will be a single as it might not be a whole number  e g  1 667      e Now double click on the button to open a code window  Declare all of  these variable using Dim statements     Private Sub btnStart_Click                 code for the start command button     by A  Programmer on 18 10 07    Dim players_name As String   Dim squad_number As Integer   Dim game_1  game_2  game_3 As Integer  Dim average As Single    For the next section of code  translate each line of pseudocode into Visual  BASIC  The only new syntax is that for an input box     players_name   InputBox    Enter the player   s name      squad_numbe
66. d Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          3 5 Declaring variables    The programs in Sections 3 2 and 3 3 were designed to process words  like  your name or address  The program in Task 2 also handled a phone number   but it treated this as a string of characters  Dim phone as String      If a program has to process numbers  then we have to    tell    the computer to  expect a number rather than a    string        The reason for this  as you probably know from the Computer Systems unit  is  that computers store different types of data in different ways  It is good  programming practice to consider all the data that will need to be stored while  the program is running  We do this at the design stage  A data flow diagram is  a useful tool for doing this  although it only tells us the data that goes in and  out of the program  There may also be other data which needs to be stored  during the processing between input and output     We will consider three types of data in this  course     computing    29 5  Par  cw Activity 5 7 A Einstein    P TD7 5700  Look at these items of data  Can you group them    E  into three basic types    Monaco 0 006       You might have grouped them into these three lists     List 1  120 699  100 5700 9999  List2  computing book A Einstein TD7 Monaco  List3  29 5 5 7 0 006    List 1 are all whole numbers  We call them integers and so does VB   List 2 are all groups of characters  We call them strings a
67. d other code in black           44 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009    FUE           HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          Stage 4     Testing       The next stage is to make sure the program works Pree eae   E      e As before  click on the start icon on the menu bar   e Enter your name in the text box    e Click on the button        first_project Ed       A message box should pop up with the appropriate  message in it  If not  click on the end icon  go back to  the coding and check it carefully  Correct any errors   Run it again     Welcome to VB Albert Einstein             If it does work  well done     Would you buy a piece of software that had only been tested  once  Probably not  One test is not enough  We need to test  the program systematically     So run some more tests     some    normal    tests  like the one above     but also  try some more    extreme    testing  For example  what happens if you enter a  number instead of a name or if you click the button before entering a name     Stage 5     Documentation    Firstly  you might want some hard copy evidence of your program     it   s your  first VB program  so you may feel justifiably proud of it     Printing your program   Select Print from the File menu to obtain a hard copy of your coding   If you want a hardcopy of your form    e Run your program    e Hold down the  lt alt gt     lt prtsc gt  keys    e Paste into an application    e  
68. data and  the output will appear in a listbox     names and marks  displayed on form    Names and marks    Click to  enter  data       Next  we design the list of steps  pseudocode  and then the coding for the    button        Pseudocode    Visual BASIC coding       1  Enter and store the first student   s name    first_name   InputBox    Enter 1  name           2  Enter and store the first student   s mark    first_mark   InputBox     and their mark           3  Enter and store the second student   s name    second_name  InputBox     Enter next name           4  Enter and store the second student   s mark    second_mark   InputBox     and their mark           5  Enter and store the third student s name       6  Enter and store the third student   s mark    and soon           11 Display the first student   s name    IstOutput Items Add  first_name        12 Display the first student   s mark    IstOutput Items Add  first_mark        13 Display the second student   s name       14  Display the second student   s mark                         and so on      15  Display the third student   s name  16  Display the third student   s mark  SOFTWARE DEVELOPMENT  INT 2  COMPUTING  137             Learning and Teaching Scotland 2009             HIGH LEVEL LANGUAGE PROGRAMMING      STANDARD ALGORITHMS          The variables required are     e first name  second_name  third_name  all stings   e first mark  second_mark  third_mark  all integers      Stage 3     Implementation       Start 
69. de  for the software    Working out the details of what the  screens will look like  what menus and  functions there will be and other detailed  aspects of the program    Deciding what type of game you want to  create and what features you want it to  have     Actually writing all the program code     Adapting the game to run on a different  type of computer     Checking that the program does what it is  supposed to do  is easy to use and can be  fixed if there is a problem     Getting users to try out the program to  make sure it works under most conditions     2    What three criteria will be used for evaluating software in this unit     3    What is the relationship between pseudocode and a structure diagram     4    Name two items of documentation usually provided with a software  package  and describe what you would expect each one to contain     5    What three types of testing should be applied to  any software     6    Describe two examples of maintenance that could be required on a    game program           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  21          Learning and Teaching Scotland 2009                LANGUAGES AND ENVIRONMENT       Section 2  Languages and environments  2 1 Computer languages    Just as there are many human languages  there are many computer  programming languages that can be used to develop software  Some are  named after people  like Ada and Pascal  Some are abbreviations  like PL 1  and Prolog  All have different strengths and weaknesses  
70. e column headings     e Make them bold     The spreadsheet should now look like this     Sy course2_xls              Orienteering Course 1   Control identifier terrain distance  m     H gate in wall 150  2 A corner of track 200  a B in woods 120  4 J stream crossing 165  5 Us top of slope 210  6 P bend in path 240  7 C hollow 120  8 F top of hill 175  g W junction of fences 200  10 K end of house 185       e Click on    stop recording           Save the improved spreadsheet as course2 xls  All the series of actions that  you applied to course xls to turn it into course2 xls have been recorded and  stored as a macro           30 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                LANGUAGES AND ENVIRONMENT       To see the macro you have created     e Goto the Tools menu   e Select Macro   e Select Macros     A dialog box like the one shown below should appear  with your named macro  listed under the name you gave it     Cancel    Step Into    Create       EERE    Delete    Macros in  Jal Open Workbooks    Options       Description  Macro recorded 07 01 2004          e Click on Edit          SOFTWARE DEVELOPMENT  INT 2  COMPUTING  31          Learning and Teaching Scotland 2009                LANGUAGES AND ENVIRONMENT          Another window will open  which displays the code of the macro you have  recorded  like this          course2_xls   Modulel  Code   oO  x      General  hd  tidy_up_ss X      Sub tidy_up_S5S           tidy up
71. e program first           94 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING      BASIC CONSTRUCTS       Extra task  1   Upper case initials    If you entered a student   s name as  e g      albert einstein     the  initials would be displayed as    ae     It would be better if they were  changed automatically to    AE     A simple change in the coding of  the OK button is required        Hint  You will need to use the Ucase predefined function   Extra task  2   A  grade    A new grade called A  has been introduced for marks of 80   and over    Change the coding to reflect this new grade  Remember to  change the condition for an A as well as introducing a new  condition for A         Pav   A Stages 5 and 6     Documentation and evaluation    As usual  you should     e print out hard copies of your form and the coding   e write a short user guide and technical guide   e write a brief evaluation of the program in terms of its fitness for purpose   user interface and readability     4 5 Using And     task  Example  Can I drive   The problem  A program is required that asks the user to    enter their age  then displays one of the following  messages  as appropriate        e Sorry  you can t drive  if you are under 16     e You can only drive a moped  if you are 16     e You can only drive a car or moped  if you are 17   20    e You can drive any vehicle  if you are 21   74     e You need a medical
72. e program has actually printed the message 25  times  so alter the line of code to include the counter  like this     IstGreeting ltems Add counter  amp      Hello           then try running it again   Modifications  1   Alter the coding so that it displays the messages   e    Goodbye    12 times  e      must work harder    200 times  e    This is very easy    100 times   Modifications  2   The program would be much more useful if it was possible to make changes to    the message and the number of times it was displayed  without having to alter  the coding each time  This can be achieved by using variables                Change the coding as follows  A string variable called message  will store the message  and an  integer variable called how_many  will store the number of    repetitions     Private Sub btnStart_Click          improved For    Next example    Dim counter As Integer  Dim message As String  Dim how_many As Integer    An InputBox is like a Message  Box  but is used to get input from  the user  and store it in a variable  message   InputBox    Message required           how_many   InputBox    How many repetitions         This command clears the list box    IstGreeting ltems Clear           Instead of a fixed number here   the loop will continue up to the  number stored in how_many    For counter   1 To how_many  IstGreeting Items Add  counter  amp           amp  message  Next   End Sub        Whatever string is stored in the variable called  message will be displa
73. e the actual value of the  data they store can vary or change during the running of a program     It is important to make sure that all variables are correctly declared     the right  type  integer  string or single      and with sensible  readable variable names     Variables can have almost any name  but each variable name    e must begin with a letter   e must not be a VB keyword  like End or Print or MsgBox    e must not contain spaces  no_of_pupils is OK  but no of pupils is not      Note  There are several other types of variable  but we will only use these  three in this unit    3 6 Working with numbers     example   The programs in Section 3 3 were designed to process words  like your name    or address  In this section  we will develop programs to process numbers      both integers and real numbers  singles      The first example is called Belinda   s  Slab Calculator  Belinda works in a garden centre  selling  paving stones  Customers come in with the  plans for their patio  and ask how many slabs  they will need and how much it will cost  For  example  Mr Mclinally says his back garden is    Here is the problem        35 slabs wide and 16 slabs deep  He wants  the pink granite slabs at   2 99 each  How  many slabs will he need  and what will they  cost        The first step is to be absolutely clear about what  the program must do  This must be agreed  between the customer  Belinda  and the  programmer before starting  The agreed definition  of what the program mus
74. e to create stand alone applications     However  small programs called macros can be developed within some  existing application packages     Example  Creating an Excel spreadsheet macro       e Set up a small spreadsheet like the one shown below  Save it as  course xls   e Save asecond copy of the same spreadsheet as course_copy xls        E  course  xls             1  Orienteering Course 1  2  3 Control identifier terrain distance  m   4 1H gate in wall 150  5 2A corner of track 200  6 3B in woods 120  7 4J stream crossing 185  8 5 T top of slope 210  9 6P bend in path 240  10  C hollow 120  11 8 F top of hill 175  gW junction of fences 200  13 10K end of house 185  14    e From the Tools menu  select Macro  then Record New Macro    The following dialog box should appear             Record Macro 2  xi     Macro name    tidy_up_ss  Shortcut key  Store macro in   Ctrl shirt  k  This Workbook 7   Description       recorded 07 01 2004    OK   Cancel            SOFTWARE DEVELOPMENT  INT 2  COMPUTING  29          Learning and Teaching Scotland 2009                LANGUAGES AND ENVIRONMENT       e Enter the name  tidy_up_SS    e Enter the shortcut key  Ctrl   Shift   K    e Then click OK     Warning  Follow these instructions very carefully     all your actions are being  recorded     e Select cell a1  the title of the spreadsheet     e Change its font to 18pt Bold    e Select A3 to D13  all the data     e Centre it all using the centre button on the menu bar   e Select row 3  th
75. eger   Dim percent As Single   Dim grade As String   Dim init1  init2 As String          92       SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          Next  storing the user inputs from the text boxes into variables  pseudocode  steps 1 to 4          Store user inputs Note use of a comment line to  max_mark   txtMax Text indicate the purpose of the code   first_name   txtName Text    surname   txtSurname Text  mark   txtMark Text    Next  the calculation of the percentage mark  pseudocode step 5          calculate percentage mark  percent    mark   max_mark    100    Step 6 is the calculation of the grade from the percentage  using a series of If  statements  The statements for grades A and Fail are straightforward  For  grades B  C and D  complex conditions are required using And         calculate grade   If percent  gt   70 Then grade      A      If percent  gt   60 And percent  lt  70 Then grade      B     If percent  gt   50 And percent  lt  60 Then grade      C     If percent  gt   45 And percent  lt  50 Then grade      D     If percent  lt  45 Then grade      Fail       Steps 7 and 8 use Mid  to extract the first character of the first name and  surname         extract initials from name  init    Mid  first_name  1  1   init2   Mid  surname  1  1     Finally  step 9 uses a message box to display the results  This is a little bit complicated     e init  init2  percent a
76. ell as the program displaying the prize that has been won  we want the  colour of the form to change  We will use the following colours   red  1   blue     2   green  3   yellow  4   black  5      All we need to do is change the  coding  so that each If statement has  two actions to be performed      displaying the appropriate message  and changing the form colour     This is how the code should  look now     Modify the Lucky  Number program and  check to see that it  correctly changes the  form colour        Note  Me BackColor refers to the  background colour property of the  current Form     One further change that is useful is to  make the Clear button turn the form  back to its standard grey colour  as  well as clearing the text box  The  coding for this is     Private Sub btnClear_Click       txtNumber  Text           Me BackColor   Color Gainsboro  End Sub    Note  Gainsboro is the name for the  default light grey colour     Usually  a conditional  statement is of the format     If condition Then action       Private Sub btnOK_Click      coding for the OK command button      displays an appropriate message for each number     and changes the form colour      written by A  Programmer on 19 10 07    Dim Number As Integer  Number   txtNumber  Text    If Number   1 Then  Me BackColor   Color Red  MsgBox Number  amp      wins you a colour TV      End If    If Number   2 Then   Me BackColor   Color Blue   MsgBox Number  amp      wins you a mobile phone      End If    If Numbe
77. eps of stepsize  7  Display the counter heen eee Items Add                      e Start anew Visual BASIC project  called GPCounter    e Create a form as above    e Give the button  list box and text boxes appropriate names   e Enter the code for the button    e Save all           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  105          Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          Stage 4   Testing    Carry out systematic testing of the program  completing a table like the one  shown below                                   Inputs Expected Actual outputs   Comment  outputs  Lower   Upper   Step  limit limit size  10 20 3 10  13  16  19  Normal 1000  1250   daa 1000 8000 2500 1500  1750  10 0  2 10  8  6  4  2  0             Devise your own test data  covering a range of normal  extreme and  exceptional data     Write a short summary of your testing     If all the tests results were as expected  move on to stages 5 and 6  If not  go    back and correct your coding until it works correctly     ay     DEX  ry Stages 5 and 6     Documentation and evaluation    As usual  you should    e print out hard copies of your form and the coding    e write a short user guide and technical guide  e write a brief evaluation of the program in terms of its fitness for purpose     user interface and readability           106 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                   HIGH LE
78. er as  integer      Stage 4     Testing       Run the program to make sure it works correctly  it should produce a list of  numbers from 1 to 100 in the list box   There is no need for a table of testing  for a simple program like this     You are going to use this program as a template to experiment with For    Next  loops  In each case below     e Replace the line of code For counter   1 To 100 with the modification  suggested    e Run the program    e Note the results in a table like this        Coding used Results  For counter   1 To 100 1234        99 100                               Modifications    For counter   1 To 9999   For counter   1 To 100 Step 2  For counter   2 To 100 Step 2  For counter   0 To 100 Step 10  For counter    10 To 10 Step 5  For counter   100 To 1 Step    5  For counter   0 To 5 Step 0 5        The final modification will  require a change to another  line of coding  Can you   work out what it will be     Hint  0 5 is not an integer          Soe Pe NS          SOFTWARE DEVELOPMENT  INT 2  COMPUTING  103             Learning and Teaching Scotland 2009              HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS       Questions    Write the Visual BASIC coding of a For    Next loop to produce each of the  following lists of numbers     1  3 6 9  12  15  18       33  36   2  0 9  18  27       99   3  10 9  8  7  6 5  4 3  2  1 0   4  0  0 75  1 5  2 25  3  3 75  4 5   5  50  40  30  20  10  0   10     20   30     40     50   6  1  4  9  16  25
79. es           32 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          LANGUAGES AND ENVIRONMENT       Example 2  Creating a word processing macro       e Open any word processing document    e As before  from the Tools menu  select Macro  then Record New Macro   e Name the macro bold_red_text    e Assign a shortcut key combination  perhaps Ctrl   Alt   R     e Click OK     Now the macro is being recorded     e Select bold and text colour red from the menu bar   e Click to stop the macro recording     Now you can use the macro     e Select any block of text   e Activate the macro by using the shortcut key combination     You can also activate the macro by selecting it from Tools  Macro  Macros     This macro would be useful if you have several documents to work through  in  each of which you have been asked to change the main heading to bold red  text     If you needed to change all the sub headings to italic blue text  you could set  up a similar macro to do that  Alternatively  you could edit the macro directly  by changing the VBA code in the edit window  Try editing the above macro to  make it produce blue italic text     The examples above are very simple ones  Macros can be used to automate  any task within an application program  For example  they can be used to  activate long and complex data manipulations within a database application or  specialised formatting within any type of document     Some applications  such as AppleW
80. et     Here is a reminder of these important steps     making sure you know what the  program has to do        deciding on the form layout  the inputs   outputs and processes required    creating the form and writing  the code for any actions    Implementation       making sure the program  works correctly        writing a user guide and  a technical guide        reviewing how well the  program solves the original  problem        making any upgrades  required                SOFTWARE DEVELOPMENT  INT 2  COMPUTING  37          Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       Questions    1  Name three types of object that could be found on a VB form   2  What does this icon do   gt     3  Give an example of a VB event     3 2 Input and output     example    Almost every program that has ever been written follows a pattern called IPO   This stands for inout process   output  Most programs are designed to take in  some data  to process it in some way  then to give out some data     Example 1   To keep things simple for your first VB program  we are going to develop one  which misses out the middle step  It will simply take in some information and  give it out again  It   s not very useful  but it will teach you some of the basics of    VB programming     We start with the program specification           Design  implement and test a program which will prompt the user to enter his  or her name  The program should then display the 
81. f  the user enters their PIN wrongly three times  they should be  warned that their card is being kept  message 3         Stage 1     Analysis     data flow diagram    PIN entered at  keyboard    Appropriate  message         Stage 2     Design   We want the user interface to look like this  VB Bank   It has a command button  a title and a text Click to rT  box for messages to appear  The user will be enter PIN    prompted to enter their PIN through an input  box        First  we design the list of steps  pseudocode  and then the coding for the  command button     We will use a Do    Loop Until  as the number of attempts the user makes is  unknown in advance by the programmer     The condition to end the loop will be that the PIN is correct OR that the user  has had three attempts              124 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS                                        Pseudocode Visual BASIC coding   1  Set a counter equal to zero counter   0   2  Store correct PIN correct_pin   1347   3  Do the following  Do   3 1 prompt the user to enter their pin   InputBox    Enter your PIN      PIN   3 2 if PIN is correct display If pin   correct_pin then txtMessage Text  message 1  Else display      Welcome to VB Bank    else  message 2  txtMessage Text      PIN entered wrongly       try again      3 3 add 1 to the counter counter   counter   1   4  Until the PIN is correct o
82. g to type these notes   e Windows XP  on another laptop    e Windows 2000  on a computer at school    e MacOS 8 1  on my trusty old Mac clone    e MacOS X 2  on my iMac      Thirdly  a full list would include all the actual documents  files  web pages   emails and so on that   had accessed  as these are also software  That would  be too long a list  so I ll ignore it here     Yl How about you  Make a list of all the software  programs and  VY VJ  operating systems  that you have used over the last few days     The point about all these programs is this  they didn   t grow on trees  They are  available for us to use because they have been designed and created by  teams of software developers  In this unit  we are going to learn about the    process of developing software  and to apply this process to develop some   simple  programs of our own     1  What is the meaning of the term hardware     2  Give three examples of software           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  9          Learning and Teaching Scotland 2009                   SOFTWARE DEVELOPMENT PROCESS       3  Identify each of the following as either hardware or software        Item Hardware Software       Monitor v       Database  Windows 97    Scanner             An email       Internet Explorer       Mouse       Modem       Computer game       Word processor       Digital camera                1 2 The development process    Before we think about how software is developed  it is worth  considering how any p
83. he design  while others will  develop the electronics to go inside  Each part will be tested on its own  then  the whole thing will be assembled into a  hopefully  working TV set     Stage 4  Testing    Before the new model can be put on sale  it will be thoroughly tested  A wide  range of tests will be carried out     It might be tested under    normal    conditions  It could be put in a room at  normal room temperature  and checked to see that all the controls work  correctly  the display is clear  it is nice and stable  and so on     If it passes this type of testing  it might next be tested under    extreme     conditions  For example  does it still work if the temperature is below freezing   or very hot and humid  if it used for long periods of time  or with the volume or  the brightness or contrast set to their maximum values     Finally  it could be tested under    exceptional    circumstances  What happens if  a 2 year old picks up the remote and presses all the buttons at once  What  happens if there is a power cut or a power surge    If it fails any of these tests  it might be necessary to go back to the  implementation  or even design  stage and do some further work    before re testing    If it passes all the testing  then it can go into production     Stage 5  Documentation    However  the development isn   t yet complete  Some  documentation will be needed to go with the TV  A user manual          SOFTWARE DEVELOPMENT  INT 2  COMPUTING  11          Learning and 
84. he program should respond to both upper case and lower case inputs           96       SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING      BASIC CONSTRUCTS          4 7 Repetition                 So far  every program you    have written starts at the beginning  executes each line once  then stops at the  end  If you want to repeat the program you have to click on the start icon to  run it again  It is often useful in a program to be able to repeat a line or group  of lines automatically     To do this  you can use a FOR     NEXT loop  Here       is a simple example program that would benefit E simple loop demo       from a FOR     NEXT loop     e Create a form like this  with a single button   called btnLoop     e Add a listbox  you will find this in the tool bx    just below label   and name it IstMessage     e Enter this coding                 Private Sub btnLoop_Click               code to display 10 greetings on the screen     by a not very good programmer     who hasn   t been taught about FOR  NEXT loops        Note  This is  the letter I  not  the number 1  IstMessage ltems Add    Have a nice day            IstMessage ltems Add    Have a nice day       IstMessage ltems Add    Have a nice day          IstMessage ltems Add    Have a nice dav      IstMessage ltems Add    Have a nice day          IstMessage ltems Add    Have a nice day          IstMessage ltems Add    Have a nice day          Is
85. he user interface will use a text box for data  entry  with two buttons  and use a message Enter a number fy    box for the response  between 1 and 5       Stage 2     Design     pseudocode Click to confirm       by A  Programmer 19 10 07       Here are the steps for the OK command  button  When it is clicked     store the number entered by the user   if the number is 1  display    You have won a colour TV      if the number is 2  display    You have won a mobile phone     and so on     BO MS    There is only one variable required     a numeric variable to store the number entered  by the user  As this must be 1  2  3  4 or 5  it should be declared as an Integer           86 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING      BASIC CONSTRUCTS       Stage 3     Implementation    e Start a new project called Winner   e Create a form as shown above   e Name the text box txtNumber   e Name the buttons btnOK and btnClear       Enter the coding for the OK command button  as below     Private Sub btnOK_Click              coding for the OK command button      displays an appropriate message for each possible number     written by A  Programmer on 19 10 07    Dim Num as Integer   Num   txtNumber Text   If Num   1 Then MsgBox  Num  amp      wins you a colour TV       If Num   2 Then MsgBox  Num  amp      wins you a mobile phone      If Num   3 Then MsgBox  Num  amp      wins you a week in Spain      If Nu
86. here are two buttons    e Some text appears in labels on the form           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  35          Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          Each of these items is called an object  Each object has properties  and  some objects  including buttons  can have program code associated with  them  so that something happens when a user  for example  clicks the button   Clicking a button is an example of an event  VB allows a programmer to    create event driven programs     To develop a program in Visual BASIC  you need to open the VB  programming environment  To begin with  it looks a little complicated  but you    will soon learn how to use it     Here is the same program while it was being developed  showing some of the    main features of the VB environment           VB toolbox    VB tool bar                  Solution  explorer window              indow    Gz    Community Help             DE           gt        GS     Ol rep oo  oe                      v  CheckBox  2 9 CheckedListBox         l MonthCalendar    Start Page   Formi vb     Form1 vb  Design        a3 Club Membership    anx             Enter your name and age in the boxs below  then  click the button to register yourself as a member                          x    E Name       F   Se Properties  DateTimePicker Ag AT 4 3   A Label window   A LinkLabel      ListBox   ee ListView Register Quit    _  MaskedTextBox Solution Explo
87. hmetical question  e g  What is 100 x 1007    e ageneral knowledge question  e g  Who won Big Brother in 20067    Improvements to the program    This simple program works fine  but there are some obvious  changes which would improve it              Improvement 1  When you give the wrong answer  the program doesn    tell you  It  could be improved by presenting a message which told the user   to try again             SOFTWARE DEVELOPMENT  INT 2  COMPUTING  113                Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          To do this  you need to add in the following line of code     If user_answer  lt  gt  correct_answer Then MsgBox     Wrong  try  again         Can you work out where this line of code should go  Edit it into your program   and check that it works            Improvement 2    The program would be improved if it told you how many guesses  you made before you got the correct answer         To do this  we need to include a counter in the loop  Here is the pseudocode   the new sections are in bold      Declare integer variables for the user   s answer and the correct answer    Declare an integer variable for the counter    Set the counter equal to zero    Set the correct answer equal to 4    Do    e get the user   s answer to the question  What is 2   2    e add one to the counter   e if the answer is not the correct answer  display    Wrong  try again     message    6  Until user   s answer is equal to the
88. hold the two random numbers to  be used for the question   Dim user_answer As Integer  Dim correct_answer As Integer  Dim first  second as Integer  Dim counter as Integer        These lines generate the two  random numbers for the question    Randomize     first   Int Rnd     10    1  second   Int Rnd     10    1 This displays the value of the  counter   0 variables first and second  rather  correct_answer   first   second than the numbers 2   2       Do  user_answer   InputBox    What is      amp  first  amp             amp  second  amp            counter   counter   1  If user_answer  lt  gt  correct_answer Then MsgBox    Wrong  try again       Loop Until user_answer   correct_answer   MsgBox    Well done  You took      amp  counter  amp      tries       End Sub          SOFTWARE DEVELOPMENT  INT 2  COMPUTING  119             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          One more modification     The program only asks one random addition question each time it is run  By  adding three lines of code  we can make it give the user a series of  Say  six  questions     We can do this by putting the whole of the middle section of the program  inside a For    Next loop  like this     Private Sub btnQuestion_Click              generates 6 random question to the user     and waits for the correct answer            Dim user_answer As Integer  Dim correct_answer As Integer  Dim first  second as Integer  Dim counter as Integer
89. i   1   so student_name 1  and  mark 1  are used  and so on    The same thing happens here   with i taking the values 0  1  2  3  and 4 in turn  so each name and  mark are displayed in the list                      SOFTWARE DEVELOPMENT  INT 2  COMPUTING     141             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     STANDARD ALGORITHMS       Implement and test this new version  It should work correctly  now        A  S   Stages 5 and 6     Documentation and evaluation   RA seo   As usual  you should    e print out hard copies of your form and the coding   e save your program and tidy up the files into a folder   e write a short user guide and technical guide   e write a brief evaluation of the program in terms of its fitness for purpose   user interface and readability    5 5 Examples using arrays   Lucky prize Draw  version 1    Stage 1     Analysis    Program specification Data flow diagram    Design  write and test a program which   prompts the user to enter 10 names  10 names KE  then selects and displays one chosen at                     random  C  gt      Stage 2     Design    We want the user interface to look like Prize Draw  this     The lucky winner is       It has a command button  two labels  a  title and a text box  called txtWinner   fF  The user will enter the 10 names using    input boxes  by A  Programmer 05 01 04             142 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009          
90. ing Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          3 10 Predefined numeric functions    There are some standard mathematical calculations that you may want to use  in your programs  Visual BASIC  along with most other high level languages   provides predefined functions to carry these out for you  We ll take a look at  some predefined functions provided by Visual BASIC     INT takes a number and removes any fractional part  leaving the  whole number part   CINT takes a number and returns the nearest whole number   ROUND rounds a number to any number of decimal places   SQRT returns the square root of any number    Function Tester program    We will use a simple VB program to test these functions                          e Create a form like this  Cappers Jog  e Name the text boxes txtEnter and Enter a number    Apply  txtResult  function  Result   e Name the command buttons   btnClear and btnFunction    Clear by A Programmer  f 18 10 2007   e Write the code for the clear button   as you did in Section 3 7        e Copy this code for  the btnFunction  command button        Private Sub btnFunction_Click         Dim number  result As Single        e Save the project and  form         number   txtEnter  Text        result   INT number   e Run the program to    test the INT  function        txtResult  Text   result  End Sub        As you do this  copy and complete a table of testing as shown below           SOFTWARE DEVELOPMENT  INT 2  COMP
91. k  but not answers to  programming tasks  as many possible correct answers are possible  and  syntax may vary depending on the version of VB in use           6 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                INTRODUCTION          Student guide    This teaching and learning material is designed to cover all the skills   knowledge and understanding that you need to pass the Software  Development unit of Intermediate 2 Computing     To achieve this unit  you must develop and demonstrate knowledge and  understanding of     e the principles of software development  Section 1    e software development languages and environments  Section 2   e high level language constructs  Sections 3 and 4    e standard algorithms  Section 5      At the end of the unit  you will be tested on this knowledge by sitting a short  20 question multiple choice test     However  it is not only about passing a test  You must also develop practical  skills in software development using a suitable high level language  Almost  any programming language can be used  but these notes  especially Sections  3 to 5  assume that you are using Visual BASIC 2005 EE  or VB 2008 EE   If  you are using a different programming language  your teacher or lecturer will  need to supply you with other materials for some parts of the unit     Your teacher or lecturer will complete a practical skills checklist for you as you  work through the practical exercises in these notes  
92. lid mark   i e  one that is over 100      If you tested the program thoroughly  you might have discovered that it is still  possible to enter invalid data  For example  the program would accept a  negative number  which would not be a valid mark in any exam that   know     We can easily adapt the program to also prevent invalid negative numbers  being entered  as follows  changes in bold   using complex conditions     Private Sub btnDataEntry_Click                    Dim mark As Single   Do   mark   InputBox    Enter a mark  between 0 and 100       If  mark  gt  100  Or  mark  lt  0  Then MsgBox     That was not a valid  mark       Loop Until  mark  gt  0  And  mark  lt   100   txtValidMark  Text   mark   End Sub             Save this program  as valid_mark    You will use it as a  basis for the tasks  in section 5 2     Make these changes and test the program  again using the following test data        Normal  23  55  99  150   10  Extreme  0  100  0 0001  99 999  100 001  Exceptional  A   lt spacebar gt         z          130 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING      STANDARD ALGORITHMS       Validation or verification     Notice that input validation doesn   t prevent wrong data being entered  For  example  if a student had scored 55 in an exam and the operator entered the  mark as 56 by mistake  the program would accept this data  The data would  be wrong but still valid     The pr
93. m   4 Then MsgBox  Num  amp      wins you 10p       If Num   5 Then MsgBox  Num  amp      wins you a meal for two      If Num  lt  1 Then MsgBox  Num  amp      is too small       If Num  gt  5 Then MsgBox  Num  amp      is too large       End Sub    Enter the coding for the Clear button as usual     re xy   we Stage 4     Testing    Devise some test data  This should include   e some normal data  e some extreme data    e some exceptional data     Run the program using your test data and record the results in a table           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  87          Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS       Pew X  SNA G3 Stages 5 and 6     Documentation and evaluation          As usual  you should     e print out hard copies of your form and the coding   e write a short user guide and technical guide   e write a brief evaluation of the program in terms of its fitness for purpose   user interface and readability     Extra task  changing form colours    You may have discovered that the colour of forms and buttons can be  changed using the properties window when you are creating a form   Properties such as colour can also be changed during the running of the  program  as the next example shows           88 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING      BASIC CONSTRUCTS          Lucky Winner  with colours     As w
94. many slabs wide        If it has worked correctly  save it    slabs and      cost       How many slabs deep   If it doesn   t work  then go back and check for  errors  Cost of one slab      2 99           Number of slabs required  20  The most common mistakes  are to make a spelling error  in the name of a variable or  a text box  so always check  these carefully     by A  Programmer  21 09 07 Total cost        59 8                SOFTWARE DEVELOPMENT  INT 2  COMPUTING  57             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          Stage 4   Testing    Testing is a very important stage in the software development  process  Proper testing of a commercially produced program  may take as long as the implementation     We will test this program methodically using normal  extreme  and exceptional data     Normal data is data that you would expect to be input to the program     Extreme data is data that is on the limits of acceptability     it should work  but  you need to check to make sure  Extreme data could include zero  or very  large numbers  or numbers close to any limit relevant to the program     Exceptional data is data that shouldn t be input under normal use  for  example entering a letter when asked for a number  or clicking a command  button when there is no data in the input text boxes     It is best to draw up a table of testing  choosing suitable test data  as shown  below  Fill in the expected results column 
95. name  so it has to be able to store it in between      Now we need to turn the pseudocode we wrote at the design stage into Visual  BASIC     Pseudocode Visual BASIC  Store the name     name   txtName Text  Display the message                    MsgBox    welcome to VB      amp  name     These two lines need a little explaining   name   txtName Text     This line is best read from right to left     it tells the computer to take the text from  the text box called txtName and store it in the memory location called name      MsgBox    Welcome to VB      amp  name    The final line tells the computer to create a message box on the screen  and  to display the words Welcome to VB  followed by whatever is stored in the    location called name      The commas and speech marks must all be there in the correct order  If you  have entered all that correctly  it should look like this          A Formi vb   Start P  Form1 vb  Design      Notice the extra blank lines       _      ___       _ OT RESNO             btnMessage v  2 Click  they don   t do anything  but E ETET    they make the program more   readable just like gaps A Private Sub btnMessage Click ByVal sender As System Obje  between paragraphs in an    by A  Programmer on 14 09 07   essay or report     Dim name As String    name   txtName Text    Now save the program again   click Save all   MsgBox   Welcome to VB    amp  name   End Sub   End Class    Note  VB keywords are displayed in blue  comment lines in green  text in red  an
96. name and a welcome  message              38 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                   HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          Stage 1     Analysis    Start by thinking about what data goes in and what data comes out of the  program while it is running  A data flow diagram is a good way of analysing  this     Start by representing the  program as a    blob            Think  what information  comes out of the program     Name and  welcome message        Show this as an arrow coming  out of the blob        Now think     what information  needs to go into the program  to give this output     Name and        Show this as an arrow going name  in to the blob        welcome message    Copy this diagram     you have drawn your first data flow diagram           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  39             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       Stage 2     Design     user interface  Next we need to think about what we want the program to look like     We can sketch out how we want the form to look like this    My First Program in VB    Click for by A  Programmer 15 12 03  message    Our form has        e atitle caption at the top   e a label  Enter your name    e a text box to type your name into   e a button to activate the message   e another label with your name and the date     If you   re wondering where the message is going to appe
97. nd 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       Testing the UCase function  Run the String Function Tester program     Record the results in a table like the one below  adding a few  tests of your own           UCase predefined function       Input string Output string Comment       Hello  world  HELLO  WORLD       123 One Two Three        2 amp                        Write a brief statement summarising the effect of the UCase function     Testing the LCase function    Edit the coding of the Function Tester 2 program        Change     string _out   UCase string_in     into  string_out   LCase string_in           72 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                   HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       Run the program to test the LCase function  Record the results in a table like  the one below  adding a few tests of your own        LCase predefined function       Input string Output string Comment       Hello  world       HELLO  WORLD       123 One Two Three        28                       Write a brief statement summarising the effect of the LCase function     Testing the Len function    Edit the coding of the String Function Tester program        Change     string_out   LCase string_in     into    string_out   Len string_in     Run the program to test the Len function  Record the results in a table  like the  one below  adding a few tests of your own  Note  Make sure there are no
98. nd grade display the values of these variables  e         inserts a comma and space after the initials  e       grade     inserts a   sign  comma and the word    grade    after the    percentage mark              SOFTWARE DEVELOPMENT  INT 2  COMPUTING  93          Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS       All the above is the actual message  then     e the two commas separate the message from the title  e    student result    at the end is the title of the message box         display message in format    AE  70   to 2 dec  places   grade A  percent   System Math Round percent  2     MsgBox init1  amp  init2  amp            amp  percent  amp         grade      amp  grade        student result      End Sub    Stage 3     Implementation    e Start a new project called exam_grader    e Create aform as above    e Name the text boxes txtMax  txtName  txtSurname and  txtMark    e Name the buttons btnOK and btnClear    e Enter the coding for the OK button    e Enter the usual coding for the Clear button        SE  7 Stage 4     Testin   IAM  Ses 9   Devise some test data  This should include    e some normal data   e some extreme data   e some exceptional data    Run the program  using your test data  and record the results in a table     Stages 5 and 6     Documentation and evaluation    Don t print out your program or write documentation or an evaluation report  yet  as you are going to make some minor improvements to th
99. nd so does VB     List 3 are all numbers with fractions  We call these real numbers  VB calls  them single              SOFTWARE DEVELOPMENT  INT 2  COMPUTING  51          Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       Ree Activity    Classify each of the following as integer  string or single      a  150  b  Bob the Builder  c  49 99  d  EH16 1AB   e  0 5  f   500  g  583  h  123   i  Albert  j   99 99  k  0 00006  l  5 High Street    Visual BASIC needs to know what type of data it will be storing and  processing in any program  To do this  we    declare variables    at the start of  the program  using lines like     Dim no_in_class as Integer  Dim name as String  Dim price as Single    When the VB system    reads    these statements at the start of a program  it sets  up a storage space of the appropriate type in the computer   s RAM  and labels  it with the variable name given  Of course  these are    electronic    storage  locations  but it is useful to imagine them as labelled boxes in which data can  be stored  like this     An integer variable   called no_in_class   storing value 18  no_in_class       Albert  ee    FY     called name     A single variable   called price   storing value 27 99              52 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                   HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       These    storage boxes    are called variables becaus
100. ntation    which helps me remember ADITDEM     Documentation  Evaluation  Maintenance    Next  we will take a closer look at each of the stages     Analysis  Design  Implementation  Testing  Documentation  Evaluation  Maintenance        You might be able to make up a better  mnemonic than this one     so long as it  helps you  then it   s OK     1 4 Analysis    The main purpose of the analysis stage is to be absolutely clear about what  the program is supposed to do  Often  a new program will start from a rough  idea  Before getting started  it is important to turn the rough idea into an exact  description of how the program will behave  What will it do  What are the  inputs and the outputs  What type of computer is it to run on  All these  questions  and many more  must be asked and answered at this stage           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  15             Learning and Teaching Scotland 2009          SOFTWARE DEVELOPMENT PROCESS          The result of this is the production of a program specification  agreed by  both the customer  whoever wants the program written  and the developer   the person or company who is developing the program      1 5 Design    Inexperienced programmers are often tempted to jump straight from the  program specification to coding  but this is not a good idea  It is worth  spending time at the design stage working out some of the important details   including how the program will look on the screen  how the user will interact  with the p
101. ocess of preventing incorrect data being entered is called verification   Many commercial data processing systems involve both verification and  validation  In this unit  we are only considering validation     Standard algorithm for input validation    The coding for input validation always follows a standard pattern  The details  will vary depending on the specification of the program  but the same pattern  can always be used  This standard pattern saves programmers time when  designing programs  A pattern like this is called a standard algorithm     Here is a simple version of a standard algorithm for input validation  It involves  a conditional loop and an If statement  like this     Do   Prompt user for valid input  If input is invalid  warn user  Loop until input is valid    Adapting Program 4 4    We can use the standard algorithm for input validation to improve the exam  grade program we developed in Section 4 4  Here is the section of code used  to input the data         store user inputs  max_mark   txtMax Text  first_name   txtName Text  surname   txtSurname Text  mark   txtMark Text    As it is at the moment  you could enter any mark into the txtMark text box           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  131          Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING     STANDARD ALGORITHMS             Let   s alter the coding so that it won   t accept the following types of  invalid marks        e no marks less than 0  e no mark
102. ode as before  If you need a  reminder how    Save your program and tidy up the files into a to do these   single folder  look back to    page 45   x 2  Write a brief user guide   AM    7  Y  CAS AD Write a brief technical guide        Al       N    Stage 6     Evaluation    av   PE Pa      PY As before  write a brief report  answering these questions   e Does the program fulfil the specification    e ls the user interface appropriate    e ls the program coding readable           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  59          Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       3 7 Adding a Clear button       One possible criticism of the previous program is that once you  have used it once  you need to delete the contents of the text  boxes before using it again     We can easily improve this by adding a second command button which will    clear each of the text boxes     Add a second button   Position it on the form   Name it btnClear    Make its text    Clear      Double click on the clear  button     A code window will appear  with  the start and finish of the coding  for the clear button     Complete this as below        r    a Belinda   s Slab Calculator             How many slabs wide  Calulate    slabs and  cost    Clear    Number of slabs required    How many slabs deep     Cost of one slab         by A  Programmer  21 09 07    Total cost             Private Sub btnClear_Click         clears all text boxes  t
103. of steps from beginning to end  whatever  data you input  This limits the usefulness of the  program  Imagine a game program that was exactly  the same every time you ran it     In this section  you will learn how to make programs  that do different things depending on the data that is  entered  This means that you can write programs with  choices for the user  and with different options and  branches within them  To do this in Visual BASIC is very easy  as you will see        Here are some examples of VB statements that use the keywords IF  THEN  and ELSE     If Number  lt  0 Then txtAnswer text      That was a negative number      If Reply      No    Then MsgBox     Are you sure          If Salary  gt  5000 Then Pay   Salary   Tax Else Pay   Salary    If Guess   Correct_Answer Then MsgBox     Well Done      Else  MsgBox     Wrong   try again           The first two examples follow a simple pattern   If condition Then action    We will study using this pattern in Section 4 2                 82 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING      BASIC CONSTRUCTS          The last two examples follow a slightly more complex  pattern          If condition Then action Else alternative action        We will study using this pattern in Section 4 3       Note  We will use the following symbols in this section                        gt  greater than    lt  less than    gt   greater than or equal to   lt  
104. omputer  Systems unit  all characters  letters  numerals and  punctuation marks  are stored in a computer system  in anumeric code called ASCII  American Standard  Code for Information Interchange   The Asc  predefined function returns this code     trick  Chr takes any number  and returns the  character which this ASCII code represents        Testing the Chr function    Edit the coding of the String Function Tester program   Make the following changes        Change To  Private Sub Private Sub  btnFunction_Click        btnFunction_Click           Dim string_in As String Dim number_in As Integer  Dim number_out As Integer Dim string_out As String  string_in   txtEnter Text number_in   txtEnter Text  number_out   Asc string_in  string_out   Chr number_in   txtResult Text   number_out txtResult Text   string_out  End Sub End Sub    Note  You should also change the label on the form to read    Enter a number     rather than    Enter a string        Run the program to test the Chr function           76 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       Record the results in a table  like this  adding a few tests to check that Chr  turns any ASCII code into the character it represents        Chr predefined function       Input number   Output character   Comment       65       66       97       98       63       20                      Write a brief statement summarising the effect
105. orks  allow you to record macros  but don   t  allow you to edit the code as you can in MS Office  If you have time  you could  explore any other applications that you use to see if they have a macro facility           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  33          Learning and Teaching Scotland 2009                LANGUAGES AND ENVIRONMENT       Questions    What is a macro    What type of language is sued to write macros    What are the advantages of using macros    Describe two situations where a macro could be useful     Seach Noli          34 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       Section 3  High level programming     getting  started    3 1 Introducing Visual BASIC    For this section of the course  you are going to learn to develop programs  using a high level language called Visual BASIC  often shortened to VB     The first stage is to become familiar with the Visual BASIC environment  Here  is what a simple Visual BASIC program might look like     a gt  Club Membership    Caption  Enter your name and age in the bows below  then  click the button to register yourself as a member  Label  Text box  Button    Register       Notice the following features of the program     e The whole program appears as a form    e At the top of the form  there is a caption  club membership    e There are two text boxes for entering the name and age    e Atthe bottom t
106. orry about all  the stuff that appears  automatically in here   You will learn what it  means later  But don t  delete or alter it in any    way         Double click on the command  button to open a code window  It  should already have the first line  of code  which should read          Private Sub btnCalculate_Click                      Enter the first two lines of code as comment lines  as you did in the previous example         code for the Calculate button     by A  Programmer 21 09 07    The next stage is to declare all the variables that the program will need  It will  need to store     e number of slabs wide  a whole number    e number of slabs deep  a whole number    e the cost of a single slab  a real number  as it could be 2 99   e the total number of slabs  a whole number    e the total cost  a real number      This can be coded into two lines  like this     Dim wide  deep  no_of_slabs as Integer  Dim slab_cost  total_cost as Single    The next lines of code are translated from the pseudocode  as shown below     Pseudocode Visual BASIC   Store the number of slabs         gt  wide   txtWide Text   wide   Store the number of slabs        deep   txtDeep Text   deep   Store the cost of one slab         gt  slab_cost   txtCost Text   Calculate the number of slabs  gt  no_of_slabs   wide   deep   required   Calculate the total cost  gt   Oa Poal gt  Naudlzsiabs  slab_cost   Display ine number Ols ape        gt  ixtTotalNumber Text   no_of_slabs   required   Display the t
107. otal cost        gt  ixtTotalCost Text   total_cost             56 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009       HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED                If you have done all of this correctly  CIERRE caog  you should have a form that looks like  this  How many slabs wide  Calulate    slabs and  cost       How many slabs deep     Cost of one slab         Number of slabs required     by A  Programmer  21 09 07 Total cost                and a code window like this           _ Form1 vba      Form1 vb  Design  a       If it all looks correct  then     o binCalaulate  x    4 click lv    J Public Class Formi                         e Run the program to  make sure it is working  correctly                   Private Sub btnCalculate Click ByVal sender A      code for Calculate button    by A  Programmer 21 09 07   Dim wide  deep  no of slabs As Integer  Dim slab cost  total_cost As Single    e Enter the following data     wide txtWide Text                      deep   txtDeep Text slabs wide  4  slab_cost   txtCost Text slabs deep  5  no of slabs   wide   deep cost per slab  2 99  total _ cost   no of slabs   slab cost  txtTotalNumber Text   no_of slabs e Click the button  txtTotalCOst Text   total cost   P End Sub   LEnd Class lv   KA  m   ma             The following results should appear in the result text boxes     e total number  20 a Belinda s Slab Calculator  e total cost       59 8  as shown below         How 
108. ou will learn more about these in Section 2     1 7 Testing   We thought a bit about testing at the start of this section  Whether we are  talking about a new TV  a new item of clothing or a new computer program   the manufacturers will spend a great deal of time in testing  This testing will be  carefully planned to test a wide variety of conditions  We can divide this up  into three types of testing    Testing normal conditions   Making sure the program does what it should do when used    normally        Testing extreme conditions    Making sure the program can handle situations that are at the edge of what  would be considered normal     Testing exceptional conditions    Making sure the program can handle situations or inputs that it has not been  designed to cope with     You will see examples of all of these in Section 3     1 8 Documentation    When you buy a product  whether it is a computer  program or anything else  you usually get some kind of  user guide with it  This tells you how to use the product  It  might also contain a tutorial  taking you through the use of  the product step by step              18 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                SOFTWARE DEVELOPMENT PROCESS       Some software comes with a big fat book called user guide or manual  others  come with the user guide on a CD     As well as documentation for the user of the software  there should also be a  technical guide of some sort  This gi
109. ox so it is deep enough for two lines of text      This allows the text in the text box to word wrap at the end of a line      Belinda McSporran73    Name  Belinda McSporran  Number  73          SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          Also  in the code  change     txtDisplay text   players_name  amp  squad_number  into  txtDisplay text      Name       amp  players_name  amp  VbCrLf  amp     Number       amp  squad_number    this puts in the VbCrLf forces a If an item has speech marks         word Name and a new line  Visual then it is copied exactly  if not     colon   followed by BASIC carriage then the value of the variable is  2 spaces return line feed  displayed       After making these changes to improve the appearance of the output  you  should carry out methodical testing of the program  Assuming that the program  displays the name and squad number of the player correctly  you only need to  test that it calculates averages correctly     pany  ew Draw up a table of testing with some     e normal data  e extreme data  e exceptional data     If there are any errors  correct them  Save and print the program  Summarise  your test results by completing these three sentences     e The program gives the correct result if         e The program gives a wrong answer if      because       e The program cannot give an answer if        Stage 5     Documentation    ey  
110. p      is too small       If Number  gt  5 Then MsgBox Number  amp      is too large     End Sub       You can see that a high level language has features that make it similar to a  human language     the use of ordinary words  for example  This means that  the implementation is often carried out using similar tools to those used for  writing an essay or report  For example  cut and paste would be useful when  typing the program shown above  To write an essay or report  you would  normally use a word processing package  High level language programs can  also be written using a word processing package  The    source code    can be  saved as a text file  which can then be translated into machine code by a  compiler     However  some software development environments provide a text editor   which incorporates many of the usual features of a word processor  The most  useful of these is probably the ability to cut and paste sections of code     Activity  Consider the software development environment you are using  ee KS for the programming section of this unit  Does it have a text  I   j  editor  or do you use a separate word processing package   What useful text editing features does it incorporate           28 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                LANGUAGES AND ENVIRONMENT       2 7 Scripting languages and macros    Most of this unit is concerned with the process of developing programs written  in a high level languag
111. pected      Run the program  using your test data  and record the results in a table     av     J Pa   4 e Stages 5 and 6     Documentation and evaluation   IAL   As usual  you should    e print out hard copies of your form and the coding   e write a short user guide and technical guide   e write a brief evaluation of the program in terms of its fitness for purpose   user interface and readability     Extra task    Modify the program so that it asks your age and gives you the  message    You can learn to drive    if you are 17 or over        Note  You will need to use one of the symbols listed in Section 4 1           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  85          Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          4 3 Multiple Ifs    C    d TEG   lt     Example  Lucky Winner  The problem  A program is required that will select a  suitable prize  depending on which number between 1 and 5  is entered by the user   Stage 1     Analysis     program specification  Design  write and test a program to   e prompt the user to enter a number between 1 and 5  e store the number  e output an appropriate message    Enter a 1        You have won a colour TV      Enter a 2        You have won a mobile phone       and so on  There is no prize if the number is not between 1 and 5     Stage 1     Analysis     data flow diagram    appropriate message on  screen        any number          2     Design     interf  ee eg ve ee    T
112. ple      Finding a minimum  This algorithm works its way through a list of numbers and finds the number    with the lowest value  For example  here is a list of daily midday  temperatures recorded at a weather station during February 2003           Date 1  2 3 4 5  6 7 8 9  10  11  12  13   14  Temperature    C  4  6 5 7 11 9 8 5 3 4 13  6  Z  4                                                                Date 15  16  17  18  19  20   21   22  23   24   25   26   27   28  er de 6 l2 13 I8 le  12 10  11 9 le  11 8 l6                                                 The finding a minimum algorithm would search through all the daily  temperatures in the list and find the lowest one  In this case  it would be 2  C   on the 17th of the month   The algorithm would return the value 2  the actual  minimum temperature               134 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING      STANDARD ALGORITHMS          Other examples could include     e finding the lowest mark in a list of exam marks  e finding the winner in a list of golf scores  e finding the youngest member in a club membership list     It can also be used to search a list of names to find the first if arranged  alphabetically  this is possible because strings are stored as ASCII codes   which are numbers     Finding a maximum  This algorithm works its way through a list of numbers and finds    the number with the highest value  In the exam
113. ple above  it  would find 12  C  on the 21st of the month         Counting occurrences    This algorithm also works its way through a list of numbers  As it does so  it  counts how many occurrences of a given value there are in the list  For  example  if the counting occurrences algorithm was applied to the list of  midday temperatures  with a search value of 9  C  it would return the answer 2   as there are 2 days  the 6th and the 24th  when the temperature was 9  C        Date 1  2  3 4 5  6 7 8 9   10 11  12  13   14  Temperature    C  4  6 5 8 11 9 8 5 3 4 13  6  Z  4                                                       Date 15  16  17  18  19   20   21   22   23   24   25   26   27   28  Temp    C  5 l6  2  3  a  e  12 10 11 9 6 J 11 8 l6                                                          Linear search    The final standard algorithm which you need to know about is called linear  search  The idea is simple     it searches through a list looking for a particular  item and reports where the item is found     In the above list of temperatures  if linear search were given the search value  7  C  it would return the answer 13  as 7  C is found at position 13 in the list              SOFTWARE DEVELOPMENT  INT 2  COMPUTING  135          Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING      STANDARD ALGORITHMS       Questions    1  Look at these lists of data items     1  27 3 1  999 1  0 001  2  15 6 2  333 2  0 002  3  9 93 3     500 3  0 010
114. ps when the  Loop While condition condition becomes false  Do Whe canaliton Only executed while the    Line s  of code to be dee Dee ha  Do    While Loop condition is true  as it is  repeated on  tested at the beginning  Loop                      Do   need to  know about all  four types              No  for this unit it is  enough to be able to  use one type of  conditional loop           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  127          Learning and Teaching Scotland 2009                   HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS       Congratulations  You have completed Section 4     Here is a Summary of what you should now be able to do using VB     Y    p  TE 4    design and create a form  using text boxes  command buttons   labels and captions   change the properties of an object   analyse a problem using a data flow diagram   write pseudocode  convert it into VB code  and assign it to an event  declare string  integer and single real  variables   use text boxes  message boxes and input boxes   test a program using normal  extreme and exceptional data   use a range of predefined functions   write brief user guides and technical guides for simple programs  evaluate a program in terms of fitness for purpose  user interface and  readability   use conditional statements involving If  Then  Else and End If   use simple and complex conditions involving comparison operators  And   Or and Not   create fixed loops using For    Next   create conditional loops using 
115. r   3 Then   Me BackColor   Color Green   MsgBox Number  amp      wins you a holiday in Spain      End If    If Number   4 Then  Me BackColor   Color  Yellow  MsgBox Number  amp      wins you 10p      End If    If Number   5 Then   Me BackColor   Color Gold   MsgBox Number  amp      wins you a day at the beach      End If    If Number  lt  1 Then MsgBox Number  amp      is too small      If Number  gt  5 Then MsgBox Number  amp      is too large      End Sub             Where multiple actions are required  a  conditional statement is of the format     If condition Then  Action 1  Action 2  Action 3  and so on   End If          SOFTWARE DEVELOPMENT  INT 2  COMPUTING  89             Learning and Teaching Scotland 2009              HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          Practical task 1     adapt the    Lucky Winner    program to fulfil this specification     Design  implement and test a program that asks the user to enter a  grade  A  B  C  D or F   and gives you messages like    A means you  got over 70         B means you got between 60  and 70      and so  on  The form should change colour depending on the grade entered        As usual  you should     e print out hard copies of your form and the coding   e write a short user guide and technical guide   e write a brief evaluation of the program in terms of its fitness for purpose   user interface and readability     Practical task 2     Adapt the AB_code program to correctly code Z and z    Remember the
116. r   InputBox    Enter the player   s number      game_1   InputBox    Score in 1st game       game_2   InputBox    Score in 2nd game       game_3   InputBox    score in 3rd game        average    game_1   game_2   game_3  3    txtDetails Text   players_name  amp  squad_number  txtAverage Text   Clint  average     End Sub          68 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          Notes      a  InputBox    Enter the  player   s name     generates  a box on the screen like this   whatever the user types into  the text box is stored in the  variable players_name when  the OK button is clicked      b  The  amp  between players_name and squad_number simply makes the                   basketball X   Enter the player s name  Cancel             contents of these two string variables follow on after each other in the    txtDetails text box      c  Clnt average  turns the value of average into the nearest whole number   see Section 3 10   Alternatively  you could use System Math Round     average  0      Stage 4   Testing    e Run the program to make sure it works     You will notice that the output looks like this     It would be better to make it look like this     To do this  make the following two changes     On the form     e select the txtDetails box    e scroll down the properties window to find multiline    e change the multiline property to true    e resize the text b
117. r counter   Until  pin   correct_pin  Or  counter   3    3   5  If counter   3 then display If counter   3 Then txtMessage Text    message 3     The card is being kept for security          Variables required   counter  integer   pin  integer   correct_pin  integer     Stage 3     Implementation       e Start a new Visual BASIC project    e Create a form as above    e Name the command button btnStart    e Name the text box txtMessage    e Enter the code for the command button  declare all required variables    e Save the project and form in a new folder     Stage 4   Testing       Create some suitable test data  and use it to test the program                                         Test data 1   Test data2   Test data 3  Test data   1347 9999 1234  8888 4321  1347 9999  Comment  SOFTWARE DEVELOPMENT  INT 2  COMPUTING  125          Learning and Teaching Scotland 2009                      HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS       ray   aw  Stages 5 and 6     Documentation and evaluation    As usual  you should     e print out hard copies of your form and the coding   e save your program   e write a short user guide and technical guide   e write a brief evaluation of the program in terms of its fitness for purpose   user interface and readability     Task  Password Checker  Modify the program to   e prompt the user to enter a password  which could contain letters as well    as numbers   e allow five attempts at guessing the password     Note  If you want to keep
118. racter uncoded_char  A string variable to hold the coded character coded_char  An integer variable for the ASCII code of the input character ascii_uncoded  An integer variable for the ASCII code of the coded character ascii_coded    Complete the code for the btnCode button  by using Dim to declare these four  variables  and converting each step of the pesudocode into VB code     Private Sub btnCode_Click            coding for the Code command button     by A  Programmer on 19 10 07    Dim uncoded_char  coded_char As String  Dim ascii_uncoded  ascii_coded As Integer    uncoded_char   txtin text   Step 1  ascii_uncoded   Asc uncoded_char   lt         ______ Step 2  R 2 a Bn ns  ascii_coded   ascii_uncoded   1 Step 3  coded_char   Chr ascii_coded  a  Step 4    txtOut text   coded_char a    Step 5  End Sub    Code the Clear button in the usual way  Save the project as AB_code           80 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       Stage 4   Testing    Run some tests using normal  extreme and exceptional data  Record your  results in a table     Stage 5     Documentation   gt  As usual  write a brief user guide and technical guide for the  Cw j  program  and attach a hard copy of the code and the form  layout    Stage 6     Evaluation   aS Write a brief evaluation of the program  You should include a  7 NA fA note about the letter s  which it codes incorrectly  You will le
119. rer  i     Solution Explorer    SAELE   28  testi  Sa  My Project  ES  Form1 vb              Properties     e  NotifyIcon   2 Form1 System  Windows  s Form Py  E a   az  3  Z    Error List  ix ControlBox e  Q 0 Errors   1 0 Warnings   i  0 Messages eee  b  ied   DoubleBuffered  Description File Line Colums Project Enabled  Font Microsoft Sans Serif      ForeColor HM Controirext  FormBorderStyle Sizable  HelpButton False k  Font  The font used to display text in the control   Ready TE  15  15 T   300 x 258          At the top is the menu bar  with the usual menus  File  edit  and some    specialised VB menus     Below this is the VB toolbar  The item you will use most is the  gt  icon  which    you use to run a program     Down the left side is the toolbox  from which you will select objects to place on  your form  The form appears in the form window in the middle of the screen           36 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009             HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED               On the right side of the screen you will see  the solution explorer window and the  properties window  All of these will be  explained as you work through the  examples     Important advice   If any of the windows  disappear unexpectedly   you can get it back by  selecting it in the View  menu     We are going to learn to develop Visual  BASIC programs  using the steps of the  software development process that you  have already m
120. riable names           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  61          Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       3 9 Working with numbers     tasks    For each task below  you should        e clarify the specification  analysis    e draw a data flow diagram  analysis    e sketch the user interface  design    e write pseudocode for the button  design    e create the form  implementation    e write the coding  implementation    e draw up a table of testing   e test the program with normal  extreme and exceptional data  e write brief user and technical guides  documentation    e evaluate the program     1  Design  write and test a program to calculate the average of six test  marks     2  Design  write and test a program to calculate the volume of a cylindrical  water tank  using the formula  volume   TT rh  r   radius of tank  h    height of tank     3  Design  write and test a program to calculate the number of points  gained by a football team  given the number of wins  draws and lost  games  assuming a win is worth 3 points  a draw 1 point  and no points  for a lost game     4  Design  write and test a program to calculate the storage requirements  in megabytes for a bit mapped graphics  The inputs should be the  breadth and height of the graphic in inches  the resolution in dots per  inch and the colour depth in bits per pixel           62 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teach
121. roduct is developed because the  process is essentially the same        For example  think about the process of developing a new  model of television     Stage 1  Analysis    Before a new product is developed  someone within the company  probably in  the marketing department  analyses what people want  They consider which  products are selling well  look at what rival companies are producing and  maybe even carry out a survey to see what people want  From this they can  work out which features are required in their newest model  including its size   target price range and various technical requirements     They use this information to produce a specification for the new model of TV   This states clearly all the features that it must have           10 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          SOFTWARE DEVELOPMENT PROCESS       Stage 2  Design    The next stage is to turn the specification into a design  Designers will get to  work  alone or in groups  to design various aspects of the new TV  What will it  look like  How will the controls be laid out  Sketches will be drawn up and  checked against the specification  Another team of designers will be planning  the internal circuitry  making sure it will allow the TV to do all the things set out  in the specification     Stage 3  Implementation    Once the design phase is over  engineers will get to work to actually build a   prototype  Some will build the case according to t
122. rogram and how the program might be structured  Program  designers use a variety of methods for describing the program structure  Two  common ones are called pseudocode and structure diagrams  There are  many others  but we will only consider these two     It is easy to understand these if we think about an everyday example  rather  than a computer program     Think about making tea  Here is a list of instructions for this task     Get a mug out of the cupboard    Put a teabag in it    Boil the kettle    Pour boiling water from the kettle into the mug   Stir     daa el be era    This is an example of pseudocode  It is a numbered list of instructions written  in normal human language  in this case  English   It doesn   t go into all the  details  but it gives the main steps     Another way of showing this is as a structure diagram  It could look like this     Making tea    Get mug Put Boil kettle Pour water  from teabag in from kettle        cupboard mug into mug    Each instruction goes into a separate box  You read pseudocode from top to  bottom  You read a structure diagram from left to right           16 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          SOFTWARE DEVELOPMENT PROCESS       A    AJ Pa  DAS    Now try a     gt  Activity          ouple for yourself  Here are some simple tasks     Q    e Going to school   e Going to New York   e Having a shower     e Phoning a friend  S  e Becoming a millionaire  b    Choose any two
123. rogram specification       Design  write and test a program to    e prompt the user to enter a player   s name  squad number and points scored  in games 1  2 and 3   e calculate the player   s average score  rounded to the nearest whole number   e display the player   s name  squad number and average clearly on a form     Stage 1     Analysis     data flow diagram    Players name    Players name  Squad tet ae a ee eed  ae Squad number  Score 1                      _ gt  f  E a points  Score 2  Score 3    Stage 2     Design     user interface    This time  we will use input boxes  which are like message boxes  but used  for input  to enter the data  so the form only needs a command button  two text  boxes for the output  and the usual labels and caption     Basketball Team Manager    Player  details     by A   Average Programmer  score  18 10 2007             66 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       Stage 2     Design     pseudocode    When the user clicks on the start button  input boxes should pop up to input  each of the six items of data  then the average should be calculated  and the  results displayed     In pseudocode     prompt for and store the player   s name   prompt for and store the player   s number   prompt for and store each of the three scores   calculate the average score   display the player   s name and number   display the player   s average s
124. s greater than the maximum mark for the exam     All you need to do is replace the single line  mark   txtMark Text  with an input validation loop  like this   Do  mark   InputBox    Enter a valid mark      If  mark  gt  max_mark  Or  mark  lt  0  Then MsgBox     That was not a  valid mark      Loop Until  mark  gt  0  And  mark  lt   max_mark   txtMark text   mark  Test the program to ensure that the input validation is working   Extra task   Change the line max_mark   txtMark Text to ensure that the user cannot enter    a maximum mark less than 0 or greater than 200  by replacing it with a  standard input validation loop        132 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     STANDARD ALGORITHMS       5 2 Input validation tasks    Adapt the valid_mark program from Section 5 1 to do each of the  following   You should start by exporting the valid_mark program  as a template  so that you can base each of these task on the  template  that way you won   t need to start each program from  scratch          e Prompt the user to enter their age   Do not accept ages less than 0 or greater than 120 as valid ages     e Prompt the user to enter a 4 digit PIN   The program should only accept the PIN if it is 4 digits long    Hint  Make it an integer  what is the smallest and largest value      e Prompt the user to enter what year they are in at school   Only accept 1  2  3  4  5 or 6 as valid years  
125. sage  Text      welcome to VB       amp  name          Run the program  The result will look   yo My first Program in VB BAX  something like this  depending on  where you placed your label   Enter your name Albert Einstein    Welcome to VB  Albet Einstein    click for  message    by A  programmer 15 09 07                   The alternative is to make the output appear in another text box           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  49             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          Output to a text box  Again  two changes are needed to the program     Firstly  add a second text box to the form and name it  txtMessage        Secondly  change the line of code from   MsgBox    welcome to VB       amp  name   to     txtMessage Text      welcome to VB       amp  name       Run the program  a My first Program in VB  Joey    The result will look something like this Enter your name Albert Einstein   depending on where you placed your  second text box         click for  message    Welcome to VB  Albert Einstein    by A  programmer 15 09 07          Choosing the style of output    You have now seen three ways of outputting the same  message     e inamessage box  e directly on the form in a label  e ina text box on the form        This may be stated in the program specification  If not  itis a  decision that you can make at the design stage           50 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning an
126. ss Formi      Al  e Double click on the   PAESI i P    ick  ByVal senger As System Obje    button       Class    A code window should  appear          Be careful not to change  any of the text which  appears here        Note the button   s name   btnMessage  and the  event  click  which will  activate this code  appear automatically     You will enter your VB  coding for this button in  the space between the  first and last lines which  have been inserted  automatically  v       e Enter the lines of code which are highlighted below in bold  Read the    explanatory notes as you go along  so that you understand what the code  does     The first two lines of code are as follows        code for the Message button     by A  Programmer on 21 09 07     These two lines start with a single apostrophe        which means that they are  comment lines     they are ignored by the computer  but make the program  more readable  It is always good practice to start any new section of coding  with some comment lines like these            SOFTWARE DEVELOPMENT  INT 2  COMPUTING  43             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          The next line is  Dim name As String     This line tells the computer to set aside a storage location in memory which  will need to hold a string of characters  and to call it    name        we know this is  required from the data flow diagram     remember  the program will input a  name  then output the 
127. st of programs that   have used recently     e Microsoft Word  the word processing program that   use       regularly use  three versions of it  Word 2000  Word 98 for MacOS 8  Word v X for  MacOS X    e Microsoft Excel  spreadsheet used to keep charity accounts for which    am the treasurer    e ClarisWorks 4  integrated package       mainly use its word processor and  simple database sections    e Internet Explorer  both PC and Mac versions     for browsing the web    e Safari  web browser for MacOS X    e three different email clients  Netscape Communicator  MS Outlook and  Mail    e iPhoto  for organising my digital photographs    e iMovie  for editing digital movies    e Adobe Photoshop  for editing digital photographs    e Citrix ICA thin client  allows me to connect to my work computer from  home    e Toast  for burning CDs              8 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009          SOFTWARE DEVELOPMENT PROCESS       e Print to pdf  a shareware program for creating pdf files   e Adobe Acrobat and Preview  for viewing pdf files    e Macromedia Flash  for developing animated graphics   e Home Page  an ancient but reliable web page editor    e some game programs   e Symantec Anti virus suite     But that   s not all  On each computer that   have used  a program  or group of  programs  called the operating system must have been running  So   must  add the following to my list     e Windows 97  on the ancient laptop   am usin
128. t do is called the program  specification              SOFTWARE DEVELOPMENT  INT 2  COMPUTING  53             Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          Stage 1     Analysis     program specification  Design  write and test a program to     e input two whole numbers  the no  of slabs wide and no  of slabs deep   e multiply them together  no  of slabs needed   no  wide x no  deep    e input the price of a single slab   e multiply to get the total price   e display the results  number of slabs required and total cost      The program should work for any numbers   Stage 1     Analysis     data flow diagram  A    blob    for the program     Nuinbarerelabe    What information comes out of the  program  Total cost    What information does the program need as input     No  of slabs wide  Number of slabs  No  of slabs deep    Cost of a slab a mas    Total cost          54 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          Stage 2     Design     user interface    Sketch out how we want the Belinda   s Slab Calculator    form to look   veh   How many slabs wide   This time we will use text  boxes for both input and  output of data     Calculate  slabs  and cost    How many slabs deep     This form has  Cost of one slab         e a title caption    e six labels Number of slabs required      e three text boxes for input by A
129. t to read    Enter your name     do this in the properties  DatePicker    window   Move the label to wherever you want it to appear on the    form     e Add a second label with your name and today   s date  in the same    way            ListBox    3a ListView          SOFTWARE DEVELOPMENT  INT 2  COMPUTING  41             Learning and Teaching Scotland 2009      Common Con         Toolbox ix  A           HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED          Sry Rowe    e Next  add a text box  Double click on the text box icon from the   c padi   2  RadioButton  toolbar  me    ee 5  RichTextBox  You may need to scroll down to find it  they are listed in     alphabetical order   Use the properties window to change its name  property  you ll need to scroll up the properties window to find it   from    TextBox1    to    txtName            Toolbox   ix    All Windows F    A    Common Con            Pointer    e Finally  add a button  Double click on the button icon on the ao   ab  Button    toolbar    e Use the properties window to change the button   s text to    click  for message     and its name to    btnMessage        Re size it and position it on    the form  a3  My first Program in VB aA    If you   ve done all that correctly  your form should Enteryourname     now look like this     If not  don   t worry     ask your teacher for help     it  gets very confusing at this stage  with lots of    things that can go wrong  but you ll soon get the  hang of it           by A 
130. tMessage ltems Add    Have a nice day       IstMessage ltems Add    Have a nice day       IstMessage Items Add    Have a nice day          End Sub        IstMessage ltems  Add  simply adds the text to the  items displayed in the list box           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  97             Learning and Teaching Scotland 2009                       HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          Here is a second version of the program that uses a FOR    NEXT loop to cut  down the amount of coding required     Private Sub btnLoop_Click            code to display 10 greetings on the screen Alter the coding as      by a much better programmer shown and run the       using a FOR    NEXT loop program again   Dim counter As Integer It does exactly the   same  but takes much   For counter   1 To 10 less coding   IstMessage ltems Add    Have a nice day           Next   End Sub    You might be wondering why we used a list box instead of displaying the  output in a text box or a label  A list box allows multiple items to be displayed  without overwriting each other     4 8 Repetition using For    Next    In this example  we will develop another program to display a repeated  message in a list box     Stage 1     Analysis    Program specification Data flow diagram       Hello  Hello        message        Design  write and test a program to  display the message      Hello  Hello  Hello      25 times               98 SOFTWARE DEVELOPMENT  INT 2  COMPUTING          
131. ter the word END after entering all the names  The loop  can then continue until name      END              Pseudocode    Visual BASIC coding       1  Clear the list box    IstNames  Items Clear         2  Set a counter equal to zero    counter   0       3  Do the following     Do       3 1 prompt the user to enter a  name    name   InputBox    Enter a name  or  END            3 2 add the name to the list box    IstNames Items Add name        3 3 extract the first letter of the  name    initial   Mid  name  1 1        3 4 if the first letter is A  add 1 to  the counter    If initial      A    Then counter   counter    1       3 5 until the user enters end    Loop Until name      END             4  Add the counter to the list box       IstNames Items Add counter        Variables required     counter  integer   name  string   initial  string        e Start a new Visual BASIC project     e Create a form as above     Stage 3     Implementation    e Name the command button btnStart     e Name the listbox IstNames     e Enter the code for the button  declare all required variables    e Save the project and form in a new folder           122 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                HIGH LEVEL LANGUAGE PROGRAMMING      BASIC CONSTRUCTS          Test the program with the following sets of test data and add some more of    Stage 4     Testing                   your own   Test data   Testdata   Test data  1 2 3  Test data Andrew
132. times the section of program is to  be repeated  What about times when the number of repetitions is not known in  advance     For example  a quiz program might give the user  repeated chances to get the answer correct  The  programmer doesn   t know in advance whether the  user will get the question right the first time  or take  two  three  four or more attempts     In this type of situation  the programmer needs to use  another kind of loop  Visual BASIC provides several  other types of loop  We will use a type called Do    Loop Until             The pattern  syntax  for this type  of loop is very simple        Do  Line s  of code  To be repeated  Loop Until condition          112 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                   HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          Here is a simple example     Set up a form like Enter the following coding for the button     this        Private Sub btnQuestion_Click           Se ee Jog     generates a question to the user  aaa z      and waits for the correct answer          Arithmetic tester  v 1   Dim user_answer As Integer    lick f    penton Dim correct_answer As Integer    by A  Programer 13 03 09 correct_answer   4             Do          user_answer   InputBox    What is 2   2       Loop Until user_answer   correct_answer    MsgBox     Well done          End Sub    Run the program  Does it behave as predicted    Adapt the program to ask    e adifferent arit
133. tland 2009                   LANGUAGES AND ENVIRONMENT             Instructions and commands made in these binary  digital form for processors are known as machine  codes  Here are a few machine codes for a 6502  processor        Not very easy  to understand   are they      10101001 00000001 Se   10000101 01110000     10100101 01110000    There are several problems with machine code     e machine codes for different processors are different  e they are very hard for humans to understand and use  e they take up a lot of space to write down   e itis difficult to spot errors in the codes     Unfortunately  processors don   t understand anything else  so machine code  has to be used  The earliest computers could only be programmed by entering  these machine codes directly  It was a slow process  easy to get it wrong  and  very difficult to track down and fix any bugs in the programs  Machine codes  are an example of low level languages  understood by the low level  components of the computer system  the processor and other electronic  circuits      To get round these difficulties  computer scientists invented high level  languages     High level languages are similar to human languages  Instead of using binary  codes  they use    normal    words  For example  the computer language BASIC  uses words like PRINT  IF  THEN  REPEAT  END  FOR  NEXT  INPUT and so  on  That means that high level languages are easier to understand than  machine code and are more    readable     that is it
134. uestions   e displays    Well done     right first time     if the user gets it right  first time   e displays    Keep practising  You took X tries to get it right      otherwise        ee KS Test the program using normal  extreme and exceptional data   Cw VJ  Write brief user and technical guides  and an evaluation report   4 15 More examples using Do    Loop Until   Example 4 15 1 Class lists   Design  write and test a program for a teacher  The program should   prompt the user to enter any list of names  which will be displayed on the  screen  The program should count how many of these names begin with    the letter A  and display this information at the end of the list     Stage 1     Analysis     Data Flow Diagram    List of names         Names entered  at keyboard    Number of As    Stage 2     Design    We want the user interface to look like this     It has a command button  a title and a list box Click to   called IstNames   enter  names  Next  we design the list of steps  pseudocode   and then the coding for the command button              SOFTWARE DEVELOPMENT  INT 2  COMPUTING  121          Learning and Teaching Scotland 2009             HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS       Q  We will need to use a loop  Should it be a For    Next loop  or a Do    Loop  Until    A  As we don   t know in advance how many names there will be in the list  we  need to use a Do    Loop Until     Q  What condition will we use to stop the loop   A  Ask the user to en
135. upported  although it  might be possible to use it in this way  Students will need significant tutor  support  particularly while attempting the practical programming sections of the  unit  This support would include giving help with the complexities of the Visual  BASIC environment  providing extra example programs where a student  needs reinforcement activities  and emphasising key teaching and learning  points as they occur     All the examples provided are exemplified in Visual BASIC  VB  2005 EE   Express Edition   and the same coding should work in VB2008 EE  Minor  amendments might be required to run the programs in other versions of  VB net  Users of versions VB5 or VB6 should use the original version of these  materials  published and distributed by Learning and Teaching Scotland  This  software development environment and programming language has been  chosen as it is one in common use in Scottish schools at          SOFTWARE DEVELOPMENT  INT 2  COMPUTING  5          Learning and Teaching Scotland 2009                INTRODUCTION       present  However  the SQA unit specification does not require any particular  language or environment  so the examples could be adapted and or  substituted by examples in any other structured procedural high level  language  To facilitate this  the examples avoid where possible constructions  that are very specific to VB and that are not easily converted into other  languages     Answers to questions are provided at the end of the pac
136. ur  computer without needing to be translated     Questions     1  Name the two main types of translator programs    2  Which one translates a whole program into machine code before it is  executed    3  Which one translates a program line by line as it is being executed    4  Why do machine code programs run more quickly on a computer than  high level language programs     2 6 Text editors    During the development of a high level language program  after the analysis  and design stages  the programmer  or team of programmers  have to  implement the design by coding it in a suitable high level language           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  27          Learning and Teaching Scotland 2009                LANGUAGES AND ENVIRONMENT       Here is an example Visual BASIC program     Private Sub btnOK_Click ByVal sender As System Object  ByVal e As  System EventArgs  Handles btnOK Click      coding for the OK command button      displays an appropriate message for each possible number entered     written by A  Programmer on 21 09 07    Dim Number as Integer    Number   txtNumber text    If Number   1 Then MsgBox Number  amp      wins you a colour TV       If Number   2 Then MsgBox Number  amp      wins you a mobile phone      If Number   3 Then MsgBox Number  amp      wins you a holiday in Spain     If Number   4 Then MsgBox Number  amp      wins you 10p      If Number   5 Then MsgBox Number  amp      wins you a day at the beach     If Number  lt  1 Then MsgBox Number  am
137. ves technical information  which is of little  interest to most users  except that it will usually include information about the  specification of computer required  including how much RAM it needs  how  fast a processor it must have and which operating system is required  The  technical guide should also include instructions on how to install the software       Get hold of a software package that has been bought by your  E Z school or college  or one you have bought yourself at home   ASG open it up and take a look inside the box that it came in     Make a list of all the items of documentation that you find there     1 9 Evaluation    The final stage in the process before the software can be distributed or sold is  evaluation  Evaluation involves reviewing the software under various headings  to see if it of the quality required     In this course  we will review software under three headings  fitness for  purpose  user interface and readability     Is the software fit for purpose  The answer is    yes    if the software does all  the things that it is supposed to do under all reasonable conditions  This  means going back to the program specification  produced at the analysis  stage  and checking that all the features of the software have been  implemented  It also means considering the results of testing  and making  sure that the program works correctly and is free from bugs     The user interface should also be evaluated  Is the program easy to use  Is it  clear what all
138. ways have an interpreter as well as the high level language program   often called source code      2 5 Compilers  An alternative approach is to use a compiler     Going back to the Japanese lecture example  instead of using a translator at  the conference  you could write down the text of your lecture in English and  get a translator to translate it all into Japanese is advance  You could then  send the translated lecture script to the conference and have it read out by a  Japanese person there     The advantages are obvious     your lecture can be delivered in the 1 hour  allowed in the conference program  and it can be used as often as required  without it needing to be translated over and over again           26 SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009                LANGUAGES AND ENVIRONMENT       A compiler program works in the same way  It takes your high level language  program and translates the whole program into machine code once  This  machine code can then be saved and kept  Once translated  it can be used  over and over again without needing to be translated every time  The compiled  program therefore runs more quickly  and the user doesn   t need to have a  translator program on their own computer     Software that you buy  such as a games program or an application  will have  been compiled into machine code before being distributed and sold  What  you get on the disk or CD is a machine code program that can run on yo
139. writing the previous value  We need to have different variable  names for each name and mark  but we can   t do that within the For  Next loop     The answer to our problem is a special type of data structure called an array   An array can be sued for any number of items     in this example  we are  assuming there are five students           SOFTWARE DEVELOPMENT  INT 2  COMPUTING  139          Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     STANDARD ALGORITHMS          Rather than setting up five variables    we can set up a name array  like  for five names  like this     this        Dim first_name As String   Dim second_name As String   Dim third_name As String   Dim fourth_name As String Dim student_name 4  as String  Dim fifth_name As String       and rather than setting up another  set of five variables for the marks  like     we can set up a mark array  like  this     this        Dim first_mark As Integer   Dim second_mark As Integer   Dim third_mark As Integer Dim mark 4  as Integer  Dim fourth_mark As Integer   Dim fifth_mark As Integer    What does Dim student_name 4  as String mean  Instead of setting up five    separately named variables to hold the five names   fourth_ fifth_name  name    Visual BASIC sets up a variable structure called an array that can store all five  names  with each array element being referred to by its index number  0  1  2   3 or 4        A UAC GY    first_name second_    name       student_ student_ student_
140. xtWide Text            txtDeep Text            txtCost Text            txtTotalNumber Text            txtTotalCost Text            End Sub       Test the new version of the  program  When you click the  Clear button  all the text boxes    should clear  ready to be used  again              60    SOFTWARE DEVELOPMENT  INT 2  COMPUTING           Learning and Teaching Scotland 2009       Jog                HIGH LEVEL LANGUAGE PROGRAMMING   GETTING STARTED       3 8 Arithmetical expressions    In Section 3 7  the example program carried out two simple multiplications   using the lines of code     no_of_slabs   wide   deep  total_cost   no_of_slabs   slab_cost     All other calculations can be carried out in a similar way  Some of the symbols  used are the same as in    normal    arithmetic  but some are different     Adding    Subtraction  Multiplication  Division   Raising to a power        1     gt     For complex calculations involving several operations  multiplication and  division take precedence over addition and subtraction  However  where the  order of the operators matters  it is safest to use brackets     Here are some examples in Visual BASIC     total   first   second   third   age   2009   birth_year   time_in_australia   time_in_scotland   12   tax    salary   4600    0 23   years   months 12   area_of_circle   3 14    radius   2   volume_of_sphere    4   3 14    radius   3     3     Note   e the use of brackets where the order is important  e the use of readable va
141. yed in the list box           100 SOFTWARE DEVELOPMENT  INT 2  COMPUTING              Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS          Now test the program thoroughly using normal  extreme and exceptional  values for both    message    and    how_many        Modifications  3     At the moment  this program can display any message over and  over again  but it is the same message on each line        Can you adapt the program to produce displays like          Go home  Now     Hint  You will need  two  or three  lines  of code within the  For    Next loop          Go home  Now     Go home O  Now  2       4 9 Counting using For    Next  Each For     Next loop that we have used so far is of the format   For counter   1 to maximum    Action  Next          Note that we have called the loop variable    counter     because that is what it  does   but it can be called anything you like  The following versions would  work in exactly the same way     For silly name_for_a_variable   1 to maximum  Action  Next    For i  1 to maximum  Action  Next    The last of these  using i as the loop variable  is probably the most commonest              SOFTWARE DEVELOPMENT  INT 2  COMPUTING  101          Learning and Teaching Scotland 2009          HIGH LEVEL LANGUAGE PROGRAMMING     BASIC CONSTRUCTS                    For    Next loops are an  is because the number of  fixed in advance by the    of maximum     Example 4 9 1 Counting Program  St
    
Download Pdf Manuals
 
 
    
Related Search
    
Related Contents
HQ W7-54903- N  Sony DSBK-190 User's Manual  LE MODÈLE TS-37G BRAISIÈRE BASCULANTE LoLo  User Manual - powerbridge.de  Lantronix 485 Network Card User Manual  Untitled    取扱説明書  OPTIMA 100 OPUS OPTIMA 100 DESIGN      Copyright © All rights reserved. 
   Failed to retrieve file