0% found this document useful (0 votes)
14 views

L0 - Eng Problems - Intro To PL

Uploaded by

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

L0 - Eng Problems - Intro To PL

Uploaded by

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

Introduction to Structured

Programming
King Abdulaziz University
Faculty of Engineering
Electrical Engineering Dept.

EE 201
9/3/2024 C-intro OE 1
Structured Programming
& Matlab

9/3/2024 C-intro OE 2
Structured programming (SP)

 what is SP ?

 Before answering this question, a


brief history of computer systems,
and how it is work should be
represented:

9/3/2024 C-intro OE 3
Computers Generations - -Past
to Present & Beyond

9/3/2024 C-intro OE 4
What is a Computer ?
 Computer
◼ Device capable of performing computations
and making logical decisions
◼ Computers process data under the control of
sets of instructions called computer programs
 Hardware (HW)
◼ Various devices comprising a computer
Keyboard, screen, mouse, disks, HW
memory, CD-ROM, and central Computer
processing units, registers etc.
SW
 Software (SW)
◼ Programs that run on a computer
9/3/2024 C-intro OE 5
Computer Hardware Architecture

101011 101011

1
0
1
1
1
0 0
0
1
1
1
0
1
1 1
1 1 0
0 0 1 1
0 0 1 1 0
1 1
1 1 1
1
0 0 1
0
0
1 1 1 1
1 1 0
1
1
1
010101000100001
011101110010101
Machine Language
9/3/2024 C-intro OE 6
Computer Hardware Organization
 A central processing unit (CPU) consists of
◼ an arithmetic/logic unit (ALU) where math and logic
operations (program instructions)are performed,
◼ a control unit which directs most operations (program
instructions)by providing timing and control signals,
◼ and registers that provide short-term data storage
and management facilities.
 a memory unit that stores instructions and data, and
 input (e.g. keyboard, mouse, microphone, disk drive,
etc.) and output (e.g. monitor, status indicator lights,
speakers, disk drive, etc.) units that are used to transmit
data into and out of the computer.

9/3/2024 C-intro OE 7
Perforated (punched) cards as one of
the 1st input devices for machine language
(o’s and1’s)

9/3/2024 C-intro OE 8
???
 So, Computer used the machine
language (1001101….) between its
components, the question ??
 How can the user deal with
components ?

Operating system
9/3/2024 C-intro OE 9
What Is an Operating system?
 An interface between the hardware
and the user.

 Provides an easy and efficient use of


the system resources.
 Examples:
◼ DOS, Windows, Unix, Linux, Qunix,
Android, OSI, …

9/3/2024 C-intro OE 10
As obvious before that:
 Computer only understands machine
language instructions.
 We need a way to convert the
instructions of the HLL – written with
natural language – to ML.

???
9/3/2024 C-intro OE 11
Translation from HLL to ML


9/3/2024 C-intro OE 13
Assembler
 Instructions written in assembly
language must be translated to
machine language instructions :
◼ Assembler do it
 One to one translation : One AL
instruction is mapped to one ML
instruction.
 AL instructions are CPU specific.

9/3/2024 C-intro OE 14
Translation from HLL to ML



9/3/2024 C-intro OE 15
Programming Language (PL)
 Definition :

◼ A vocabulary and set of grammatical


rules for instructing a computer to
perform specific tasks.

 SO PL’s could be classified according to :


◼ Execution model
◼ Programming approach

9/3/2024 C-intro OE 16
Execution model

9/3/2024 C-intro OE 17
Compiler
 Instructions written in high-level
language also must be translated to
machine language instructions :
◼ Compiler do it
 Generally, one to many translation :
One HL instruction is mapped to many
ML instruction.
 HL instructions are not CPU specific but
compiler is.

9/3/2024 C-intro OE 18
Interpreter
 An interpreter translates high-level instructions into an
intermediate form, then executes.
 In contrast, a compiler translates high-level instructions
directly into machine language.
 Compiled programs generally run faster than
interpreted programs.
 The real need of interpreter comes where compiler fails
to satisfy the software development needs.
 If the source code is huge in size, then the compilation
