0% found this document useful (0 votes)
33 views88 pages

Chapter 1.0

This document provides an introduction to programming concepts and C programming language. It defines key terms like program, programmer, and programming language. It describes the different types of programming languages from machine language to assembly language to high-level languages. It also provides examples of C code and explains the process of compiling and executing a program. The document serves as a good starting point for learning programming fundamentals and the C language.
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)
33 views88 pages

Chapter 1.0

This document provides an introduction to programming concepts and C programming language. It defines key terms like program, programmer, and programming language. It describes the different types of programming languages from machine language to assembly language to high-level languages. It also provides examples of C code and explains the process of compiling and executing a program. The document serves as a good starting point for learning programming fundamentals and the C language.
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/ 88

DEC 20012 – PROGRAMMING

FUNDAMENTAL

Noted prepared by:


Pn. Wan Fazlini Idayu binti Wan
Fakari (013-7023854)
Chapter 1 :
INTRODUCTORY CONCEPTS
Pn. Wan Fazlini Idayu binti Wan
Fakari
1.1 Introduction To
Programming
The process of writing, testing and maintaining
the source code of the computer program

What ?

Computer Programming

How to program ?
•Requires knowledge in the application domain
•Follow the steps in software development method
Programming is a problem-solving
activity

To solve problems To ease daily process


occurred in life e.g.: transaction,
with the assistance payroll, accounting,
of computer registration, information
exchange etc.
5
1.1.1 Know the programming language
A set of symbol, word, code or
instructions which is understood by What ?
computer

Programming Language ?
Method of communication for which
computers could understand and execute Function?
the instructions written in source code.
A programming
language is
therefore a Hello! What can I
do to you?
practical way
for us (humans)
to give
instructions to
a computer.

Tell me 1 + 1 is
equal to what???
1.1.2 Background of C programming.

C History

• Derived from the BCPL language by


Martin Richards (1967).
• Ken Thompson developed a B language from BCPL
language(1970).
• Evolved into the C language by Dennis Ritchie (1970) at
Bell Telephone Laboratories Inc. (now the AT & T Bell
Laboratories).
• C language was first used on a computer Digital
Equipment Corporation PDP-11 to fully use in UNIX
1.1.2 Background of C programming.

Why use C?

• the portability of the compiler;


• the standard library concept;
• a powerful and varied repertoire of operators;
• an elegant syntax;
• ready access to the hardware when needed;
• and the ease with which applications can be optimised by
hand-coding isolated procedures
• C is often called a "Middle Level" programming language. This
is not a reflection on its lack of programming power but more
a reflection on its capability to access the system's low level
functions.
Reference: http://www.le.ac.uk/users/rjm1/cotter/page_04.htm
1.1.3 Describe the sample of C program.
1.1.3 Describe the sample of C program.
#include <stdio.h>
#include <stdlib.h>
main()
{
printf("hello, world\n");
return 0;
system (“pause”);
}

Examples of C programming
1.1.4 Explain the compile and execute programs.

• computer program run through the following steps:


Edit : Source code (type the program)

Compile : If no syntax errors  Object Code

Link : Link to library function  exe mode

Run : Output (check for any semantic errors)


1.1.4 Explain the compile and execute programs.

Reference: http://c.camden.rutgers.edu/c_resources/c_programming/
1.2 Definition and types of
programming.
1.2.1 Define the following terms:

• Programme
• Programmer
• Programming language
1.2.1 Define the following terms:

Programme:
• A set of step-by-step instructions that tells a
computer to perform a specific task and to produce
the required results.
• written by the programmer
• Produced through programming

16
1.2.1 Define the following terms:

Programme.

A computer program is a series of organized


instructions that directs a computer to perform
tasks. Without programs, computers are
useless.
1.2.1 Define the following terms:
Programmer
• A Programmer is a person who designs, writes and
test computer programs.
1.2.1 Define the following terms:

Programmer.
 Individual that composes instructions for computer systems to refer to
when performing a given action.
Define the following terms:
What is programming?
1.2.1

Programming
• Programming is a process of designing/
creating a program.
• It is a communication technique to explain the
instructions to the computer.
• Used to produce the program.

20
1.2.1 Define the following terms:

