Programming Concept
Programming Concept
PROGRAMMING
CONCEPT
By
Mr. Hassan
Variable and Constant
Varaible: a programming memory data location that stores that can change
name. Hassan
(variale) (data vaue)
Contant: a programming memory data location that stores that can not change , constant is very useful in
programming and if want the value to change you only need to change it where it was first declared.
DATA TYPES
STRING: Is a name given to a series of character or symbols
e.g.
name. “Hassan”
CHARACTER or CHAR represent a single character stored in the computer memory. It is more efficient
to store a single character in a character data byte because a string can have a minimum of four byte
allocated for that data type, so a single string data type can be stored in that four bytes but you only
need a byte to store a CHAR.
DATA TYPES contd.
BOOLEAN: Is a data type that holds only two values.
e.g.
true/false, yes/no
BASIC PRINCIPLE OF
PROGRAMMING
KEY TERMS
Algorithm:- Is a set of instruction to solve a problem
Sequence:– Instruction that occur one after the other in a logical order
Excuted:- A program that is run
Selectection:- makin a choice or decision in a program
Iteration :- repeating instruction in a program
Condition:- a state in the program that will be met or not be met.
BASIC PRINCIPLE OF
PROGRAMMING contd:
Sequence:– occurs when algorithm are written one after the other in a
logical order.
Input first number
Store the first number
Input second number
Store second number
Add first number to second number
Output result
Stop the program
age USERINPUT
if age is > 18 THEN
PRINT “you are an adult”
ELSE
PRINT “you are not an adult”
BASIC PRINCIPLE OF
PROGRAMMING contd:
Iteration :- repeating instruction in a program
FOR LOOP
For 5 loops
PRINT “Happy”
ENDFOR
BASIC PRINCIPLE OF
PROGRAMMING contd:
Condition:- a state in the program that will be met or not be met.
CONDITION LOOP :- repeats a set of instruction until a condition is met
Me “Happy”
REPEAT:
PRINT “ Me“
UNTIL Me = ”Sad“
This will keep printing Happy until the variable becomes sad.
BASIC PRINCIPLE OF
PROGRAMMING contd:
Totalling:- useful for running total in a program.
score = 0
score = score + 2
BASIC PRINCIPLE OF
PROGRAMMING contd:
Counting:- useful for counting the number of times something occurs in
a program.
count = 0
count = score + 1
USING PREDEFINED ROUTINES
KEY TERMS:-
Predefined function:- Is a pre-programmed set of instruction that return a value.
Library:- a store of program instruction that can be imported into a program
Predefined procedure:- a pre-programmed set of instruction that do not return a
value
USING ARRAY
KEY TERMS:-
Array:- Is a store of data value that are related and of the same data types.
Element :- an individual data located in an array.
Highscore [83,75,82,98,80,87,97, 89,96,95]
The output
PRINT Highscore [9] will be tenth,
PRINT Highscore [3] fourth etc
PRINT Highscore [8] element in
PRINT Highscore [0] the array
The above statement means that the program should write and store 90
into index 1 or should overwrite whatever data in index 1.
BRAIN CHECK:-
Write a program to overwrite the first element in an array
We can also use a variable to read data from and array as shown below, if
count is replace with 3, then the fourth element will be displayed
BRAIN CHECK:-
The program statement below is used for
FOR count 0 TO 3
PRINT Highscores (count)
NEXT count