0% found this document useful (0 votes)
18 views96 pages

Chapter1 Introduction v20242 Rev1

The document outlines the EE3491 course on Programming Techniques, focusing on C and C++ programming languages. It covers course objectives, targeted platforms, evaluation methods, and essential software installation instructions. Additionally, it provides insights into computer hardware and software, programming history, and the importance of programming in electrical and electronic engineering applications.

Uploaded by

coccocvodanh
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)
18 views96 pages

Chapter1 Introduction v20242 Rev1

The document outlines the EE3491 course on Programming Techniques, focusing on C and C++ programming languages. It covers course objectives, targeted platforms, evaluation methods, and essential software installation instructions. Additionally, it provides insights into computer hardware and software, programming history, and the importance of programming in electrical and electronic engineering applications.

Uploaded by

coccocvodanh
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/ 96

EE3491 - Kỹ thuật lập trình

EE3490E – Programming Techniques


Chapter 1: Introduction

Lecturer: Dr. Hoang Duc Chinh (Hoàng Đức Chính)


Department of Automation Engineering
School of Electrical and Electronic Engineering
Email: [email protected]

© HĐC 2024.1
Content

1.1. Course Description


1.2. Getting started
1.3. Computer Hardware
1.4. Computer Software
1.5. Basic definitions
1.6. Overview of C/C++ languages

© HĐC 2024.2 Chapter 1: Introduction 2


1.1. Course Description
Sensors
 Electric Machines and Drives
 Power Electronics
Microcontroller  Control Engineering
 Measurement and Instrumentation
Drivers
 Microprocessor
Sensors

Communication

 Indutrial Communication
Systems
 Logic Control and PLC
 Computer Integrated
Manufacturing Systems

© HĐC 2024.2 Chapter 1: Introduction 3


1.1. Course Description
Sensors

 Programming Techniques
 Programming Languages
Microcontroller

Drivers

Sensors

Communication

 Programming Techniques
 Programming Languages

© HĐC 2024.2 Chapter 1: Introduction 4


Programming in Electrical & Electronic Engineering Applications

Control applications, e.g. microcontroller, computer,


programmable logic controller, distributed controller
system
Data acquisition and management
Human Machine Interface
System integration
Design and calculation software
Simulation software
Optimization
Communication protocols
…

© HĐC 2024.2 Chapter 1: Introduction 5


Aims and scopes

 This course provides fundamentals of programming techniques,


implemented with C and C++ programming languages
 Structure programming
 Object oriented programming (OOP)
 Real-time programming and typical data structure in embedded systems
 Generic programming (optional)
 You will also learn the essential knowledge, including
 memory management, pointers, preprocessor macros,
 and how to find bugs when you inevitably use any of those incorrectly.
 Why C/C++:
 Strong and popular languages, which enables programmer to implement
most important techniques
 Essential in electrical and electronic systems

© HĐC 2024.2 Chapter 1: Introduction 6


Targeted platforms

© HĐC 2024.2 Chapter 1: Introduction 7


What to expect?

© HĐC 2024.2 Chapter 1: Introduction 8


What to expect?

© HĐC 2024.2 Chapter 1: Introduction 9


What to expect?

 Solid background is important, especially


 Thinking and Methodology
 Adaptation to different applications
 Adaptation to various programming languages: Java, Python, C#,
MATLAB, etc.
 Focus on professionality in programming: effectiveness and quality
 The following topics may be mentioned but not included in
the main scope of this course:
 Low-level system programming
 Graphics programing
 I/O interface
 Database
 Communication and Networking
 Design and write programmes with weekly assignments and
an individual mini-project

© HĐC 2024.2 Chapter 1: Introduction 10


Syllabus
 Chapter 1 – Introduction 2 week*
 Chapter 2 – Basic of C & C++ 3 weeks
Assignments
 Chapter 3 – Functions & Libraries 3.5 weeks
Mini project assigned
Mid-term exams tentative schedule (Thi giữa kỳ dự kiến) Week 10th
 Chapter 4 – Data structures & Algorithms 2.5 weeks
Assignments
 Chapter 5 – Program design & efficiency 1.5 weeks
Mini project submision
 Chapter 6 & 7 – Class & Objects 1 weeks
 Chapter 8 – Class relationship 1 weeks
Assignments
 Revision 0.5 weeks
* Duration of each Chapter is tentative and can be changed slightly along the course

© HĐC 2024.2 Chapter 1: Introduction 11