Programming Language.
a set of conventions in which instructions for the
machine are written.
A high-level language used to write computer
programs, as COBOL or BASIC, or, sometimes, an
assembly language.
An artificial language used to write instructions
that can be translated into machine language and
then executed by a computer.
1.2.1 Define the following terms:

Programming Language.
C language

assembly
Language
Motorola I.C
1.2.2 Describe the various types of
programming languages

High
Machine Assembly level
language

evel l an guage
Low l

23
1.2.2 Describe the various types of
programming languages

Category Explanation
Machine Binary number codes understood by
language a specific CPU
Assembly Mnemonic codes that correspond to
language machine language instructions
High level Machine-independent programming
language language that combines algebraic
expressions and English symbols.

Computer programmers usually only involve in


writing high level language
24
1.2.2 Describe the various types of
programming languages

#1: Machine Level Language


 Machine languages are the only Programming
languages understood by computers. While easily
understood by computers, machine languages are
almost impossible for human to use because they
consist entirely of numbers (binary bits i.e. 0 or 1).
1.2.2 Describe the various types of
programming languages

#1: Machine Level Language


1.2.2 Describe the various types of
programming languages

#1: Machine Level Language


 Advantages:
the programs are written in binary form,
there is no need of assemblers or compilers to
convert the codes to machine readable form so the
execution is fast.
This also leads to smaller file size.
1.2.2 Describe the various types of
programming languages

#1: Machine Level Language


 Disadvantages:
It is extremely difficult to learn , as program codes are
to be written in binary form.
It is machine dependent so program written on one
computer cannot be run on another computer of the
same type.
As they are machine dependent proper knowledge of
CPU architecture (addressing methods, register types
etc) is a must.
1.2.2 Describe the various types of
programming languages

#2: Low Level or Assembly Language


 Assembly language is a type of programming
language ,which is used to program computers,
microprocessors, microcontrollers, and other
(usually) integrated circuits.
They implement a symbolic representation of the
numeric machine codes and other constants
needed to program a particular CPU architecture.
1.2.2 Describe the various types of
programming languages

#2: Low Level or Assembly Language


 An assembly language is thus specific to certain
physical or virtual computer architecture. An
assembly language programmer must understand
the microprocessor’s unique architecture (such as
its registers and instruction).
Program written in assembly language is
converted to binary codes using special programs
called assemblers.
1.2.2 Describe the various types of
programming languages

#2: Low Level or Assembly Language


binary
Assembler

PC architecture
1.2.2 Describe the various types of
programming languages

#2: Low Level or Assembly Language


 In assembly language a mnemonic is a code, usually from
1 to 5 letters, that represent an operational code (op-
code), followed by one or more numbers (the operands).
Op-code or operation code is between one and three
bytes in length and uniquely defines the function that is
performed. It is the data that represents a microprocessor
instruction.
1.2.2 Describe the various types of
programming languages
#2: Low Level or Assembly Language
1.2.2 Describe the various types of
programming languages

#2: Low Level or Assembly Language


Advantages:
Program written in assembly language are simpler than
program written in machine codes as use of binary codes
to represent operational codes is replaced by words
(mnemonics).
Program written for a family of microprocessors need
not be rewritten i.e. machine dependence is somewhat
reduced.
Less knowledge of CPU architecture compared to
machine level language is required.
1.2.2 Describe the various types of
programming languages

#2: Low Level or Assembly Language


Disdvantages:
Requirement of knowledge of CPU architecture
is not completely eliminated.
Assembly Languages are to be converted into
binary codes using assemblers so final
executable file size is large compared to
machine level ones.
1.2.2 Describe the various types of
programming languages

#3: High Level Language


High level programming languages are those
programming language which use normal
everyday word to represent the executable
operational codes.
These types of programming language follow
strictly followed rule for writing these instruction.
This rule is known as syntax.
1.2.2 Describe the various types of
programming languages

#3: High Level Language


High level languages are easy to learn as they
avoid the need to understand the complex CPU
architecture and also because the commands are
in plain understandable English form.
These programs written in plain English form
following syntax are converted in machine
understandable form using either compilers or
interpreters.
Computer only
understands
machine language.

So, computer need


translator call:
-Assembler
-Compiler or interpreter.

Assembler:
assembly machine

compiler or interpreter
high level machine
38
Assembly
code

Assembler

Object code
(machine language)
39
1.2.2 Describe the various types of
programming languages

