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.

Sunday, 6 October 2013

VB Lesson 6: The For... Next Loop

So this is the final lesson that I did in bulk, so after this hopefully every post will be a lot more together and coherent. Nothing will overlap in a fuzzy way, it'll only overlap when I want it to. Not to mention I'll be on the same page as everyone else. Plus, my head won't hurt anymore, like it did after three solid hours of cramming the first 6 lessons of Computing in.

Visual Basic Lesson 6:

So we have covered two types of loops, let's move onto a third. This is another iteration statement and it does repeat a selected set of instructions, the difference is that it repeats for a set number of times. It is unlike the repeat loop, which repeats as many times until a condition is met, as it just repeats for the number of times you specify.

Here is an example of a program which will take any number and give you the first 12 from its times table, I made it out of a program which was originally just for the 12 times table. This is also an example of program which displays the output in a text box rather than a MsgBox:


The reason it is an example of a loop is because it does the calculation specified 12 times before it stops.

Here is a code which displays another use of the for next loop:


This coding shows that the loop can be used to count down from one to value until it reaches another specified value, but also shows off the fact that you don't have to go down in intervals of one. You can choose to go down (or up) in steps of however many you like (in this case it's steps of minus 5 and is therefore counting down) you're not particularly limited.

A final example of a for next loop code is this:



What this code shows is similar to the times table program, except this is specifically for one thing (displaying the square numbers from 1 to 100 in a text box.) not for any times table. It is once again showing off the fact that this loop is for a specified number of times, before it stops and moves on.

And that is the end of another iteration statement, sorry it is not too great, I have written 5 (technically 6) of these in a row and so I have lost creativity and will. Hopefully future ones will be a lot better!!

See you soon Lalin :D.

VB Lesson 5: Iteration (Do Loops)

So after the confusion of lesson 4 it is nice to have something which I sort of understand. This was a topic which wasn't covered by legendary Lalin, it was covered by the lovely Clive instead. So I came under a different teaching style here. However, hopefully my coverage will be just a thorough though. So, onto the lesson :D.

Visual Basic Lesson 5:

Here is another type of statement which we haven't come across before, iteration statements, sounds fancy but really isn't hard to figure out. Essentially they are statements which make instructions, coded by you, to repeat or loop many times. There are different types of loops, repeat loops, while loops and for next loops, however we shall only be looking at repeat and while loops today, for next loops are covered in lesson 6.

Let's start with the repeat loop. Basically, what a repeat loop does is loop a section of code until the condition set becomes true. There is no set number of times, it just continues until the condition is met. It is useful for data validation.

An example for data validation would be:

Dim age As Integer

Do
age = InputBox("How old are you?")
If age >= 100 Then
MsgBox("Must be less than 100!")
End if
Loop until age<100

This code ensures that valid data must be entered, before moving on from that section of code. The code would continue to loop until an age below 100 is entered and the program would then move onto the next part of the code.

Another example for the use of a repeat loop would be:

Dim total as Integer = 0
count = 0
Dim marks As Integer

Do
Number = InputBox("Enter marks")
total = total + marks
count = count + 1
Loop until count = 5

MsgBox("Total" & total)

This code ensure that this section of code will loop 5 times, before moving onto the next section of code. It is useful for entering multiple marks and gaining a total. However, similar coding can mean that you can get several pieces of data entered without having to repeat the whole program.

A final example of a repeat loop is:

Dim total As Integer = 0

Do
Number = InputBox("Enter number")
total = total + number
Loop until number = 0

What would happen in this program would be the InputBox continues to come up, until the user enters 0. That means that several pieces of data are able to be added and when the user has finished, they simply enter 0 and the program stops looping. 0 in this case is a rogue value. Why? Because 0 isn't real data that the user wants to enter, it's just a value which has been assigned to the code in order to make the loop stop.

This now brings us to the while loop. So, the while loop continues using a particular piece of coding whilst the condition is true. As soon as the condition becomes false, the loop stops and the program moves on.

For example:

Dim reply as string

reply = InputBox ("Run program?")
Do while reply = "Yes"
reply = InputBox ("Another go?")
Loop

This program means that if the user types "yes" the program runs, but if the user types "no" then the program doesn't even run once. This cannot be done with a repeat loop.

And that's pretty much repeat loops and while loops, there's not much to them. They're both exceptionally useful when a piece of coding needs to be used more than once and they ensure self-documenting code as it they mean that the code is kept neat and as concise as possible, there's no need to keep copy and pasting!

So goodbye until next time, where for next loops will be tackled... Yay :D.






VB Lesson 4: I'm Not Really Sure.

Hey, that rhymed! How clever of me. Well, that's just the only thing I've done cleverly here, because it appears I'm missing the lesson 4 handout as well and it looks like I don't have any notes from Lalin either. Therefore, I'm not entirely sure about lesson 4 and the content which goes in it, due to doing all the lessons mashed together. I'm hoping you can help here Lalin?

Will hopefully update this and fill it with consolidation, once I can see what exactly I'm missing here.
Well, onto lesson 5 anyway.

VB Lesson 3: If and Select Statements

Yo, lesson 3 of VB now. Exciting times. The examples used in this post may cross over with lesson 2, because, as explained earlier, I crammed most of the lessons I'd missed into one whole session and so there's sort of a blurred line when it comes to which program goes with which lesson. But that doesn't matter, as each lesson is supposed to build on the knowledge from the last, so really it just shows the ideals of teaching and learning at their very best.

Visual Basic Lesson 3:

Once again we didn't really go through the worksheet for this one, but that wasn't due to not having it, it was just because it is easier to understand this lesson through practical examples.

Sometimes, when a user is inputting data into a program, they won't always give information which is applicable to a particular piece of code and so you need a statement which can differentiate between the useful data and the useless data. For example, if a program is designed to check whether a person can drive in the UK, it would be pointless if the program always stated "You can legally start driving" as it's Output, despite a user giving their age as one which is under 17. Therefore you need a statement which can choose between two or more bits of coding and give the correct Output. This is where selection statements come into play.

Selection statements are for situations when a condition has to be (be true) in order for the program to execute a selected bit of code.

For example:
Dim age As Integer

age = InputBox("How old are you?")

If age < 17 Then
MsgBox"Too young"
ELSE
MsgBox"You can start driving!"
End if

Things to note here:
 You must always start and end an "If statement"
You must give a condition such as "if age < 17" and once the condition is finished add "then" or "else" etc...

For this lesson Lalin set me some examples of his own, which tied in with lesson 2.

For example there is the relational operator program with an If statement:

There is the circle area program:

And the surface area of a washer program:

These programs all encompass at least one element of the past three lessons. 

Now I believe I have covered everything in lesson 3, if not I'm sure it'll be covered in lesson 4, because, as I have previous stated many times, I did do a bunch of the lessons all in one go and so some of this may be in a muddle.

Until next time :).

VB Lesson 2: Performing Calculations

Hello again, it has not been long since my last post. Why? Is it because I love Computing so much that I can't keep myself away (perhaps this is the case) or is it because I just condensed most of my previous lessons into one solid three hours of Computing? Whilst the former seems to be true, I must state that the reason for this blog post being so close is due to the latter. So let's get down to business.

Visual Basic Lesson 2:

So when I covered the basics of this lesson I did not have the worksheet and so most of it was me just designing different programs based on the questions Lalin set for me. So I will go through the stuff learnt with Lalin through the set questions and then I will attempt to cover what I have learned through the sheet.

Essentially there is no easier way to learn how to program than by doing! But before you do, you must understand the steps which must be undertaken when trying to write out calculations. These are the steps:

1. Declare variables. Using suitable data types.
e.g Dim total As Single = 0
Dim marks1 As Integer
Dim marks2 As Integer
2. Get input from user. Using InputBox usually.
e.g. marks1 = InputBox("How many marks were scored in first test?")
marks2 = InputBox("How many marks were scored in second test?")
3. Calculate values. 
e.g. total = marks1 + marks2
4. Display end values. Usually with a MsgBox or a Text Box.
e.g. MsgBox("Total: " & total)

If you follow the steps in green that's half the battle and you shouldn't go wrong.

Some things to note:
When doing calculations your total should be set to whichever number you want it to start at, which for the most part should be 0.