Evaluations

Progress assessment: 30%


 Weekly exercises/ Quizzes (Progress scores)
 Mini project
o Up to 3 bonus points over 10 if performing very well
o -3 points if no submission or plagirsim
 Mid-term exams (written & open book but no electronic
devices)
Final exams: 70%
 Oral/Written exams (open book but no electronic devices)

© HĐC 2024.2 Chapter 1: Introduction 12


Evaluations

Mid-term and final exams are in written format with the


duration of 60 – 90 minutes, they includes
 Theoretical questions
 Evaluate program results
 Write programs to solve specific problems
Mini project:
 Good performance: bonus points
 Late submission: 0 bonus point
 NO submission: up to -3 in progress assessment
 Can be used for final exams if it is in oral format (an extra
project will be given in this case)

© HĐC 2024.2 Chapter 1: Introduction 13


Learning methodologies

Method 1: Attend lectures self-attempt read


material discussion practice
Method 2: Read material self-attempt attend
lectures discussion practice
Basic principle: Studying actively and regularly!
Do not:
 Write too much in the class
 Learn by heart
 Rely on revision only
 Learn the examples in the books/references solely
 Take pictures/videos in the class

© HĐC 2024.2 Chapter 1: Introduction 14


References

 English:
[1] Brian Kernighan B.W., Ritchie D.M., The
C Programming Language, 2nd edition,
Prentice Hall, 1998
[2] Bjarne Stroustrup, The C++
Programming Language, 4th Edition
[3] Stanley B. Lippman et. al, C++ Primer,
5th Edition
[4] Scott Meyers, Effective C++, 3rd Edition
[*] Many other books and resources
 Tiếng Việt:
[5] Phạm Văn Ất et. al., Giáo Trình Kỹ Thuật
Lập Trình C Căn Bản và Nâng Cao
[6] Phạm Văn Ất et. al., Giáo Trình C++ Và
Lập Trình Hướng Đối Tượng

© HĐC 2024.2 Chapter 1: Introduction 15


Contact

Our team:
 Assoc. Prof. Nguyễn Hồng Quang
 Dr. Hoàng Đức Chính
 Dr. Nguyễn Trí Cường
 Dr. Võ Duy Thành
Department of Automation Engineering,
School of Electrical and Electronics Engineering
Lecture notes (Slides bài giảng), assignments &
discussion: Microsoft Teams (Team code: xem QLĐT)
It is highly recommended to discuss about the course in
the offline class and the class’s Teams

© HĐC 2024.2 Chapter 1: Introduction 16


The tools

A computer: PC or Laptop or Single Board Computer


Editors: Visual Studio Code (must use in this course),
Notepads++, Emacs, Sublime, etc.
Compilers: gcc, g++
Debugger: gdb
Operating systems and Packages:
 Windows: Mingw-w64 (recommended), Cygwin
 Linux (Ubuntu) and MacOS: gcc, g++ and gdb are usually pre-
installed as default packages
An Integrated Development Environment such as Visual
Studio, Code Blocks, Dev-C++, etc. can be used but not
recommended.
© HĐC 2024.2 Chapter 1: Introduction 17
1.2 Getting started

 Windows:
 Install Visual Studio Code (VS Code)
https://code.visualstudio.com/download
 Install C++ extension for VS Code
 Download MinGW-w64 here: https://github.com/niXman/mingw-
builds-binaries/releases/download/14.2.0-rt_v12-rev1/x86_64-14.2.0-
release-posix-seh-ucrt-rt_v12-rev1.7z
 Install MinGW-w64 by extracting the above file in a folder with
simple path, e.g: C\Mingw64
 Set Mingw64\bin in Windows Environment Variables
 Linux:
 gcc or g++ may be installed by default, otherwise install it:
sudo apt-get update
sudo apt-get install build-essential gdb
 MacOS: Use Clang for compiling
 Check if Clang is install: clang --version
 Install it: xcode-select --install

© HĐC 2024.2 Chapter 1: Introduction 18


Installation

Install MinGW-w64
 Version: (choose the highest)
 Architecture: x86_64
 Threads: win32 or posix
 Exceptions: seh
 Build revision: 0
Add the path to your Mingw-w64 bin folder to the
Windows PATH environment variable

© HĐC 2024.2 Chapter 1: Introduction 19


MinGW-W64 configuration

© HĐC 2024.2 Chapter 1: Introduction 20


