Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Programming Concept

Uploaded by

Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Programming Concept

Uploaded by

Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

COMPUTER SCIENCE

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”

NUMBERS: This represent numerical values or figures in programming. They can


be subdivided into:
INTEGER which include whole numbers like: 1,2,3,4,5,60,90,

REAL NUMBER which include numerals with decimal places


like: 3.142. they are also known as FLOAT.

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

Selectection:- makin a choice or decision in a program


BASIC PRINCIPLE OF
PROGRAMMING contd:
Selectection:- makin a choice or decision in a 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 name of The data


the variable value stored
that stores in the array
the array
CREATING AN ARRAY
STEPS:-
 Give the variable that will store the array a name to identify the array a
 Set the number of element the array will hold, this is called specifying the
dimension
 Define the type of data the array will hold, this is called specifying data type.

Highscore integer [10]


READING TO AND WRITING
FROM AN ARRAY
Programs can be ask to read certain element in an array, this is done by asking the
program to output data in a particular location on the array. The program will read
data in that particular location and output it for us to see-

PRINT Highscore [10]


PRINT Highscore [3]
PRINT Highscore [8]
PRINT Highscore [0]
READING TO AND WRITING
FROM AN ARRAY
Programs can be ask to read certain element in an array, this is done by asking the
program to output data in a particular location on the array. The program will read
data in that particular location and output it for us to see-

The output
PRINT Highscore [9] will be tenth,
PRINT Highscore [3] fourth etc
PRINT Highscore [8] element in
PRINT Highscore [0] the array

Read outputting data from an array so we can see it.


Write inputting data into an array to store it.
Highscore (1) [90]

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

PRINT Highscore (count)

BRAIN CHECK:-
The program statement below is used for

Highscore (count) [98]


READING AND WRITING INTO AN
ARRAY USING LOOPS
A FOR …….. TO ……… NEXT loop will read values from and write values to for a
number of times stated in the loop

FOR count 0 TO 3
PRINT Highscores (count)
NEXT count

You might also like