For the rest of that lesson I just tried out some of Lalin's questions. 

My first program was used to add numbers together. The adding program:

The next program was the triangle area program:

There were more programs which I tried out, however they were a mix of lesson 2 and 3 and so I will cover them in my next post.

This was pretty much all I covered for lesson 2 on it's own. However there is more to understand when it comes to calculations in VB.

Whilst performing calculations you obviously use Maths, therefore in order to use Maths, you must have symbols which you can use in your code in order to perform Mathematical functions. These symbols are known as Arithmetic Operators or Relational Operators.

The Arithmetic Operators are:
+ add
- subtract
* multiply
/ divide
^ to the power of

The Relational Operators are:
= equals (only in calculations)
<> not equals
> greater than 
>= greater than or equal to
< less than
<= less than or equal to

Such as with Maths there is obviously an order in which the program will use operators. For example in standard Maths, BODMAS or BIDMAS applies. It is the same with programming. Precedence is the order in which operators are applied. The precedence in programming is:

Brackets ^ */ +- Not And Or = <> > >= < <=
(If they are the same colour it does not matter which is worked out first.)

It is essentially the same as BOD/BIDMAS, but with a few extra terms.
e.g. the 'Not', the 'And' and the 'Or'.

This is because there is another type of operator. The logical operators, which are not found in Maths. There are only three to know, but they are essential.

Logical Operators:
And - Both must be true.
Or - Either or both must be true.
Not - Not true.

I will use an examples of all the operators in future lessons.

I hope that has covered lesson 2 in enough detail. See you next time.


VB Lesson 1: Introduction

Hola, so this is my first blog for AS Computing. No one is going to read it, except Lalin (hi there) so I don't expect it to be particularly eloquent. I'm basically just going to document my progress throughout my AS course for Computing.

The first few posts are all going to come in one go, as I just started proper Computing lessons last Tuesday, so I had to learn all the beginning lessons in pretty much one go. I followed the classwork in the first lesson and then on Wednesday I did three hours in the Computing workshop.

Okay, so onto lesson one. Essentially this was just a run down of key terms and the basics of programming.

Visual Basic Lesson 1:

So, I guess I should start with variables. But before that you need to understand RAM. RAM stands for Random Access Memory. It is a temporary form of memory, which has different sections or locations in which data can be stored. ROM is Read Only Memory and that is a more permanent form of memory.

A variable is a location in RAM memory where data is stored and ever-changing, it is usually given a name. The name which you give a variable is called an identifier which is probably because it is how you identify which variable is which, but that's just a shot in the dark for me.

With identifiers you need to make sure that your identifiers are self-documenting, which basically means that they need to have sensible names, which you will understand when you or another programmer comes to visit your program at a later date.

When programming, you always have to declare the variables and that is no exception when using Visual Basic (hereafter known as VB). A simple "equation" for a variable declaration would be:

Dim (Identifier) As (Data Type)
e.g Dim marks1 As Integer

But wait! What does "dim" mean? And what is a data type?! Well dim is short for dimension and it is a way in which to define a variable.

And data types? Well, different data types are used for different types of data.

Common data type examples would be:

Integer - used to store whole numbers. Data can be used in calculations.
Single - used to hold decimal numbers. Data can be used in calculations.
String - used to hold letters and numbers. Data cannot be used in calculations.
Date - used to hold date and time information.
Char - used to store one single letter. VB does NOT used this data type.
Booelean - can only hold one of two values. e.g. Yes and no or true and false.

Also when coding there are other components. For example there are statements, two key types of statements are assignment statements and selection statements (which will be covered in another lesson) these statements allow you to use the variables you have declared in your code in order to carry out a particular function.

An example of an assignment statement would be:

name = InputBox("What is your name?")

Remember, your code should be self-documenting, as well as your identifiers. Therefore your programs should be well-structured, with comments and they should be indented and clearly laid out. No goto statements should be used!

After I got all that round my head it was time to start programming.
I did  a basic program, which I call the "Birthday Program", it was fairly simple and easy and I was quickly able to add bits to it.


And that's essentially the end of lesson 1. Hope I haven't forgotten anything, but as I said, several lessons were squashed into one.

See ya next time :).