0% found this document useful (0 votes)
81 views44 pages

C/C++ Programming Techniques: ET2031 / ET2031E

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 44

C/C++ Programming Techniques

ET2031 / ET2031E

1
Course overview
Overview

• Course:
• Course: C/C++ Programming techniques
• Course code: ET2031 2(2-0-1-4)
• Teams code: ......
• Instructor
• PhD. Đỗ Thị Ngọc Diệp
• Communication Engineering Faculty – SEEE – HUST
• Speech Communication Department – MICA Institute
• Email: diep.dothingoc@hust.edu.vn

3
Course syllabus

Week Lecture
1-2 Introduction, basic concepts
3 Excercise
4 Arrays and Pointers
5-6 Function Oriented Programming
7 Excercise
8 Data structure
9-10 Object-Oriented Programming
11 Excercise
12 Inheritance
13 Standard Template Library
14 Other techniques
15-16 Project presentation
Requirements for students

• Attend all the classes.


• Self-study and master the programming language.
• Follow the programming style: use comments, indentation, clean
code, etc. These styles will be required for weekly exercise, projects,
examination.
• Practice:
• Complete the weekly exercises, assignments on Teams.
• Complete the Big project.

5
Textbooks and References

• Textbooks
• [1] Nguyễn Thanh Bình, Nguyễn Hoài Giang. Ngôn ngữ lập trình C và Cấu
trúc dữ liệu. NXB Giáo Dục 2017.
• [2] Nguyễn Việt Hương. Ngôn ngữ lập trình C++ và cấu trúc dữ liệu. NXB
Giáo dục, 2000.
• References
• [1] Lê Đăng Hưng, Tạ Tuấn Anh, Nguyễn Hữu Đức, Nguyễn Thanh Thủy.
Lập trình hướng đối tượng với C++. NXB Khoa học kỹ thuật, 2006.
• [2] Trần Văn Tư, Nguyễn Ngọc Tuấn. 450 bài tập về lập trình C++. NXB
Thống kê, 2000.
• [3] C++ & Lập trình hướng đối tượng, GS. Phạm Văn Ất, NXB KH&KT
• [4] The C Programming Language – 2nd Edition, Brian W. Kerninghan &
Dennis M. Ritchie, Prentice-Hall,1988
• [5] The C++ Programming Language – 4th Edition, Bjarne Stroustrup,
Addison-Wesley, 2013
• Other programming languages

6
Reference

• Online tutorials
• Interactive learning
• Advanced topics

https://www.learn-c.org/

7
Course Evaluation

• Process grade: 30% of final grade


• Combination of Exercise at class, Assignment on Teams, Big
Project grades.
• Final examination grade: 70% of final grade

8
Introduction

9
Content

• Computer software development progress


• Computer development history
• Computer architecture
• Software development progress
• Software Programming
• General concepts
• Programming technique
• Programming languages
• Programming paradigms
• C/C++ introduction
• History of the C++ language
• Why C/C++
• Tools

10
I. Computer software development progress

11
Computer development history

ENIAC (Electronic Numerical


• 1940s Integrator And Computer)

• electronic lights, switches


for programming
• 1950s
• early transistorized
computer
• FORTRAN, COBOL
• 1965
• IC: Integrated Circuit
• 1972
• microprocessor

12
Computer development history

Src: Microsoft Educator Community

13
Computer architecture

• Hardware

https://www.techsignin.com

14
Computer architecture

• Software & Operating System

https://www.youtube.com/watch?v=5AjReRMoG3Y

15
Computer architecture

• Operating System:
• is a system software
• Allows users to manipulate:
• computer hardware
• external device
• run application software (Executive programs)

https://www.youtube.com/watch?v=5AjReRMoG3Y
https://sensorstechforum.com 16
Executive programs – Machine code

• CPU:
• Read/Write to memory Memory
• Perform math operations, etc. CPU

• Executive program (exe):


• List of instructions for the computer to
process
• Computer only understands binary code 0 / 1
• Executive program is in binary (machine code)
• The computer's internal memory holds
both data and program's instructions at
runtime.

17
How do computers read code - Compiler

• Program to convert source code (by


human) into machine code
Programming language

How do computers read code?


Frame of Essence
https://www.youtube.com/watch?v=QXjU9qTsYCc

18
Compile source code into binary


in binary

19
… and run the binary

in binary
in hexadecimal assembly code

do the correct
action in the memory

Memory location

20
Program error

• Testing: is the process of checking the functioning of software features


• Debugging: is the process of finding the cause of an error, and fixing it
• Syntax error (compiler error):
• By writing a program that does not follow the prescribed syntax
• Detected by the compiler
• Note: sometimes the error is not detected because it is misinterpreted to another syntax
• Run-time error:
• When the program runs in violation of the allowed conditions
• Detected while running
• Logical error: Because the algorithm is wrong, computer can not detect

21
Software development process

• Software lifecycle:
• Analysis of the requirements of the problem
(analysis + define requirements)
• Software design (design)
• Building the product (develop)
• Coding/ Programming (source code)
• Testing, Debugging
• Documentation
• Deployment in reality (machine code)
• Maintenance, update and further development
• Out-of-date
https://www.javatpoint.com

22
II. Software Programming

23
General concepts

• Software • Software: set of programs.


• Program • Program: an ordered sequence of instructions to solve a
• Algorithm certain problem, written in a certain programming language.
• Data • Algorithm: a group of operations and calculations that need
to be performed correctly so that after a finite number of
steps we can achieve the desired result.
• Data: represent the necessary information for the problem
under the appropriate structure.
• Input data: data that needs to be input initially for
processing
• Intermediate data: contains intermediate results during
processing.
• Output data: contains the desired result of the problem.
• Algorithm performs the transformation from input data to
output data.

