What is Programming

By Danny Reed,2014-06-20 18:38
7 views 0
What is Programming

What is Programming?

    A computer program is a set of instructions for the computer to follow. When you write a program you are creating a series of steps for the computer to follow so it will perform a specific task. To these steps must be written in a computer language.

The Big Four

    There are four big things to remember when writing a program:

Order Matters

    ; The computer follows your instructions in the order that you entered

    them from top to bottom.

    ; If your instructions are in the incorrect order the computer will not

    function as expected.

Case Matters

    ; Turing is a case sensitive language. This means that it treats uppercase

    and lowercase letters differently.

    ; Turing will not recognize put and PUT as being the same word.

    ; All commands in Turing are LOWERCASE. If you type them in using

    uppercase letters the computer will not recognize the commands.

Documentation Matters

    ; Documentation may be notes that we write about our code to make it

    easier to understand.

    ; A documented program is easier to read, comprehend, and modify. ; Non-documented programs are very difficult to understand and will not

    gain you full marks in this course.

The User Matters

    ; The most important part of a program is the user. If your program is not

    user friendly people will not want to purchase or use it. ; When writing a program it is important to consider what would make it

    appealing to users and easier to use.

Planning a Program

    Before sitting down at the computer and typing your code it is important to stop and think about what your program will do. Planning your program makes it far easier to write that if you just start from scratch.

When planning a program we go back to the IPO model.


    ; List all information that needs to be entered by the user to make the

    program run


    ; List what needs to be calculated, repeated, or decided in the program ; Number these in the order that they need to be completed.


; List what needs to be output to the screen

    ; Draw out any graphics on a graphics planning sheet

    The Graphics Screen

Turing has two ways of displaying information on the screen. There is a text mode

    which displays only characters, and a graphics mode which can display both

    characters and graphics such as lines, boxes, and other shapes.

    By default, the screen is set to text mode, so if you want your program to display

    graphics you must add the following command as the first line of your program: setscreen ("graphics:vga")

    The letters "vga" stand for versatile graphics adapter. In vga mode the screen is divided

    into many small dots. The smallest item that can be displayed, one dot, is called a pixel

    (short for picture element).

    The location of any dot on the screen is defined by counting the number of pixels

    horizontally ( x axis) and vertically ( y axis) from the lower left hand corner of the

    screen. Any location can be specified as x,y.

    In Turing, maxx is a predefined identifier that automatically stores the largest number of pixels along the x axis. In vga mode maxx is equal to 640 pixels.

    In Turing, maxy is a predefined identifier that automatically stores the largest number of pixels along the y axis. In vga mode maxy is equal to 480 pixels.

    A predefined identifier, also referred to as a reserved word, is a word that has a very

    specific use in a programming language and therefore can't be used for anything else. e.g. PUT

    Programming Style

There are 2 types of computer programs:

    1. programs that work but make no sense to anyone except the person created it (and

    sometimes not even them)

    2. programs that any programmer can read and understand

    In the real world no one has much use for messy, hard to read programs, And as programs become bigger and more complex, they are almost always worked on by a number of different people. This means that over time, a number of different people will have to read parts of the program, probably make changes or modifications and leave the program in such a way that the process could be repeated over and over again. One of the ways to make sure a program makes sense is to follow a set of guidelines sometimes referred to as a programming style guide. A programming style guide

    provides a set of rules or expectations that every programmer must follow to ensure that

    all programs are clearly written, easy to understand, and easy to fix or change. The most important feature of a good programming style is to provide information about the program directly in the body of the program itself. This is done my including

    programmer comments. These comments are written in english so they are easy to understand by another programmer, but when the program is run, they are not interpreted

    as instructions for the computer. In Turing, a programmer comment is preceded by a %


    e.g. % This is a comment

    This style guide must be followed for every program you write.

    TEE Programming Style Guide

    ALL programs must include:


    The header is always written at the top of the program and must include:

    ; the program name

    ; the author’s name (you)

    ; the date the program was created

    ; any modification dates (added in to the program)

    ; description of the program

    Programmer Comments

    ; Explain each variable, constant, and array used throughout your program. Choose

    variable names that provide a good indication of what they do (e.g. use "price"

    instead of "p")

    ; Comment at the top and bottom of loops (for/end for), conditional statements (if

    then/else/end if), and all procedures to explain what is happening in the program

    and what various parts do.


    ; Make individual sections of code obvious (stand out) by using white space and by

    indenting the contents of loops and conditional statements.

    The "put" Statement

    The put statement allows you to output something to the screen. If you want to output words or text to the screen you must use quotation marks around the information you

    would like to be displayed. If you would like to output the result of a mathematical calculation to the screen, you do not use quotation marks, or the equation will appear

    instead of the result!

