Programming – Week 1

13 Jun

Global & Local Variables

This week in my Higher Computing class I learned a massive amount of new programming elements.  Although the work is a great deal harder and writing code has become more complex I still feel that I understand everything well and I am getting through work at a good pace.

Throughout the week I created a number of programs from which I have learned a lot of new things.  The first being a ‘Film Rating’ program that introduced Global Variables into my code.  A Global Variable is a variable, e.g. an integer, that is recognised and used throughout every piece of code in the program.  A Local Variable however, is a variable that is only used in the one specific piece of code in which it was declared.

Global Variable In Use

In this case (Film Rating) the variable of the number of votes and the total rating of the film had to be declared as Global since these values must be accumulated in order to work out the average rating, which is the purposeof the program.

Variable Scope & Types

The types of variables that I am currently using include, ‘String’, ‘Integer’ and ‘Double’. A ‘String’ variable can contain information in text and numerical format whereas an ‘Integer’ variable can only contain numbers without a decimal place.  A ‘Double’ variable can store numbers with a decimal place which allows for more accurate results in calculations.

The ‘Scope’ of a variable is determined by the accessibility of the variable throughout the program.  For example, a Global variable is accessed in every scope.

Random Number Generation

Another program which I created is called ‘Random Guesser’.

This is a program in which the user clicks ‘Start’ and a random number is generated.  The user must then click on a number button and guess the correct number.

The generation of the random number required the use of the RND function in REALbasic.  This function generates a random number within the parameters specified by the code writer.

Advertisements

One Response to “Programming – Week 1”

  1. Mr Cunningham June 14, 2011 at 11:49 am #

    Excellent first post Calum. Great reflection on the past week’s work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: