Introduction To Programming Techniques

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Course Name : Programming Techniques

Course # : ITT103
Lecturer :
Lecture #1 : Introduction to Programming Techniques
Date :

INTRODUCTION TO PROGRAMMING TECHNIQUES

The System Development Life Cycle is comprised of 6 steps, namely:

1. Analyze the current system


2. Define the new system requirements
3. Design the new system
4. Develop the new system
5. Implement the new system
6. Evaluate the new system

Program Development Cycle (PDC)

- The fourth step of the SDLC (Development of the new system) is comprised of a series of well-defined
steps called the Program Development Cycle.
- A programmer carries out the steps in the PDC.

What is a Program?

- A program is an organized lists of instructions that, when executed, causes the computer to behave in
a predetermined manner. Without programs, computers are useless.

What is Programming?

- Programming is instructing a computer to do something for you with the help of a programming
language

The Functions on the computer (I.P.O.S.)

The only instructions that we can give a CPU – the brain of every PC – involve one or more of the
following functions of the PC: -

Input (I): The PC accepts data from the surrounding world (mostly from a user)
Process (P): The PC makes important operations and decisions on given data to complete a task
Output (O): The PC sends data to the outside world usually via a monitor
Storage (O): The PC’s way of temporarily or permanently holding needed data for processing

Page 1 of 9
TYPES OF PROGRAMMING LANGUAGES

There are five distinct programming language generations, or levels:

1. Machine language
2. Assembly language
3. High level (Procedural language)
4. Fourth generation( Nonprocedural language)
5. Fifth generation (natural language)

Machine language

– First-generation language
– Source code is expressed using binary or hexadecimal numbers
– The only programming language a computer understands directly
– Executes quickly because no conversion is needed but hard for humans to understand

Assembly language

– A low-level, second-generation language


– Source code is expressed using mnemonics (abbreviations for machine language commands)
– Easier for humans to understand than machine language but takes longer to execute because of the
conversion process

High level language

– Third-generation languages
– Considered procedural languages (more english like in structure)
– Easier to read, write, and maintain however source code has to be converted to machine language
– Programmer tells computer what to do and how to do it.

Fourth-generation language

–Nonprocedural languages
- Database oriented languages
- Report generators (database reports)
- Query languages
– SQL (structured query language)
- Programmers tell computer what to do but NOT how to do it.

Page 2 of 9
Fifth-generation language

– Fifth-generation languages
– Still being perfected
– Nonprocedural
– Use everyday language to program
– Uses concepts of artificial intelligence (neural networks, machine learning etc.) to solve problems

Identifiers

Manipulation of data is a basic feature of a computer’s abilities. This data must be present in the memory
(RAM) of the computer for operations to be done on it. The computer accesses this data via memory
addresses. Identifiers are required to keep track of these memory addresses (data containers). Identifiers
allow us humans to give these ‘data containers’ more meaningful names. This makes the task of
manipulation of data more manageable.

Memory Address Perspectives:


1997 Computer sees- AH010 D4327
We see- YEAR

“Tom” Computer sees - AH041 C4439


We see- FNAME
Random Access Memory (RAM)

Internally the computer sees a HEXIDECIMAL label representing the memory location; while we see
familiar titles / labels such as YEAR, FNAME, and AGE, which we are able to put into some context.

Variables

A variable represents a memory location that stores an assigned value. Each variable is associated with a data
type and stores values. Variables can change their value during program execution, but not their structure and
not their data type. A variable is characterized by three elements:

1. Name: it must be unique and inherent to the programming contest, mainly for the readability of the
program; ·        
2. Type: it indicates if the variable is an integer, real, character, etc. Each type allocates different space
in central memory; ·

Page 3 of 9
3. Content: it is the value assigned to the variable in a step of the program execution.
Furthermore, the most important operators are comparison and assignment: ·
Assignment. The symbol = (single equal) assigns to a variable its value. ·        
Test for equality. The symbol = = (double equals) compares the values of two variables (an
expression with final value true or false). For example, if we assign 4 to the variable num and 5 to
the variable val we shall write:
num=4;
val =5;

For example, if we compare num and val , write: num==val;


For example, if we sum two variables (num and val), and we want to store the result of this operation
in the variable sum we should write:  sum = num + val;

In some particular cases, we are interested in the iterative sum of a set of value for an algorithm. For
example, if we want to know the sum of some integer values, in this case, we can use an intermediate
variable and we should write:

final_sum = final_sum + new_value;

In programming we can add the new_value to the content of the variable final_sum and store the
result in the same variable final_sum. Reading the formula from left to right

Constants

Constants, are elements that cannot change their value during program execution. If we want to assign an
integer value (4) to a constant GCT we write: GCT = 4

Literal (Literal Constant)

These are values taken at face value


For example, what follows is the utilization of all Identifier Types :

CIRC = 2 * PI * R

CIRC is a variable

2 is a literal constant

PI is a constant

R is a variable

Basic Data Types

Real / Numeric - values from the set of real numbers

Page 4 of 9
(e.g. -12.348, 0, 199.0, 1654.984034)

Integers - values from the set of whole numbers

(e.g. -3075, -2, 0, 23, 94754)

Character - value, from a set of symbols, which may be represented

on the computer (ASCII set of characters) enclosed within

characters) enclosed within Single Quotes. (e.g. ‘E’, ‘%’)

String - a combination of one or more characters enclosed in Double Quotes.

(e.g. “123”, “Lisa”)

Boolean - True or false

Operators, Operands, Expressions and statements

Operators - the symbols used in processing/calculation operations

Arithmetic Operators:

+ Addition or unary plus

- Subtraction or unary minus

* multiplication

/division

%modulo division

Relational Operators

>greater than 25 > 16 is TRUE

< less than 40 < 32 is FALSE

>= greater than or equal 55 >= 55 is TRUE

Page 5 of 9
<= less than or equal 33 <= 44 is TRUE

== equal to 100 == 100 is TRUE ; 7 == 8 is FALSE

!= not equal to 7 !=8 is TRUE

Logical Operators

&& AND

| | OR

! NOT

The Logical Operators are used in Compound Conditions.

Example: IF SalesAmt > 10000 AND SalesPerson = “Sue” THEN

Bonus = AveSales * 2

ELSE

Bonus = AveSales * 1.5

ENDIF

Truth Tables illustrate the outcome of combining conditions using the logical operators stated.

That is, let’s say that X and Y are conditions, which may be either True or False

Logical AND

A logical AND is True if and only if both X and Y are True

X Y X .AND. Y

F F F

F T F

T F F

T T T

Page 6 of 9
Logical OR (inclusive)

A logical OR is True if any of both X and Y are True, including both being True.

X Y X .OR. Y

F F F

F T T

T F T

T T T

Logical NOT

A logical NOT negates or reverses a condition such that True becomes False, and False becomes True.

X NOT. X

F T

T F

Operands - Can be a variable, a constant, or a literal constant.

- What the operator operates on.

Expressions - Consists of operators and operands or an identifier by itself

- it must evaluate to a Single Value

- arithmetic expressions can be assigned ( or =) to a variable

Statement - a complete instruction

- by itself it accomplishes a task

- can be derived from expressions

Page 7 of 9
Evaluating expressions

When processing a mathematical expression the computer evaluates by going from left to right by default.
However this default operation is impacted by precedence rules which indicate what operations ought to
occur before others. The BOMDAS acronym will assist in remembering the order.

BOMDAS

o • B – brackets first
o • O – Orders (powers, square roots etc)
o • MD – multiplication & division
o • AS – addition and subtraction
NB: remember processing goes from left to right by default

Logical - evaluated to either True [T] or False [F]

Example:-

Expressions evaluated using BOMDAS rules

o • 3 + 6 x 2 = 3 + 12 = 15
o • (3 + 6) x 2 = 9 x 2 = 18
o • 12 / 6 x 3 / 2 = 2 x 3 / 2 = 6 /2 = 3

Output information

A program will output data to the user. You can output a message using the following command:

Write “Your message”

(OR)

Print “Your message”

Example:-

Write “This is a calculator program” //This will display the message on computer screen

Page 8 of 9
Write “The total is “,sum //This will display the message “The total is” and the value
stored in variable sum

Write “The first number is “,num1,” and the second number is “,num2 //This will display the value of
num1 and num2 with its
messages.

Input information

A program needs input from the user. The data inputted into the program is stored in the variables .You
can input data into a program using the following command:

Read variablename1,variablename2,…….

(OR)

Input variablename1,variablename2,………….

Example:-

Read num1, num2 //This will input data into the variables named num1,num2

Page 9 of 9

You might also like