24
General concepts

• Primitive/atomic • Primitive/atomic data:


data • indivisible base data element
• Structural data • can be a digit, a character, a number, etc.
(data structure) • Structural data : ways to link atomic data together
• Programming • character string
• one-dimensional array
• two-dimensional array
• More complex: linked list, tree, graph, etc.
• Programming:
• Select an appropriate data structure, on which to build an
effective processing algorithm
• Choosing a data structure must consider the operations
that act on that data structure,
• in contrast, when considering the operation, pay attention
to which data structure the operation affects.

25
Programming technique

• Programming • Programming techniques: A technique to implement a


techniques software solution (data structure + algorithm) on the basis of a
• Programming methodology and one (or more) programming language(s) in
language accordance with the specific requirements of application
• Programming • Programming language
paradigms • A standardized language
• Both humans and computers can read and understand
• Use the corresponding compiler to compile the entire
source program into machine code before execution
• Each programming language has predefined data structures.
• Methodology/paradigms
• Imperative programming
• Structural/ Functional programming
• Object-Oriented programming
• Event-driven programming

26
Programming languages

• Development process:
• Machine language: direct use of binary code, no need to compile, depends on
the processor.
• 2nd generation (assembly language): need to compile, readable, depends on
the processor.
• 3rd generation (high level language): control structures, data types,
encapsulation. (Fortran, C, C++, Java and JavaScript,…)
• 4th generation: improve efficiency such as reducing
error-prone elements, syntax closer to spoken
language. (SQL, Perl, Python,…)
• 5th generation: use visual tools to
develop a program. (Mercury, Prolog)

http://btechsmartclass.com
27
Programming languages

28
Imperative programming

• Typical: assembly
• The program consists of a set of instructions that are executed sequentially
(from top to bottom)
• Does not show structure, poorly supports modularization
• Difficult to solve complex problems

Assembly language
Structural programming

• Typical: C, C++, Fortran


• Describe step-by-step the programs needed to solve a problem
• Allows modularization, partial reuse of code
• The effectiveness of this method depends mainly on the programmer
Object-oriented programming

• Typical: C++, Java


• Programs are a collection of classes and objects that interact with each other.
• This model is relatively close to problems in life.
• Improve security, inheritance, reusability, and flexibility and generality of the
program
Object-Oriented Technology

• Object-oriented technology (OOT) is a set of rules (including abstraction,


encapsulation, inheritance, polymorphism), and instructions for building
software, along with programming language, database, and other tools that
support these rules.
• OOT usage ?
• Client/Server system, Web system
• Embedded system
• Real-time system
• General software system
• etc.

32
Event-driven programming

• Typical: JavaScript, Java, Python ...


• Describe the events that can occur in the system, how to detect them, and
set up the sequence of steps to respond to those events.
• towards handling events that may arise during the operation of a
software.
• Can be combined with other programming paradigms (object-oriented,
procedural)
• Often used in solving problems that require a lot of Human-Machine or
Machine-Machine interaction.
• Allows interaction (quickly) with users, with other devices, etc.
III. C/C++ introduction

34
History of the C language

• Born in the 1970s, associated with the development of the Unix OS.
• Author: Dennis Ritchie (Bell Laboratories)
• Target:
• Enhancing efficiency
• Capable of accessing low-level hardware, capable of direct memory access
• Structured languages (instead of programming in assembly language)
• Short syntax, few keywords
• No hardware dependency
• Structures, functions, encapsulation, etc.

35
History of the C++ language

• Born in 1979 by extending the C language


• Author: Bjarne Stroustrup
• Target: Add new features
• Overcoming some disadvantages of C
• Added new features compared to C:
• Object Oriented Programming (OOP)
• General programming (template)
• Many small features make programming more flexible (add bool type,
declare variable anywhere, strong type, define method overloading,
namespace, exception handling, ...)

36
C-based languages

• C++ includes all features of C, but adds classes and other features to support
object-oriented programming
• Java: is based on C++ and therefore inherits many C features
• C#: is a more recent language derived from C++ and Java
• Perl: is originally a fairy simple scripting language and overtime it has grown
and adopted many of the features of C

37
C Compiler and linker

http://btechsmartclass.com

https://teaching.csse.uwa.edu.au/units/CITS2002/lectures/lecture02/03.html
38
Why choose C/C++

• Advantage:
• efficient, flexible, stable
• widely supported on different environments
• many libraries and tools available
• wide range of applications: on server, embedded system, OS, etc.
• original language, making learning other programming languages easy
• Defect:
• Language [too] complicated
• Error control is more difficult than in high-level languages (Java, .NET, scripts,
etc.), especially due to the use of pointers

Src image: http://www.atnyla.com/tutorial/features-of-c/1/157 39


Tools

• LINUX/Ubuntu Text editor

vi, vim gedit

Write code
Write code

Compile
Compile
Run
Run

40
Tools

• LINUX/Ubuntu
• IDE
• Interface

41
Tools

• Windows
• Editors: Notepad++/Visual Studio Code + C/C++ extension
• Compilers: Cygwin/MinGW
• IDE: Codeblocks/Visual Studio Community/Netbeans/Eclipse/Dev-C

require several environment


variables
http://www.codeblocks.org/

Walkthrough: Compile a C program on the command line:


https://msdn.microsoft.com/en-us/library/bb384838.aspx

42
Tools

• Online C compiler on browser


• OnlineGDB C Compiler
• Tutorialspoint Compiler
• Etc.

43
• https://www.youtube.com/watch?v=YOLN-t09-tM
• https://www.youtube.com/watch?v=rydtxg8gQz0

44

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