Archive for the ‘Software Development’ Category

Compilers and Interpreters

December 5, 2007

I think this is a hard bit of the course to understand (and explain) but here goes:

All high level language (HLL) programs need to be translated into machine code (aka 1’s and 0’s/binary). There are two forms of translators to make this happen; Compilers and Interpreters.

Compilers – These turn the whole HLL program into machine code in one go. This results in a file (object code) that can then be run on any computer system (is very portable) and runs very quickly (as it does not need to be translated again). Unfortunately if you have made a mistake (called a syntax error) in your program then it won’t run at all.

Interpreters – These turn the HLL program into binary each time you try and run it. An interpreter will go through each line of your program each time it translates it. This means that it is slow to translate your program.

Here are the Powerpoints below:

translators-1.jpgtranslators-2.jpgtranslators-3.jpg

Standard Algorithms 3 & 4

December 3, 2007

So these two find the highest number in a list or the lowest number in a list.  The way they work is this:  look at the first item in the list and make it the maximum, then look at every other item and see if it is more.  Quite simple when you think of it like that.

Here is the pseudocode for finding max:

1.1  set the first item to be the maximum

 

1.2  for each item (starting with the second)

 

1.3  if the current item is more than the maximum

 

1.4  set the current item to be the maximum

 

1.5  end if

 

1.6  end loop

 

1.7 print out the maximum

 

 Finding the minimum is exactly the same only change more than to read less than (and every maximum to minimum).

 

Powerpoint:

 finding-max-min.jpg

 

 

 

 

Standard Algorithm 2 – Linear Search

November 30, 2007

This algorithm asks the user for something to look for and then checks through a list of items to see if it can find it. If it does find it, the algorithm says in what position it found it. So for example from the following list:

“Stewart”, “Simon”, “Dara”, “Scott”, “Keith”, “Farooq”, “Gaetano”

User Input Algorithm Output

Stewart 1

Dara 3

Gaetano 7

In the same way as the last standard algorithm you need to be able to write the pseudocode in the exam!

1.1 ask for item being searched for

 

1.2 for each item in the array

 

1.3 if this item matches the item being searched for

1.4 store the position

 

1.5 end if

 

1.6 end loop

 

1.7 print out where the item was found

 

Powerpoint below:

linear-search.jpg

Standard Algorithm 1 – Counting Occurrences

November 29, 2007

This is the first standard algorithm (in no particular order) that you have to know, and be able to write a pseudo code version of in the exam.

Put simply this algorithm counts the number of times an item appears in a list. The item could be a name or a number, the list is normally an array.

So for example in the following list:

“A” “B” “B” “C” “B” “A” “A” “B” “C” “B”

The algorithm would ask the user what they are looking for and then should return the results below:

Being looked for                             Number of occurrences

A                                                                          3

B                                                                          5

C                                                                          2

So you need to be able to write the pseudo code that will do this. My answer is below, see the powerpoints at the bottom for more detail:

1.1 ask for item being searched for

1.2 for each item in the array

1.3 if this item matches the item being searched for

1.4 add one to the count

1.5 end if

1.6 end loop

1.7 print out the number of times the item was found

 

counting-occurrences.jpg


Brazilians!

November 23, 2007

This was Mr Polland’s excellent program that I converted in to VB (and am still a bit too excited about).

It has an array of your names, an array of brazilian endings, and it concatenates a random ending onto a substring of your name.

The point of the lesson is to do with Functions. The random function is called with two parameters (low and high) andit then generates a random number between those two. In the program I use that random number to pick a brazilian ending and put it onto your name.

Here is a screenshot:

brazilian-program.jpg

Local and Global Variables

November 22, 2007

A local variable is declared (set up) and only available for use in the sub-routine it is made in. A global variable is declared at the start of your program (in VB anyway) and can be used anywhere.

It is easier to understand when you look at some code:
private sub get_marks

dim marks(10) as integer

for counter 1 to 10

marks(counter) = inputbox(“Type in your mark”)

next

end sub

In the code above the array (marks) is only available inside the sub-routine called get_marks. If you try to access it somewhere else, it won’t work i.e. the scope of the variable (array) is local

If you set up the variable (or array) at the start of the program before any sub-routines (like we normally do) then it will be available for use everywhere i.e. the scope of the variable is global

Notes below:

local-global-variables.jpg

String operations – Sub strings and Concatenation

November 20, 2007

We looked at what a string variable was last week e.g. “James”, “Eh12”. You need to know about two things that you can do to this type of data:

Substring – take a part of a string e.g. take “ame” from “James”

Concatenation – join two strings together e.g. join “Craig” and “mount” to make “Craigmount”

That is pretty much it, except you need to know how to make Visual Basic do this. Here are some examples:

Concatenation is done using the & symbol.

For example:

first = “j”

second = “whiteside”

username = first & second

The code above will make username equal to “jwhiteside“.

Substrings are done by using left, mid (or right).

For example:

day = “wednesday”

firstbit = left(day, 6)

middlebit = mid(day, 4, 3)

lastbit = right(day, 3)

This would make firstbit equal to “Wednes”, secondbit equal to “nes” and lastbit equal to “day”.

Click on the notes below to see the other examples and the questions again.

string-ops.jpgstring-op-questions.jpg

Sub routines

November 19, 2007

Once I eventually got my program to work in the way it was supposed to 😉 we looked at what a sub-routine is (also called a procedure). There were two sub routines in this program that took in pupil marks and then printed out an average, they are called:

  • fill_array
  • calculate_average

It is good to make use of sub-routines as they increase the maintainability of your program (i.e. other programmers can update your program easily).

These can be called (made to run) from any part of the program.  Click the notes below to see the program:

subroutines.jpg

Because this program makes use of subroutines so it is modular!

For Loops

November 18, 2007

We did some quick questions (here they are without answers constructs-quick-qus-wthout-answers.jpg in case you want to try them again, with answers at the bottom of the post so you can check them), then we had a look at how to make code repeat itself a set number of times. One way to do this is with a for loop.

In Visual Basic you need a counter (to keep track of how often the loop has gone round). This can then be used to do clever things, like change a particular element of an array. For example in the code below on the tenth go around of the loop, what the user types in will go into place 10 of the array (if you are starting from 1):

 

 

For counter := 1 to 15

 

name(counter) = InputBox(“Please type in another name”)

 

Next

If you still don’t get it, re-read the powerpoint below:

for-loop.jpg

 

And these are the answers to the quick questions:

constructs-quick-qus-with-answers.jpg

Maintenance

November 7, 2007

If everything went to plan today (without me) then you should have learned about the three different types of maintenance that can occur after a program has been released.

These are:

Perfective – adding new features to improve the software (e.g. Sims updates!)

Corrective – fixing problems in the software that should have been taken care of during development!

Adaptive – altering the software to work on new computer systems or in new environments

All of these occur after the software has been released.

Powerpoint from lesson:

maintenance.jpg