MinGW-W64 configuration

© HĐC 2024.2 Chapter 1: Introduction 21


MinGW-W64 configuration

© HĐC 2024.2 Chapter 1: Introduction 22


MinGW-W64 configuration

© HĐC 2024.2 Chapter 1: Introduction 23


MinGW-W64 configuration

After installing MinGW-w64, you can verify if the


installation is correct by opening a new Command
Prompt and typing:
 gcc --version
 g++ --version
 gdb --version

 Otherwise, the
code cannot be
compiled, and
you have to
reinstall/reconfig

© HĐC 2024.2 Chapter 1: Introduction 24


VSCode configuration

 Install C++ extension for VS Code

© HĐC 2024.2 Chapter 1: Introduction 25


VSCode configuration

Configuration files in VSCode project


 c_cpp_properties.json (compiler path and IntelliSense settings)
 tasks.json (build instructions)
 launch.json (debugger settings) (.json JavaScript Object
Notation (JSON) format)

© HĐC 2024.2 Chapter 1: Introduction 26


Compiler path

© HĐC 2024.2 Chapter 1: Introduction 27


Build task (tasks.json)

© HĐC 2024.2 Chapter 1: Introduction 28


Debugger configuration (launch.json)

© HĐC 2024.2 Chapter 1: Introduction 29


Start coding

© HĐC 2024.2 Chapter 1: Introduction 30


Further readings

Integrate with External Tools via Tasks:


https://code.visualstudio.com/docs/editor/tasks
Debugging:
https://code.visualstudio.com/docs/editor/debugging
C/C++ in Windows:
https://code.visualstudio.com/docs/cpp/config-mingw
C/C++ in Linux:
https://code.visualstudio.com/docs/cpp/config-linux

© HĐC 2024.2 Chapter 1: Introduction 31


Homework 1

Install the following software packages in Windows


7/10:
 Visual Studio Code
 C++ Extension in Visual Studio Code
 Mingw64 and respected configuration
Create a new project, write a simple program (Hello
World as an example) and execute
Try to change a few argument in tasks.json and
launch.json to see what will happen

© HĐC 2024.2 Chapter 1: Introduction 32


1.3. Computer hardware

The primary function of a digital computer is to process


data input to produce results that can be better used in a
specific application environment.
.
Input .
Central Processing Devices
.

Unit (CPU) 0x634100 2024


0x634104 A
.
.
Main Memory Output .

Devices 0x634200
0x634204
.
.
Secondary Storage .

Hardware components of a computer Main memory

© HĐC 2024.2 Chapter 1: Introduction 33


1.3 Computer hardware

Abacus, 2700 BC - present Antikythera, 150–100 BCE Pascal’s calculator, 1642

A metal rebuild of Babbage’s Difference Engine, A modern partial rebuild of


created in 1855 & used till 1930s Babbage’s Analytical Engine

© HĐC 2024.2 Chapter 1: Introduction 34


1.3 Computer hardware

Enigma machine, The Bombe, 1939


1923 - 1942

Alan Mathison Turing


(23/6/1912 – 7/6/1954)

ENIAC (Electronic Numerical UNIVAC (Universal


Integrator and Computer), 1945 Automatic Computer), 1951
© HĐC 2024.2 Chapter 1: Introduction 35
1.3 Computer architecture

© HĐC 2024.2 Chapter 1: Introduction 36


1.3 Computer architecture

Central Processing Unit


Control Unit

Input Arithmetic & Logic Unit Output


Devices Devices

Memory Unit

John Von Neumann


(1903-1957) Von Neumann Architecture was proposed in 1945

© HĐC 2024.2 Chapter 1: Introduction 37


1.3 Computer architecture

ALU

Instruction Data
Control Unit
Memory Memory

I/O

Harvard Architecture

© HĐC 2024.2 Chapter 1: Introduction 38


1.4 Computer Software

Software are programs written to perform specific tasks.


All software is written in programming languages.
There are two types of programs:
 System programs control the computer.
 Application programs perform a specific task.

© HĐC 2024.2 Chapter 1: Introduction 39


The history
“Software Crisis”
1st version of C
Structural
programming
Early
Ada Lovelace Programming
Languages 1990s Parallel &
published the 1st
Assembler, distributed computing
computer program 1st ver. of Fortran Python, Java, JavaScript

1843 1940s 1950s 1960s 1970s 1980s 1990s 21st cent.

