Sunday, 8 December 2013

Algorithms Research - Flowcharts & Structured English



Lalin, you WILL have the other blog posts done, but I cannot do them for Monday. I gave up two frees on Friday to get my coursework on track, which meant that I didn't do the work set for Friday's History lesson (she set work despite not being there) and obviously I had work on Saturday. Today has been the only day I could do work and I had the History work from Friday due Tuesday (but it's an hour and half's work), Law and English coursework due in for Monday. Obviously I spent most of today doing my English, which still isn't finished. So I'm doing this homework and on Wednesday, after the photoshoot, I shall do the rest of my blogs!

Algorithm Research - Flowcharts & Structured English

An algorithm is defined as a set of finite instructions written to solve a specific task, which is generic and programming-language independent

This is research, so all the other stuff will appear in a later blog :).

Flowcharts -
The flowcharts have basic symbols, which are recognised by most, but not all, programmers.

Examples of symbols which can be used in flowcharts:
 -Indicates the start or end of a program.
- Is used for decision making and branching.
 - Indicates any inputs and outputs.
 - This is the symbol for the connector, which joins two parts of a program together.
 - Indicates a process or instruction.
 - For any commentselaborations or definitions.

Although these are the main symbols, they are not the only symbols used, there are others which can be implicated.

A few things that should be noted when creating flowcharts:


  • Flowcharts should be clear and easy to follow. 
  • There should be no ambiguous steps. 
  • The direction of flow should remain consistent .
  • Only one flow line should come from a process symbol.
  • Only one flow line should enter a decision symbol, but several can leave it.
  • Flowcharts should have a start and a finish.
  • Testing flowcharts with test data is a good idea to ensure that the algorithm is as clear and uncomplicated as possible.
An example flowchart would be:
This particular flowchart is for finding out the average of two numbers.

Structured English -

This type of algorithm is similar to that of pseudo-code. However, most of the steps have few symbols or terms which relate to programming whatsoever.

An example algorithm would be:

Begin
Read name
   If name equals "Harry" Then
      Write "Why don't you marry Pippa?"
   Else 
      Write "Are you royal enough?"
   End if
End

To show the difference between Structured English and Pseudo-code here are is an example:
Structured English:
Multiply Number1 by Number2 to get product

Pseudo-code:
Product <-- Number1 * Number2


And that's pretty much all there is to it.
Will probably come back and edit this over Christmas anyway, because it's awful. Sorry Lalin :(.

Wednesday, 13 November 2013

VB Lesson 10: Standard Subroutines & Functions

I genuinely have no excuse Lalin, except maybe that I helped you last week with both open evenings ;), but seriously, I've just been lazy. But I'm writing them up now, so yay :).

Visual Basic Lesson 10:

So onto subroutines and functions... Wooh! Subroutines and functions are really useful pieces of coding, but before we talk about writing our own, we need to look at the standard ones which are offered by VB. On top of that we also need to define what exactly a subroutine is and what exactly a function is.

Firstly let us look at functions. Functions, like variables, still have to have a name, if they didn't then it would be impossible to distinguish between them. This all comes down to self-documenting code when writing your own, because a function name tells the programmer what the function does - to a certain extent anyway. Functions also have parameters. This sounds fairly fancy, but essentially the parameters are variables within brackets.

A standard example of a parameter:

(Variable)
There will be a more practical example of a parameter when it comes to an actual example function.

Another key feature of a function is that it must always return a value! Every single time.  So because it has to return a value you must always have something on the left with an equals sign, with something else on the right.

For example:

Current = Now()

A further example of a function is:

Dim current As Date

Current = Now()
M = Month(Current)
Print Hour(Current), Minute (Current)

Two useful built in functions are the midfunction and the substring function. 

Okay, now onto subroutines. Like functions, subroutines have to have a name and they can have parameters. But the difference is that subroutines may or may not return a value and the returned value doesn't have to be used as an assignment.

Here is an example of a program designed in class:


This program is designed to use the substring function in order to reverse a name which the user has inputted, in order to display it backwards.

And that's essentially built in subroutines and functions. Next time we will look at writing  our own subroutines.

Bye!

Sunday, 3 November 2013

Test Answer Rewrites!

This isn't a blog explaining anything. It is just the rewrites of the answers from the test which I got wrong.