#3: High Level Language


Advantages.
 They are easy to understand and user friendly.
 It reduces the complexity of programming as need of knowledge
of CPU architecture is eliminated.
 High level programs are very easy to maintain than machine and
lower level languages. In machine and lower level languages,
instructions are difficult and very hard to locate, correct and
modify but in high level language, it is very easy to understand and
modify when desired.
1.2.2 Describe the various types of
programming languages

#3: High Level Language


Advantages.
Each high-level language provides a large number of
built-in functions or procedures that can be used to
perform specific tasks during designing of new
programs. In this way, a large amount of time of
programmer is saved.
 Program written in high-level language is machine
independent. It means that a program written on one
type of computer can be executed on another type of
computer.
1.2.2 Describe the various types of
programming languages

#3: High Level Language


Disadvantages.
The additional process of compilation needs more
machine time than the straight assembly process.
 There is no control of hardware part while writing high
level programs.
 The programs have to be compiled every time a
change is made.
1.2.2 Describe the various types of
programming languages
1.2.2 Describe the various types of
programming languages
1.3 The types of programming and
structure programming
methodology
1.3.1 Explain the following types of programming:

• Structured programming
• Modular programming
• Object-Oriented programming
1.3.1 Explain the following types of programming:

#1: Structured programming


 Structured programming is a programming
paradigm/technique aimed on improving the clarity,
quality, and development time of a computer program by
making extensive use of subroutines, block structures
and for and while loops.
Top-down approach.
The most popular structured programming languages
include C,C++, Ada, and Pascal.
1.3.1 Explain the following types of programming:

#1: Structured programming


 Split the task into modular/specific box to make
program much more easier to develop
1.3.1 Explain the following types of programming:

#2: Modular programming


 Modular programming is a software design technique
that increases the extent to which software is
composed of separate, interchangeable components
called modules by breaking down program functions into
modules, each of which accomplishes one function and
contains everything necessary to accomplish this.
1.3.1 Explain the following types of programming:

#2: Modular programming


 Conceptually, modules represent a separation,
and improve maintainability by enforcing logical
boundaries between components.
Explain the following types of programming:
1.3.1

Modular programming (2)


#2: Modular programming
Main program
data

module1 module2
data+data1 data+data2

procedure2 procedure3
procedure1

56
1.3.1 Explain the following types of programming:

#3: Object Oriented programming


 Object-oriented programming (OOP) is a
programming paradigm using "objects" – data
structures consisting of data fields and methods
together with their interactions – to design
applications and computer programs.
1.3.1 Explain the following types of programming:

#3: Object Oriented programming


 Programming techniques may include features such
as data abstraction, encapsulation,
messaging, modularity, polymorphism, and
inheritance. Many modern programming
languages now support OOP, at least as an option.
The most popular object-oriented programming
languages include Java, Visual Basic, C#, C++, and
Python.
1.3.1 Explain the following types of programming:

#3: Object Oriented programming


Everything in OOP is grouped as self
sustainable "objects"
Types of programming
Structured Programming/
 Object Oriented Programming
Modular programming

Structured Programming is designed which


Object Oriented Programming is designed
focuses on process/ logical structure and then
which focuses on data.
data required for that process.

Structured programming follows top-down Object oriented programming follows bottom-


approach. up approach.

Structured Programming is also known as Object Oriented Programming supports


Modular Programming and a subset of inheritance, encapsulation, abstraction,
procedural programming language. polymorphism, etc.

In Structured Programming, Programs are divided In Object Oriented Programming, Programs


into small self contained functions. are divided into small entities called objects.

Structured Programming is less secure as there is Object Oriented Programming is more secure
no way of data hiding. as having data hiding feature.

Structured Programming can solve moderately Object Oriented Programming can solve any
complex programs. complex programs.

Structured Programming provides less Object Oriented Programming provides more


reusability, more function dependency. reusability, less function dependency.

Less abstraction and less flexibility. More abstraction and more flexibility.
1.4 Algorithm, flowchart
and pseudocode
Define the algoritm in programming
i. Definition: an algorithm is a step-by-step procedure
to solve a given problem.
Define the algoritm in programming.
i. An algorithm gives a solution to a particular problem as a
well defined set of steps.
ii. A recipe in a cookbook is a good example of an algorithm.
When a computer is used for solving a particular problem,
the steps to the solution should be communicated to the
computer.
iii. An algorithm is executed in a computer by combining lot of
elementary operations such as additions and subtractions to
perform more complex mathematical operations.
Define the algoritm in programming.