Blooming era of
Stronger Internet
Computational Languages facilitate
Languages Internet applications
Cobol, Lisp, Basic including Web, IoT, Big
Data, etc.

1st modern C++ 1st introduced


computers Simplicity – Object
Machine code oriented, Functional
Programming

© HĐC 2024.2 Chapter 1: Introduction 40


Software crisis

 Software crisis included various issues when developing software


in 1960s, especially with large software system based on
conventional techniques at that time.
 Consequences:
1. Time and price increased tremendously
2. Low productivity
3. Low quality
 It resulted in appearance of Software Engineering

© HĐC 2024.2 Chapter 1: Introduction 41


What is programming?

Write a program to Write a function to


calculate factorial of calculate the
100! factorial!

Write a program to Write a program to


print the first 100 print the first N
prime numbers! prime numbers!

This is not proper This is programming!


programming!
A computer program is a collection of instructions for a
computer to perform a specific function and achieve a
particular result.
© HĐC 2024.2 Chapter 1: Introduction 42
Software vs. Program
Program Software
Definition A set of instructions that is used as a A set of programs that enables the
process of creating a software hardware to perform a specific task.
program by using programming
language.
Size smaller in size ( a few KB to ~1 larger in size ( a few Mb to Gb)
MB)
Types have no further categorization A few types: system software,
application software, etc.
Features & includes fewer features and limited has more features and
functionality functionalities. functionalities.
Development unorganized, unplanned, and well planned, organized, and
approach unprocedural systematic
Time taken takes less time to be developed requires more time to be developed

Examples video games, malware, etc. Adobe Photoshop, Adobe Reader,


Google Chrome, etc.
https://www.javatpoint.com/program-vs-software
© HĐC 2024.2 Chapter 1: Introduction 43
A good program/software

 Provide the right solution accepted by customers


 Reliability
 Proper execution
 Less errors in quantity and frequency of occurrence
 Non-severe errors
 Efficiency
 Compact programs, low memory utilization
 Fast run, low CPU usage
 Effectiveness
 Short development time
 Easy to maintain
 Highly usable
 User friendly
 Rich features

© HĐC 2024.2 Chapter 1: Introduction 44


How to program well?

 Learn the way of thinking and programming methodologies


 Mathematical thinking, logical thinking, structure thinking, OOP
thinking and generic thinking
 Exploring data structures and algorithms
 Understand the computer
 Interaction amongst CPU, Programs and Memory
 Memory management
 Mastering the programming language
 Understand the strengths and limits of the language
 Programming skill
 Self-practicing
 Understand the above aspects
 Learn from professional developers’ codes (but do not copy blindly)
 Keep practicing and be creative

© HĐC 2024.2 Chapter 1: Introduction 45


Examples

 Write a program to calculate the factorial of a positive integer


n
 The function
int factorial (int N);
 Algorithm:
 Recursive method:
if (N > 1)
return N*factorial(N-1);
return 1;

 Iterative method
int kq = 1;
while (N > 1)
kq *= N--;
return kq;

© HĐC 2024.2 Chapter 1: Introduction 46


Supreme principle

“Keep it simple :
as simple as possible,
but no simpler”
- Albert Einstein

© HĐC 2024.2 Chapter 1: Introduction 47


1.5 Basic definitions

 Programming techniques relate to algorithms/ideas to solve a


class of respected problems, e.g.: “Divide and conquer” or
“program development by stepwise refinement”
 A programming paradigm is a style, or “way,” of programming.
Some languages make it easy to write in some paradigms but not
others.
 A Programming style is a set of guidelines used to format
programming instructions. It is useful to follow a style as it makes
it easier for programmers to understand the code, maintain it, and
assists in reducing the likelihood of introducing errors.
 Programming culture
 Programming activities, usually relates to programming languages
 A combination of programming model, style and techniques
 Programming ethics as well as the way software is used
 A Programming language is basically a set of instructions which
allows to communicate commands to a computing machine. Using
a programming language we can control the behavior of a
machine and automate processes.

© HĐC 2024.2 Chapter 1: Introduction 48


Programming techniques

Programming technique: The technique is used to


implement a software solution (data structure and
algorithm) based on a methodology and one or a few
programming languages suitable with the requirements
of a specific application.

Programming technique Analysis & Design

© HĐC 2024.2 Chapter 1: Introduction 49


Programming Paradigms

Sequential programming
Structured programming
Modular programming
Object-oriented programming
Generic programming
Component-based programming
Real-time programming

