ELEX 2125
ELEX 2125
C Programming for Electronics
This course is an introduction to C programming
and software development. The course focuses on
structured program development using the C
language. Students will also learn to document
code, debug programs and utilize software libraries.
The lecture handouts include references to the
textbook: C How to Program by Deitel & Deitel,
Pearson (abbreviated as Deitel & Deitel).
These lecture handouts were prepared by Joselito
Laguio, Instructor (abbreviated as JL)
JL
1
ELEX 2125
Tips in the Textbook
Important for this course:
Good programming practices
Common programming errors
Error-prevention tips
Software engineering observations
Not important for this course:
Performance tips
Portability tips
JL
2
ELEX 2125
Logical units of a computer:
Input
Output
Memory
Arithmetic Logic Unit
Central Processing Unit
Secondary storage
JL
3
ELEX 2125
Programming Languages
High level vs low level language
Machine Language – (Machine Code) low level
language using bits
Assembly Language – low level language for a
specific type of processor
Assembler – converts assembly code to
machine code
Compilers – converts instructions to machine
code
IDE – Integrated Development Environment
includes editor, compiler, debugger
Interpreter – directly executes instructions or
converts to an intermediate form (not
machine code)
JL
4
ELEX 2125
C - general-purpose programming language,
structured programming, subset of C++
C++ – operating systems, browsers, games
C# – (C Sharp) developed by Microsoft, similar
to Java
Python – fastest growing, easy to learn
JavaScript – behind much of the web: plugins,
websites
Java – used for databases, Android apps,
“backend” programming language for the
web, desktop apps
JL
5
ELEX 2125
Steps in the development of a computer
program
1. Define the problem
Thorough understanding
Factors: input/output, processing
requirement, memory requirements, error
handling, interface with other programs
2. Design the program
Algorithm
Flowchart
Pseudocode
3. Write the code
Computer language
4. Debug the code
5. Test the code
Trivial and special cases
Test data max and min values
JL
6
ELEX 2125
6. Documentation
For maintenance
For ease of future modification
For redesign
7. Maintenance
Update and correction
Field experience
* The steps may be iterative
JL
7
ELEX 2125
Steps in Development of a C program
1. Create program using an editor
2. Preprocessing
3. Compiling
4. Linking
5. Loading
6. Execution
JL
8
ELEX 2125
Flowchart (action oriented)
A flowchart is a graphical method for
presenting an algorithm.
Symbols
Flow line – directs the flow from action to
action
Terminator – marks the beginning and end of
flowchart. Two terminators per flowchart.
JL
9
ELEX 2125
Process – can be one or more actions
Input/output – parallelogram
Decision – rhombus, diamond
JL
10
ELEX 2125
Connector
Rule 2 flow lines in and one flow line out
Function call (covered later in the course)
JL
11
ELEX 2125
Only three forms of control are needed in
structured programming:
1. Sequence (stepping)
2. Selection (decision-making)
3. Iteration (repetition or looping)
JL
12
ELEX 2125
Exercises
1. Converts assembly language to machine language
_________
2. A computer can directly understand its own _______
language
3. Programs that directly execute high-level language
programs without compiling are called __________
4. A translator program that converts high-level language
programs into machine language is called a
__________
5. A __________ links the object code with the code for
the missing functions to produce an executable image.
6. A graphical representation of an algorithm is called a
__________
JL
13