duration increased.
 Interpreters are designed to translate single instruction
at a time and execute them immediately.

9/3/2024 C-intro OE 19
Programming approaches
 Imperative programming. (The oldest, works on the logic of “First do this then do that”)

◼ (Assembly, C, C++, Java etc.)


 Declarative programming. (focuses on logic of computation, no flow control statements)

◼ (SQL, Xquery)
 Structured programming approach.(improvement of imperative,
◼ (C, C++, Pascal, Ada, Matlab etc.) extensive use of flow control)

 Procedural programming approach.(Kind of structured, each line is procedural calls or


◼ (C, Pascal, BASIC, Fortran etc.) data assignment)

 Object-Oriented programming approach. (widely practiced approach)

◼ (Simula-67, Java, C++, C#, Matlab etc.)


 Functional programming approach. (Totally different approach. Function calls

◼ (Python, Lisp, Clojure, Haskell etc.) -function is input to another function)

9/3/2024 C-intro OE 20
Main Programming approach

9/3/2024 C-intro OE 21
Translation from HLL to ML




9/3/2024 C-intro OE 22
Evolution of Programming languages
◼ First Generation : Machine languages
 Strings of numbers giving machine specific instructions
 Example:
+1300042774
+1400593419
+1200274027
◼ Second Generation : Assembly languages
 English-like abbreviations representing elementary computer
operations (translated via assemblers)
◼ Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
◼ Third Generation : High-level languages
 Codes similar to everyday English
 Use mathematical notations (translated via compilers)
 Example: grossPay = basePay + overTimePay
9/3/2024 C-intro OE 23
Basic 66

C 73

C ++ 80

Matlab 84

Python 91

Java 95

C# 2001

9/3/2024 C-intro OE 24
Structured Programming

 Structured programming
◼ Disciplined approach for writing
programs
◼ Clear, easy to test, debug, and modify
 Structured programming takes time
to master

9/3/2024 C-intro OE 25
Structured Programming
(continued…

 Structured programming is a technique for


designing programs .
 A hierarchy of modules is used, each
having a single entry and a single exit point
.
 Control is passed downward through the
structure without unconditional branches to
higher levels of the structure.
 In MATLAB these modules can be built-in or
user-defined functions.
9/3/2024 C-intro OE 26
Top-Down or Modular
Programming
Structural chart
MAIN PROGRAM GLOBAL DATA

FUNCTION FUNCTION 2 FUNCTION 3


1

FUNCTION 4 FUNCTION 5

9/3/2024 C-intro OE 27
Structured Programming
(continued…

 Control of the program flow uses the same


three types of control structures used in
algorithms:
1. Sequence of sequentially executed
statements.
2. Conditional execution of statements (i.e.,
"if" statements).
3. Looping.
Structured SubRoutine calls (e.g., 'gosub' but
not 'goto').
9/3/2024 C-intro OE 28
Three Structured Programming
Constructs (Algorithmic operations)

9/3/2024 C-intro OE 29
Structured Programming
(continued…

In particular, the following language usage


is forbidden:
 "GoTo" statements.
 "break" or "continue" out of the middle
of loops.
 Multiple exit points to a
function/procedure/subroutine (i.e.,
multiple "return" statements).
 Multiple entry points to a
function/procedure/subroutine.
9/3/2024 C-intro OE 30
Object-Oriented Approach
Programming

 Completely different approach to information


systems
 Views information system as collection of
interacting objects that work together to
accomplish tasks
Objects – things in computer system that can
respond to messages
Conceptually, no processes, programs, data
entities, or files are defined – just objects
 OO languages: Java, C++, C#, .NET, VB
9/3/2024 C-intro OE 31
Object-Oriented Approach to
Systems
Object 2
Object 1

Data Data

Function Function

Object 3

Data

Function

9/3/2024 C-intro OE 32
Structured Programming VS
Object-Oriented
The main difference is that :
structured programming In contrast, object
deals with the flow of oriented programming
execution, and not, primarily deals with data
primarily, with the data. issues. In a pure object
It has to do with the oriented approach, the
organization of the flow of program
code, rather than the execution is treated as
data. It also eliminates bits of behavior
arbitrary jumps associated with the
(GOTOs) in code blocks packets of data that are
and functions. "objects".
9/3/2024 C-intro OE 33
MATLAB
An
overview

9/3/2024 C-intro OE 34
MATLAB Overview
 Why MATLAB in this course
 What is MATLAB?
 History of MATLAB
◼ Who developed MATLAB
◼ Why MATLAB was developed
◼ Who currently maintains MATLAB
 Strengths of MATLAB
 Weaknesses of MATLAB
9/3/2024 C-intro OE 35
Why MATLAB in this course ?
 The purpose of the EE201 course is to
provide students with the necessary
skills to solve engineering problems
using computer programming. In this
course, students will learn how to
apply programming fundamentals and
utilize its flexibility and ease of use in
both academic and professional
purposes.
9/3/2024 C-intro OE 36
Why MATLAB in this course ?

 The course aims to enhance students'


logical thinking abilities and mental
skills, which are crucial for engineers.

9/3/2024 C-intro OE 37
Why MATLAB in this course ?

 Structured programming is a
technique used to design programs,
and various platforms can be used to
teach this concept, such as C, Python,
and Java.
However…!

9/3/2024 C-intro OE 38
Why MATLAB in this course ?
MATLAB has been selected for this course
due to its additional advantages for
engineering students, including familiarity
with the package that will enable them to
utilize MATLAB's essential engineering
applications in the future, such as signal
processing, fuzzy logic, neural networks,
control systems, modeling and simulation,
image processing, and more.

9/3/2024 C-intro OE 39
What is MATLAB?
 MATLAB
◼ MATrix LABoratory
◼ Interactive system
◼ Programming language

9/3/2024 C-intro OE 40
History of MATLAB
 Developing Software to MATLAB
◼ Fortran subroutines for solving linear
(LINPACK) and eigenvalue (EISPACK)
problems
◼ Developed primarily by Cleve Moler in
the 1970’s

9/3/2024 C-intro OE 41
History of MATLAB (continued…

 Later, when teaching courses in


mathematics, Moler wanted his
students to be able to use LINPACK
and EISPACK without requiring
knowledge of Fortran

 MATLAB developed as an interactive


system to access LINPACK and
EISPACK
9/3/2024 C-intro OE 42
History of MATLAB (continued…

 MATLAB gained popularity primarily


through word of mouth because it
was not officially distributed

 In the 1980’s, MATLAB was rewritten


in C with more functionality (such as
plotting routines)

9/3/2024 C-intro OE 43
History of MATLAB (continued…

 The Mathworks, Inc. was created in


1984
 The Mathworks is now responsible for
development, sale, and support for
MATLAB.

9/3/2024 C-intro OE 44
Strengths of MATLAB
(continued…

 MATLAB is relatively easy to learn


 MATLAB code is optimized to be relatively
quick when performing matrix operations
 MATLAB may behave like a calculator or as
a programming language
 MATLAB is interpreted, errors are easier to
fix
 Although primarily procedural, MATLAB
does have some object-oriented elements.

9/3/2024 C-intro OE 45
Strengths of MATLAB
(continued…

 MATLAB is now widely used in several


important engineering applications such as
example :
◼ Signal Processing.
◼ Fuzzy Logic.
◼ Neural Networks.
◼ Control systems.
◼ Modeling and simulation
◼ Image Processing.

9/3/2024 C-intro OE 46
Weaknesses of MATLAB
 MATLAB is NOT a general purpose
programming language.
 MATLAB is an interpreted language
(making it for the most part slower
than a compiled language such as
C++).
 MATLAB is designed for scientific
computation and is not suitable for
some things (such as parsing text).
9/3/2024 C-intro OE 47
Individually answer the following : Activity(1)

1. Type of PL ?
ML AL HLL
2. Which type of HLL ?
S. P. O.O.P Both
3. Uses ?
Assembler Interpreter Compiler

4. Working with which operating system ?


Only windows Many According to version
5. Machine dependent ?
Machine configuration dependent Machine type dependent
9/3/2024 C-intro OE 48

You might also like