Question 6. Validation and verification check are carried out on employee data being entered into a computer system.
(a) Using an example of acceptable data describe a suitable validation check for each of the items of data below. In each case give an example of invalid data that would be detected by the check.
A different validation check must be used in each case.                                                [4]
         Employee salary.

A suitable validation check for an employee salary would be a type check, which would ensure the correct data type, in this case real data, is being used for the data stored. For example "£20,000" would be accepted, but "twenty thousand pounds" would be rejected as it is the text data type, not real data.

Question 9. (a) Below is an algorithm to produce the multiplication table for a given number.

Algorithm Multiplication Table.
Multiplier is integer                       {input by user}
Product is integer                         {used to store current answer}i is integer                                    {loop control variable}startmainprog    input Multiplier        for i = 1 to 12                  set Product = i* Multiplier                  output Product    end forend mainprog             
 (i) Draw circle on the above algorithm to clearly indicate an example of annotation.[1]

for i = 1 to 12
                  set Product = i* Multiplier
                  output Product
    end for    

(b) Below is a segment of an algorithm that determines if an item is present in a sorted array.

input SearchValueset Found = False        {initialise variables}set i = 0set SizeArray = 9
repeat
         set i = i + 1         if SearchVariable = SearchArray[i] then Found = True
until (Found = True) OR (i = SizeArray) OR (SearchValue < SearchArray[i])

 Complete the table below to show how each variable changes when the algorithm is performed on the test data given.
Search Value = 41 

i SearchArray[i] Found
1        14           False
2        19           False
3        23           False
4        28           False
5        31           False
6        39           False
7        43           False
          47           

Question 12. (a) State what the output will be for a customer who has bought:

                          (iii) twenty five bottles of olive oil of total value 45                                    [1]

Give free bottle of Greek olive oil.

Question 13. Below is an algorithm intended to calculate the area of a circle

Algorithm CalculateArea

Pi = 3.142

Area is integer Area is Real

Radius is real

Startmainprog

       output "Type in the radius"

       input Radius

       Area = Pi * Radius * Radius

       Output "The area is" Area

endmainprog

(b) The line "Area is integer" may cause a problem. Describe the problem that this line may cause and amend the algorithm to remove the problem.

The problem that this line may cause is that an area may not be an integer or whole number, it might be a decimal number, therefore a piece of real data.


You may cross out any words of lines in the algorithm and write your own words or lines. There is no need to completely rewrite the algorithm.

Wednesday, 23 October 2013

VB Lesson 11

VB Lesson 9: Two Dimensional Arrays

Hello again :D. I know I'm a little late with this, life has been crazy busy at the moment so I do apologise that it hasn't been done sooner. Hopefully I'll be back on track after this. Still expecting you to watch MiC Lalin, it has to be done. You'd enjoy it, you're that type of person.

Visual Basic Lesson 9:

So, we have gone over one dimensional arrays, which means we are ready to advance onto two dimensional arrays... Exciting right? Obviously, because we have already explored arrays this will build upon the previous lesson more than most.

Once again two dimensional arrays are a type of data structure. You still have to declare variables and all the normal stuff like that. But instead of just having a row of code, you can have rows and columns. That is the essential difference between two dimensional arrays and one dimensional arrays. Otherwise it still stores a collection of the same data type.  Two dimensional arrays also have indexes, there are row indexes and column indexes and these are assigned to each array element, as usual. Once again, the elements are initialised to zero until the user inputs data.

The example of a variable declaration for a two dimensional array is:

Dim table(3, 10) As Integer

You specify how much data you are going to store, so how many rows of data and how many columns. Similar to how you would create a table in Microsoft Word.

Once again, loops go well with these data structures; however, generally you use nested For Next Loops with two dimensional arrays.

For example:

For i = 1 to 3
   For j = 1 to 10
        Table(i, j) = 55
   Next j
Next i

The inner loop has to be completed before the outer loop can move on. For example, j needs to go through numbers 1, 2, 3, 4 etc... Before i can equal 2. This is true for all nested loops. This particular set of For Next loops means that for each "turn" the inner loop counts through each element in the row, once it has reached 10, the program moves to the next row. Each element in this program is set to 55.

An example program created in class is:


This program uses a nested For Next loop with a two dimensional array in order to get 25 different pieces of data and create an average for them.

That is essentially two dimensional arrays. See ya next time!

Monday, 14 October 2013

VB Lesson 8: One Dimensional Array

Onto one dimensional arrays. This is a fairly easy idea and a particularly useful function. Although forgive me if I make any mistakes, I am exceedingly tired. I hope you're going to watch Made in Chelsea tonight Lalin, it promises to be a good start to the series ;).

Visual Basic Lesson 8:

So, here we are at arrays. There are other arrays, but we first need to learn about one dimensional arrays. Essentially a one dimensional array is a data structure that can be used to store a collection of data of the same data type. Of the same data type? Does that mean you cannot store string and integer together? Well, yes it does when it comes to one dimensional arrays, if you want to store a collection of different data types, you have to use a record.

It's not particularly complicated and there's nothing special. The way to use a one dimensional array is the same as any other function. Essentially you use a variable declaration as usual, but you have to specify the number of elements. For example:

Dim list(10) As Integer

As you can see, you are still giving the variable an identifier and you're still specifying the data type, but you're also telling it just how much data you're going to store.

Along with elements you also have indexes. The indexes are the numbers given to each array element. Once you have declared the data each element is initialised to zero and this only changes once the data has been inputted by a user. 

One dimensional arrays generally go hand it hand with For Next loops. This is so that you don't have to create several lines of the same code for each element in an array. For example:

Dim list(5) As Integer

list(1) = InputBox("Enter a value")
list(2) = InputBox("Enter a value")
etc...

Where as a For Next loop prevents this untidy time wasting practice:

Dim list(5) As Integer
Dim x As Integer

For x = 1 to 5
List(x) = InputBox("Enter a value")
Next x

This code looks neat and makes sense, it allows the you to collect the data you need in a simple piece of coding.

Here are some more example programs created in class:

The above program is a program which takes 10 pieces of data inputted by the user and then displays them in a MsgBox in reverse order.

Another example of the program being used to a For Next loop:

This is a piece of coding which takes the numbers that the user inputs and it then squares them.

And another:


This program shows the use of a For Next loop with an array to shift the inputted data one element to the left.

And final example:

This program shows the real skill of the array data structure. It shows two arrays having their data inputted separately, but then being added together to create the data for a third array.

And this really concludes arrays. Sorry it wasn't really great, but I am feeling exceedingly tired today, I might come back to update this.
Until next time ;).

Tuesday, 8 October 2013

VB Lesson 7: Extracting a specified number of characters from a string

Wow that title is a mouthful, but then again this function is quite a toughie, so maybe that's why. The initial concept is easy, but putting it into a program and making it function? Well that is a different ballgame! But it is also quite magical as well.

Visual Basic Lesson 7:

What's next then? The Mid function of course! It's an essential function which will form the basis for the programming coursework. Why is it the Mid function? Well, because it returns a value back. It's a very useful function, but before you can start programming you need to understand this formula:

Mid(string, start, length)
e.g. Dim myString As String
Dim extractedChars as String

myString = InputBox("Enter suitable string.")

extractedChars = Mid(myString, 2, 6)
In this case myString can be "Harvard", therefore the extractedChar variable will take "arvard" from the word.

The "string" in the formula is the string you wish to use the function on.
The "start" is where you'd like the Mid function to start.
The "length" is the number of characters you wish to get.

What that example essentially shows is a program which can take a section of the string and move it over into another variable, which is useful for spellchecks.

When you don't know the length of the word you are wishing to spellcheck you merely use a For Next loop and use the built in .length as shown in this example program I created during class:


The above program uses two Mid functions. One to take the letters from the actual answer "colloportus" and one to take the letters from the student answer. The 
If studentChar <> answerChar Then 
counter = counter + 1
acts as an error check. It means that the first letter of the student answer and the first letter of the actual answer are compared and if they don't match then the counter goes up. The loop ensures that each letter of the student answer is checked with the actual answer. Later on in the program there are three If Statements which determine if the spellings are minor or major errors. 

The reason the Mid function doesn't have to be typed for each letter is because x is defined as a range which uses the .length function to ensure all letters are checked, the loop runs through until each letter is checked.

And that's pretty much the Mid function. It's a lot easier to understand when you see it's application in a program, that than just reading or listening to an explanation.
Until next time :D.