0% found this document useful (0 votes)
35 views37 pages

Chapter 1 Intro To CP

Uploaded by

Farhana
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)
35 views37 pages

Chapter 1 Intro To CP

Uploaded by

Farhana
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/ 37

COMPUTER PROGRAMMING

BDA 24202
DR. HO FU HAW
JKP, FKMP
E5-001-10
ABOUT THIS COURSE

• Lecture: 42 hours (14weeks x 3hours)


• Goals: To introduce students on programming development environment and
develop skills in writing programming applications useful for problem solving
using C language.
LEARNING OUTCOMES

• Engineering Knowledge - Apply the problem solving technique using algorithm and
construct the structure of program as awareness and basic understanding in
programming language. (C3, LO1, LOD1)
• Modern Tool Usage-Develop the program to solve problem using C language. (C4,
LO2, LOD9)
• Life Long Learning-Present the project findings in oral and written form for the
individual or group assignment (A2, LO6, LOD13)-Present the project findings in oral
and written form for the individual or group assignment (A2, LO6, LOD13)
CONTENTS
• 1.0 INTRODUCTION TO COMPUTER AND PROGRAMMING
• Introduction To Computer And Programming, Flow Chart and Pseudo Code.
• 2.0 THE STRUCTURE OF C LANGUAGE
• Introduction to C language, Basic C, Function Variable, Constant and Identifier, Data Types,
Pre-processor Directives.
• 3.0 INPUT AND OUTPUT DATA
• Input/Output String Processing, File Processing.
• 4.0 OPERATORS AND EXPRESSIONS
• Mathematical Operators, Conditional Operators, Relational and Logical Operators,
Assignment Operators.
• 5.0 CONTROL STATEMENTS
• Using control statement which includes if, for, switch, while loop, break, and goto.
• 6.0 ARRAYS
• Array, multidimensional array, pointer, string.
• 7.0 FUNCTIONS
• Definition, Accessing A Function, Function Types, Function Prototypes, Function Call
• 8.0 EMBEDDED SYSTEMS PROGRAMMING (2 hours)
• Concept of Embedded Systems Programming, Embedded Systems Interfacing, Design
Integration of Software and Hardware
ASSESSMENT

• Test 1: 15% (CLO1)


• Test 2: 15% (CLO1)
• Practical Assessment 1: 10% (2 programs) (CLO2)
• Practical Assessment 2: 10% (2 programs) (CLO2)
• Individual Assignment: 10% (CLO1, CLO2)
• Group project: 40% (CLO 1,2,3)
ATTENDANCE/REGULATIONS DURING LECTURE
• Students must attend not less than 80% (QR code attendance)
• Students who do not fulfill item 1 of the above are not allowed to attend further
lecture and sit for any form of assessment. Zero ‘0’ mark will be given to
students who fail to comply with item 1. As for HW course, students who fail to
comply with item 1 will be given Failure Attendance (HG) grade.
• Students should adhere to the dress regulations in effect and must discipline
themselves to avoid from any disciplinary actions.
REFERENCE
• Pal, M. (2013). C programming: including numerical and statistical methods, Oxford : Alpha Science. Call
number: QA76.7 .P34 2013
• McGrath, M. (2012). C programming in easy steps, Warwickshire. Call number: QA76.73 .M47 2012
• Horton, I. (2011). Beginning C: from novice to professional, Berkeley, CA. Call number: QA76.73.C15
.H67 2011
• Ling, H. C. (2009). C Programming for beginners, Kuala Lumpur: Prentice Hall, Call number:
QA76.73.C15 .C74 2009
• Wahab, S. H. (2009). Asas Pengaturcaraan C Bagi Beginner, Selangor: Venton Publishing. Call number:
QA76.73.C15 .S92 2009

• Stya, P. (2015). Programming in C, New Delhi: I K International Pvt Ltd. Call number:
QA76.73.C153.P72 2015
• Mike, M. (2012). C Programming in easy steps, Warwickshire: In Easy Steps. Call number: QA76.73.
M47 2012
WHY YOU NEED PROGRAMMING SKILLS?

• JOB REQUIREMENTS
• INDUSTRY REVOLUTION 4.0 (IoT, AI, Big Data, Embedded Engineering)
• HIGHER SALARY
• OTHERS.
CHECK HERE: TOP 10 PROGRAMMING LANGUANGES
EXAMPLES OF PROGRAMMING APPLICATIONS

CHECK HERE: EMBEDDED SYSTEMS PROGRAMMING


EXAMPLE PROGRAMMING LANGUAGE

• C/C++
• JAVA
• ALGOL
• PYTHON
• VISUAL BASIC
• FORTRAN
OFF-LINE AND ON-LINE C-COMPILER
HOW DO YOU WRITE A PROGRAM?

• Decide what steps are needed to complete the task


• Write the algorithm either steps in pseudocode (written in English)
or as a flowchart (graphic symbols)
• Translate into the programming language
• Try out the program and “debug” it (fix if necessary)
ALGORITHM
• A set of instructions for solving a problem, or, an ordered
sequence of unambiguous and well-defined instructions that
performs some task and halts in finite time (Al Kho-war-iz-mi a 9th
century Persian mathematician).
• Three categories of Algorithmic Operations:
sequential operations - instructions are executed in order
conditional (”question asking”) operations - a control structure that asks a
true/false question and then selects the next instruction based on the answer
iterative operations (loops) - a control structure that repeats the execution of
a block of instructions
EXAMPLE OF ALGORITHM:

• Given y = mx + c , develop an algorithm to obtain y.


Algorithm:
• Step 1: determine m value
• Step 2: determine x value
• Step 3: determine c value
• Step 4: y value can be obtained by insert m,x,c value into formula m*x+c
WHAT IS PSEUDOCODE?

• List of steps written in English


• Like the instructions for a recipe
• Must be in the right sequence
• Imagine saying “bake the cake” and then “mix it up”
RULES FOR PSEUDO CODE
1. Consist of a statement of instructions in sequence
2. Every step consists of keyword
3. Every step should be written in different step, if continued, the next
row must be indented
4. if/else for condition, while/do for repetition
5. Every step must contain clear statement and easy to understand
6. Use start for beginning of operation, and end/halt for finishing it.
SAMPLE PSEUDOCODE

• Task: add two numbers


• Pseudocode:
• Start
• Get two numbers, a and b
• C = a+b
• Display c value
• End
WHAT DOES A FLOWCHART LOOK LIKE?

• The pseudocode from the previous slide would look like this as a flowchart:

Start
Display c
Get number a
and b
End
C = a+b
WHAT ARE THOSE FUNNY SYMBOLS?

• START/END

• INPUT/OUTPUT

• PROCESS

• DECISION
• START/END Start

• Used at the beginning and


end of each flowchart.

End
• INPUT/OUTPUT
• Shows when
information/data comes
into a program or is
printed out.
• PROCESS
• Used to show calculations,
storing of data in
variables, and other
“processes” that take place
within a program.
• DECISION
• Used to show that the
program must decide
Y
whether something (usually X>7?
a comparison between
numbers) is true or false. N
YES and NO (or T/F)
branches are usually
shown.
FLOWCHART
DO…WHILE LOOP IN WHILE….LOOP IN
PSEUDOCODE PSEUDOCODE
1. GET X 1. GET X
2. DO 2. WHILE (X<20)
Y= X + 2 Y= X + 2
WHILE (X<20) 3. DISPLAY Y
3. DISPLAY Y 4. END
4. END

Y= X +2
X<20

X<20
Y=X+2
EXERCISES 1.0:
• Develop a flow chart of y=(x+y)*(z+y) numbers, and convert the
flowchart into pseudo code
• Develop a flow chart to decide if no rain you will come to class by
bicycle, else you will come to class by bus.
• Develop a flow chart to evaluate z, if x=12y, z=x+5.
• Develop a flow chart to score marks for your individual and group
project to enable you to get at least grade B+ in C-Programming
course (assuming you obtain 10% in both test 1 and test 2, 8% in
both lab test 1 and 2, Individual project: unknown, group project:
unknown)
EXERCISE 2.0:
• Computing Weekly Wages: Gross pay (Y) depends on the pay rate
and the number of hours worked per week. However, if you work
more than 40 hours, you get paid 1.5 rate for all hours worked over
40. Assume pay rate/hour = RM5, X = total hour(s).
a. Develop a flow chart to display above weekly wages calculation.
b. Construct the Pseudo-code based on the developed flow chart.
LOOPS

• A loop is a repetition of all or part of the commands in a program.


• A loop often has a counter (a variable) and continues to repeat a specified
number of times.
• A loop may also continue until a certain condition is met (e.g., until the end of
a file or until a number reaches a set limit)
EXERCISE 3.0:

• Draw a flowchart to find all values of y= 5x +x2 for x =0 to 2. The increment


of x is 0.2.
EXERCISE 4.0:
DEVELOP A FLOW CHART FOR BELOW FUNCTION

2𝑥 + 5 ; 𝑥 ≤ 5
𝑓 𝑥 =
12𝑥 + 𝑥 2 ; 𝑥 > 8
EXERCISE 5.0:

 x 2  3x + 2 for 0  x < 1.5


f (x) =  x-4  x+1 for 1.5  x < 3.0
 2x + 5
 for 3  x < 5.0

 Log10 x 2  1 
• If a long x = 0 to x = 5.0, let define xi, i = 1, 2, 3, …., N. where
dx is distance between two successive point xi and xi+1 is equal to
0.01+x.

• Write the flowchart and pseudocode, so the program will find the
maximum value of f(x)
EXERCISE 6.0:
PLEASE DRAW THE FLOW CHART AND PSEUDO CODE
FOR BELOW CASE
• If projectile with initial velocity u (m/sec) is fired at angle θ(with horizontal),
then the horizontal range R is given by R =u2sin 2θ/g where g =9.81 m/sec2.
Draw a flowchart to compute each value of R when u varied from 20-150
m/s and 400 to 500 m/s at θ=50° .
EXERCISE 7.0:
DEVELOP A FLOW CHART FOR BELOW CASE:
• A ball was dropped from a 100m tall building, the initial speed U is 10 m/s.
The acceleration of ball is R= 2UHg/5, H is the height of building, g is the
gravity. Draw a flow chart to determine the acceleration of ball
a. height H= 90m
b. 70m<H<65m
QUESTION?

•THANK YOU……..

You might also like