© HĐC 2024.2 Chapter 1: Introduction 50


Sequential programming

The most classical method, listing sequential commands,


low abstraction
The operation flow is controlled by performing jumping
instruction, or including subroutines
Examples:
 Machine code
 ASSEMBLY
 BASIC
 IL (Instruction List), STL (Statement List)
 LD, LAD (Ladder Diagram

© HĐC 2024.2 Chapter 1: Introduction 51


Sequential programming

Example: Machine Code


 Only logic operations with 1 and 0 bits
 Used at early stage of computers
 Too complicated and impossible to deal with big problems!!!

23fc 0000 0001 0000 0040


0cb9 0000 000a 0000 0040
6e0c
06b9 0000 0001 0000 0040
60e8

© HĐC 2024.2 Chapter 1: Introduction 52


Sequential programming

Example: Calculating the factorial of a positive integer n


in Assembly
1: MOV AX, n
2: DEC n
3: CMP n,1
4: JMPI
5: MUL AX, n
6: JMP 2
7: MOV n, AX
8: RET

© HĐC 2024.2 Chapter 1: Introduction 53


Sequential programming

Strengths:
 Simple thinking
 Low-level abstraction, easy to manage resources
 May be high efficient
 Appropriate to small problems or in embedded system
Weakness:
 Difficult to read, thus easy to make mistakes
 Difficult to reuse
 Low effectiveness
 Not suitable to large-scale applications

© HĐC 2024.2 Chapter 1: Introduction 54


Structured programming

Data is structured as data types, and the programs are


also structured to avoid jumping instructions
Analysis and design with top-down approach
Implementation with bottom-up approach
Structured programming use sequential operations,
selection instruction (if then else), loop (while), and
escape (exit)
Examples:
 PASCAL, ALGO, FORTRAN, C, …
 SFC (Sequential Function Charts)
 ST (Structured Text)

© HĐC 2024.2 Chapter 1: Introduction 55


Structured programming

Example: Calculating the factorial of a positive integer n


in PASCAL

© HĐC 2024.2 Chapter 1: Introduction 56


Structured programming

Example: Student management application

© HĐC 2024.2 Chapter 1: Introduction 57


Modular programming

It is an improvement of Structured Programming. The


program is built with more strict structure, and the unit
of program structure is a module
Module:
 An independent unit which has been standardized to establish a
system
 Each module includes an interface (exposed) and an
implementation (hidden)
 The modules communicate with each other via their intefaces
Examples:
 Modula-2, based on PASCAL and designed by Niclaus Wirth in
1977

© HĐC 2024.2 Chapter 1: Introduction 58


Object-oriented programming

 It programming paradigm based on the concept of "objects",


which can contain data and code: data in the form
of fields (often known as attributes or properties), and code,
in the form of procedures (often known as methods).
 3 principles:
 Data encapsulation
 Subtyping/inheritance
 Polymorphism
 Examples:
 C++, C#, Ojective-C
 Java
 Python
 MATLAB
 …

© HĐC 2024.2 Chapter 1: Introduction 59


Object-oriented programming

Example: Student management application

© HĐC 2024.2 Chapter 1: Introduction 60


Object-oriented programming

Example: Matrix calculation in MATLAB

// read the input u

// return output y

© HĐC 2024.2 Chapter 1: Introduction 61


Generic programming

Generalizing whatever possible to introduce a solution


template for a class of specific programs
Strength:
 Reduce source codes
 Increase the reusability of software
 Can be combined with other programming paradigms
 Interchangeability
Generalization approaches:
 Data types
 Basic operations
 Data structures
 Memory management, etc.

© HĐC 2024.2 Chapter 1: Introduction 62


Generic programming

Example: Mathematical structures

© HĐC 2024.2 Chapter 1: Introduction 63


Component-based programming

Software development is based on available “IC”


components or created ones
Evolved from object oriented programming
Most of Windows and Internet applications are built with
this paradigm
Examples:
 C/C++, C#
 Delphi, Visual Basic
 Script, HTML, XML, …

© HĐC 2024.2 Chapter 1: Introduction 64


Real-time programming

 Software development with real-time responsive to the


system, especially control systems in manufacturing,
robotics, unmanned vehicles, etc.
 Properties:
 Competitive programming (multi-tasking, multi-threading)
 Event driven
 Scheduling mechanism
 Synchronization
 High efficiency
 Languages: ASM, C/C++, ADA, etc
 Needs the support of
 Operating systems
 Hardware platforms
 Communication networks

© HĐC 2024.2 Chapter 1: Introduction 65


1.6 Software development process

PROBLEM ? SOLUTION REAL LIFE

Analysis Coding
Testing

ANALYSED DESIGN DESIGNED


MODEL MODEL WORLD

© HĐC 2024.2 Chapter 1: Introduction 66


1.6 Software development process

© HĐC 2024.2 Chapter 1: Introduction 67


1.6 Software development process

© HĐC 2024.2 Chapter 1: Introduction 68


Programming steps

© HĐC 2024.2 Chapter 1: Introduction 69


Waterfall model

 Requirements – defines needed


information, function, behavior,
performance and interfaces.
 Design – data structures, software
architecture, interface
representations, algorithmic
details.
 Implementation – source code,
database, user documentation,
testing.
 Deployment – installation and
operation
 Maintenance – patching and
upgrading

© HĐC 2024.2 Chapter 1: Introduction 70


Agile model

© HĐC 2024.2 Chapter 1: Introduction 71


Waterfall model vs. Agile model

Waterfall model Agile model


Client input is required only after completing each Client input is required throughout the product
phase. development.

Changes cannot be made after the completion of a


Changes can be made at any stage.
phase.

Coordination is not needed as one team starts the work Coordination among project teams is required to
after the finish of another team. ensure correctness.

It is mainly used for small project development. It is really useful in large and complex projects.

Testing can only be performed when the complete The testing part can be started before the development
product is ready. of the entire product.

It takes more time compared to Agile. It completes the project in comparatively less time.

It is quite rigid. It is more flexible.

Hardly any test plan is discussed during a cycle. After each sprint/cycle test plan is discussed.

© HĐC 2024.2 Chapter 1: Introduction 72


Developing tools / environment

IDE (Integrated Development Environment)


 Support the whole process of programming
 E.g.: MS Visual Studio, Borland C++ (Builder), Keil-C
Tools
 Editor
 Compiler
 Linker
 Loader
 Debugger
 Project manager

© HĐC 2024.2 Chapter 1: Introduction 73


Compiler

 A compiler is a computer
program that translates
computer code written in one
programming language (the
source language) into another
language (the target language).
 The name "compiler" is
primarily used for programs
that translate source code from
a high-level programming
language to a lower level
language (e.g., assembly
language, object code, or
machine code) to create an
executable program
 Example: C, C++, C#, Java,
COBOL, Go

© HĐC 2024.2 Chapter 1: Introduction 74


Interpreter

An interpreter is a computer


program that directly executes
instructions written in a
programming or scripting
language, without requiring
them previously to have been
compiled into a machine
language program
It does not generate an object
program
Example: JavaScript, Matlab,
Python, BASIC

© HĐC 2024.2 Chapter 1: Introduction 75


Design Diagrams

Flow Chart
 Flow Charts used shapes to present a
program/algorithm
o Start/End
o Process
o Decision
o Data…
 Disadvantages
o Used only for small applications
o Modification and drawing are time-consuming
o Unstructured code is difficult to maintain

© HĐC 2024.2 Chapter 1: Introduction 76


Design Diagrams – Flowchart revision

Symbols are defined in ISO 5807:1985


ANSI/ISO Shape Name

Flowline (Arrowhead)

Terminal

Decision

Input/Output

Predefined Process

Annotation (Comment)

On-page Connector

Off-page Connector

© HĐC 2024.2 Chapter 1: Introduction 77


Design Diagrams – Unified Modeling Language (UML)

© HĐC 2024.2 Chapter 1: Introduction 78


Design Diagrams – Unified Modeling Language (UML)

UML usecase diagram

© HĐC 2024.2 Chapter 1: Introduction 79


Design Diagrams – Unified Modeling Language (UML)

Class Diagram

© HĐC 2024.2 Chapter 1: Introduction 80


Design Diagrams – Unified Modeling Language (UML)

Sequence Diagram

© HĐC 2024.2 Chapter 1: Introduction 81


Design Diagrams – Unified Modeling Language (UML)

State (transition) diagram

Read more in Miles, R., & Hamilton, K. (2006). Learning


UML 2.0. O'Reilly Media, Inc..

© HĐC 2024.2 Chapter 1: Introduction 82


Pseudo Code

Disadvantage of the graphical design method


 Time consume
 Not easy to modify
Pseudocode: a kind of structured language (English)
 Describe the operation of an algorithm
 Concentrate on the development of an algorithm
Some features
 No fixed rule or standard or style for developing
 Pseudocode uses English sentences or keywords
 Cannot be compiled
Still have guidelines to develop pseudocode
 Sequencing, Selection, Iteration

© HĐC 2024.2 Chapter 1: Introduction 83


Pseudo Code

Example:

© HĐC 2024.2 Chapter 1: Introduction 84


1.6 Fundamentals of C/C++ languages

 A programming languages is a way of using symbols


and rules, by which a programmer “dictates” a device.
 Syntax: the grammar and structure ofthe code
 Semantics: the meaning and logic of the code
Two types of programming language
 Low-level: assembly, machine languages
 High-level: C/C++, Python, LabView, …

© HĐC 2024.2 Chapter 1: Introduction 85


1.6 Fundamentals of C/C++ languages

A language is called a programming language only when


it is “Turing Complete”, i.e., do what UTM can do:
UTM can solve any computational problem.Make
decisions based on what it sees in memory
 Run forever
 Use infinite memory
 Has random access memory
 Simulate any other Turing machine

As a programming language can do what UTM can do


→ All programming languages can do exactly the same thing

© HĐC 2024.2 Chapter 1: Introduction 86


1.6 Fundamentals of C/C++ languages

Key features/concepts of all programming languages


 Syntax: The specific rules and structure used to write code
 Data Types: The type of values that can be stored in a program
 Variables: Named memory locations that can store values
 Operators: Symbols used to perform operations on values
 Control Structures: Statements used to control the flow of a
program
 Libraries and Frameworks: Collections of pre-written code
that can be used to perform common tasks and speed up
development
 Paradigms: The programming style or philosophy used in the
language, such as procedural, object-oriented, or functional.

© HĐC 2024.2 Chapter 1: Introduction 87


Programming languages ranking

2021 2022

https://spectrum.ieee.org/top-programming-languages-2021 https://spectrum.ieee.org/top-programming-languages-2022

© HĐC 2024.2 Chapter 1: Introduction 88


Programming languages ranking

https://spectrum.ieee.org/the-top-programming-languages-2023

© HĐC 2024.2 Chapter 1: Introduction 89


Programming languages ranking

https://spectrum.ieee.org/the-top-programming-languages-2023

© HĐC 2024.2 Chapter 1: Introduction 90


Programming languages ranking

https://spectrum.ieee.org/the-top-programming-languages-2023

© HĐC 2024.2 Chapter 1: Introduction 91


1.6 Fundamentals of C/C++ languages

C:
 At Bell Labs by Dennis Ritchie between 1972 and 1973 for
Unix.
 K&R C (Brian Kernighan and Dennis Ritchie) in 1978
 During the 1980s, C gradually gained popularity, many C
compilers
 Standardized by the ANSI since 1989 (ANSI C - American
National Standards Institute) and by the International
Organization for Standardization.
 Newest release C18 (ISO/IEC 9899:2018)
 Next version C2x
 Embedded C Thomson,
Ritchie,
& Kernighan

© HĐC 2024.2 Chapter 1: Introduction 92


1.6 Fundamentals of C/C++ languages

C++:
 Bjarne Stroustrup’s “C with Classes” at
Bell Labs in 1979
 C++ in 1982

https://www.stroustrup.com/
 First commercial implementation in 1985
 In 1998, C++ started to be standardized as C++98 (ISO/IEC
14882:1998)

 Newest release C++17 (ISO/IEC 14882:2017)


 Next version C++20

© HĐC 2024.2 Chapter 1: Introduction 93


Why C/C++

 Features:
 Close to hardware
 High efficiency
 Relatively user-friendly to developers
 Interchangeable
 International Standardization
 Strength of ANSI-C
 Popular in most of microprocessor, microcontroller, DSP
 Popular to world-wide developers
 Strength of ANSI/ISO C++:
 Object-oriented programming
 Generic programming (template)
 Mathematical programming (Data Abstraction and Operator
Overloading)

© HĐC 2024.2 Chapter 1: Introduction 94


“C makes it easy to shoot
yourself in the foot;
C++ makes it harder, but
when you do it blows your
whole leg off.”
― Bjarne Stroustrup

© HĐC 2024.2 Chapter 1: Introduction 95


END OF CHAPTER 1

You might also like