Here is an example:


    If you wish to output more than one thing at a time, you need to consider how you want

    to space out the objects when they print on the screen.

    Sometimes, it is desirable to allow a specific number of spaces for the output displayed to the screen. To accomplish this simply add a colon followed by a number (representing

    the number of spaces desired) to the end of the PUT statement. If the information to be displayed is a number, or the result of a calculation, a second

    colon and number may be used to indicate the number of decimal places. Note: the

    decimal point counts as a space in the output.

    In these examples the ^ (called a caret) indicates a blank space.

    the CODE the Output to the screen





    ; Text (strings) are left justified (in the example 5 extra spaces are placed after the text).

    ; Numbers are right justified (6 spaces before the calculation result)

    Continuing to print on the same line

    Adding 2 periods to the end of a put statement instructs the computer to continue printing information on the same line. This is helpful when trying to "construct" output.

    The Code:

    Screen Output:



    The colour command

We can display text in a variety of different colours. Each colour has associated with

    it a code.

1. Type in the following program and run it.

    % This program displays text in different colours.


    put "Mackenzie is GREAT !"


    put "Mackenzie is GREAT !"


    put "Mackenzie is GREAT !"


    put "Mackenzie is SUPERB!"

What does the command colourback(2) do?

Use the program color.exe (on the Q drive) to see the full variety of colors and color

    numbers of each.

Or, just type in the code below: (It will scroll off the screen.)

for count:1..100


     put count, ". Testing the colour!"


    end for

    The locatexy command

The locatexy command locates a specific pixel point (x, y) where output will start.


    locatexy (x , y)

    Here is an example:

    Drawing Commands

    One of the benefits of the Turing programming language is that it includes a number of built in graphics procedures to draw a variety of shapes.

    Rather than writing commands that draw the individual lines that when drawn together create a single shape, these built in commands can draw the entire shape in a single instruction.

    The following are some of the pre-determined graphics commands used in Touring:

     Sample Drawing a single dot

    drawdot (6,5,2) drawdot ( x, y, c ) % draws a green dot near the bottom left WHERE: corner of

    % the screen. NOTE: ONE PIXEL IS

    ; drawdot is the turing command VERY SMALL

    % AND MAY BE HARD TO SEE!! ; x,y is a single pixel location on the


    ; c is the colour of the dot

     Sample Drawing a line

    drawline ( x1, y1, x2, y2, c )


    ; drawline is the turing command ; x1, y1is the pixel location of the start of the line

    ; x2, y2 is the pixel location of the end of the line

    ; c is the colour of the line

    Drawing a box Sample

    drawbox (500,300,550,479,14) drawbox ( x1, y1, x2, y2, c ) % draws a yellow box in the upper right WHERE: corner of the screen ; drawbox is the turing command

    ; x1, y1 is the pixel location of the

    lower left corner of the box

    ; x2, y2 is the pixel location of upper

    right corner of the box

    ; c is the colour of the border

     Sample Drawing a circle or oval

    drawoval (320,240,25,40,15) drawoval ( x, y, r1, r2, c ) % draws a white oval near the middle of the WHERE: screen

     ; drawoval is the turing command ; x, y is the pixel location of the

    centre of the oval/circle drawoval (200,100,30,30,4) ; r1 is the horizontal radius (x axis) % draws a red circle in the bottom left of

    the screen ; r2 is the vertical radius (y axis)

    % Note: for circles, r1 and r2 must be the ; c is the colour of the border same!

     Sample Drawing a star

    drawstar ( x1, y1, x2, y2, c )


    ; drawstar is the turing command

    ; x1, y1is the pixel location of the lower left corner of the star

    ; x2, y2 is the pixel location of upper right corner

    of the star

    ; c is the colour of the border

Report this document

For any questions or suggestions please email