Let's say that you have a friend arriving at the


airport, and your friend needs to get from the
airport to your house. Here are four different
algorithms that you might give your friend for
getting to your home:
Define the algoritm in programming.

The taxi algorithm:


Go to the taxi stand.
Get in a taxi.
Give the driver my address.

The call-me algorithm:


When your plane arrives, call my cell phone.
Meet me outside.
I’ll take u to my home!!
Define the algoritm in programming.

The rent-a-car algorithm:


Take the shuttle to the rental car place.
Rent a car.
Follow the directions to get to my house.

The bus algorithm:


Outside baggage claim, catch bus number 70.
Transfer to bus 14 on Main Street.
Get off on Elm street.
Walk two blocks north to my house.
Define the algoritm in programming.

• All four of these algorithms accomplish exactly the same


goal,

• BUT each algorithm does it in completely different way.

• In computer programming, there are often many different


ways -- algorithms -- to accomplish any given task.

• Each algorithm has advantages and disadvantages in


different situations.
Define the algoritm in programming.
Define the algoritm in programming
Identify the pseudocode in programming

● Pseudocode is one of the methods that could


be used to represent an algorithm. It is not
written in a specific syntax that is used by a
programming language and therefore cannot
be executed in a computer.
● There are lots of formats used for writing
pseudocode and most of them borrow some of
the structures from popular programming
languages such as C, Lisp, FORTRAN, etc.
Identify the pseudocode in programming

● Most of the algorithms are presented using


pseudocode since they can be read and
understood using programmers who are
familiar with different programming languages.
● Pseudocode allows to include control
structures such as WHILE, IF-THEN-ELSE,
REPEAT-UNTIL, FOR, and CASE, which are
present in many high level languages.
Pseudocode in C programming Adding 2
numbers

1. Initialize total to zero


2. Initialize number1
3. Initialize number2
4. Input number1
5. Input number2
6. Add number1 and number2 = total
7. Display the result.
Identify the pseudocode in programming
Compare the advantages and disadvantages of Pseudocode

Advantages Disadvantages

Easily understood Cannot be executed in the computer

Easily maintained

The codes are changeable


Identify the flowchart in programming

● Graphic representation of algorithm which is consist of


geometric symbols.
● Symbols are connected by line of arrows called flow
lines which indicate the direction of flow of processes
or activities.
● The shape of the symbol indicates the type of
operation that is to occur.
● Flowchart should flow from the top of the page to the
bottom. The symbols used in flowchart are
standardized.
Explain the flowchart symbols.
Explain the flowchart symbols.
Explain the flowchart symbols.
Explain the flowchart symbols.
Compare the advantages and
disadvantages of flowchart
Advantages Disadvantages

Easy to draw Time consuming

Easy technique to understand logic Difficult for modification

Easy to identify the mistake by non Difficult task to draw flow charts for big
computer person programs

There are no standards of pertaining the


Easy for branching and looping details that should be included in a flow
chart.
Construct flowchart for the given problem.

Algorithm and flow chart to read the name and print the name.
Construct flowchart for the given problem.

Algorithm and flow chart to add two numbers.


Construct flowchart for the given problem.

Algorithm and flow chart to find the average of three numbers.


Construct flowchart for the given problem.

Algorithm and a flow chart to calculate area of square.


Apply flowchart for the following

a. Sequence structure.

In a computer program or an
algorithm, sequence involves
simple steps which are to be
executed one after the other. The
steps are executed in the same
order in which they are written.
a. Sequence structure.
Apply flowchart for the following

b. Selection Structure.

Selection is used in a
computer program or
algorithm to determine
which particular step or set
of steps is to be executed.
b. Selection Structure.
c. Looping Structure.

true
false
Apply flowchart for the following
c. Looping Structure.

• Repetition allows for a portion of an algorithm or


computer program to be done any number of times
dependent on some condition being met.

• An occurrence of repetition is usually known as a loop.

• An essential feature of repetition is that each loop has


a termination condition to stop the repetition, or the
obvious outcome is that the loop never completes
execution (an infinite loop).
c. Looping Structure.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy