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

Computer Programming BDA 24202: Prepared By: Dr. Ho Fu Haw

Uploaded by

muhdfaridmfd0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Computer Programming BDA 24202: Prepared By: Dr. Ho Fu Haw

Uploaded by

muhdfaridmfd0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

COMPUTER PROGRAMMING

BDA 24202

Prepared by: Dr. Ho Fu Haw


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
• Concept of Embedded Systems Programming Embedded Systems Interfacing, Design
,

Integration of Software and Hardware


ASSESSMENT

• Test 1: 20% (CLO1, Chap1-4)


• Test 2: 20% (CLO1, Chap 5-7)
• Individual Assignment: 20% (CLO1, CLO2: Problem Based Learning)
• Group project: 40% (CLO 1,2,3: Complex engineering problem 3-4 members
per group)
ATTENDANCE/REGULATIONS DURING LECTURE
• Students must attend not less than 80% (Online 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
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 or code
• 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
whether something (usually Y
X>7?
a comparison between
numbers) is true or false. N
YES and NO (or T/F)
branches are usually
shown.
FLOWCHART SYMBOL SUMMARY
FLOW CHART EXAMPLES
LOOPS- ITERATION (REPETATION)

• 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)
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+2)*(z+3) 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=12, z=x+5.
DEVELOP A FLOW CHART OF Y=(X+2)*(Z+3) 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=12, z=x+5.
EXERCISE 2.0:
• Computing Weekly Salary: Gross pay (Y) depends on the pay rate
and the number of hours (X) worked per week. However, if you work
more than 40 hours, you will 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 salary calculation.
b. Construct the Pseudo-code based on the developed flow chart.
Start Pseudo Code:

1. Start
Get 2. Get Hours (X)
Hour(X) 3. If X>40
Y=Y=(40*5)+(X-40)*5*1.5
else
No
Y=X*5
X>40 Y=X*5 4. Display Y
5. End
yes

Y=(40*5)+(X-
40)*5*1.5

Display Y

End
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.
Start Pseudo Code:

1. Start
X=0 2. X=0
3. If x<=2;
X=X+0.2 Y=5*x+(x*x);
X=X+0.2;
No Display y;
X<=2 else
Display Y;
yes 4. End

Y=5*x+(x*x)

Display Y

End
EXERCISE 4.0:
DEVELOP A FLOW CHART FOR BELOW FUNCTION

2𝑥𝑥 + 5 ; 𝑥𝑥 ≤ 5
𝒇𝒇 𝒙𝒙 = �
12𝑥𝑥 + 𝑥𝑥 2 ; 𝑥𝑥 > 8
Start Pseudo Code:

1. Start
Get X 2. Get X
3. If x<=5;
f(x)=2*x+5;
display f(x);
X<=5 f(x)=2*x+5 elseif
yes x>8;
No f(x)=12 ∗ 𝑥𝑥 + x ∗ x;
display f(x);
else
X>8 f(x)=12 ∗ 𝑥𝑥 + x ∗ x End
yes 4. End
No
Display
f(x)

End
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 + 1
2
)
• If a long x = 0 to x = 5.0, the increment is of x = x+0.5
• Write the flowchart to display all x value.
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° .
Start • If projectile with initial velocity U
(m/sec) is fired at angle θ(with
G=9.81; θ=0; R=0; U=0 horizontal), then the horizontal range
R is given by R =u2sin 2θ/g where g
No =9.81 m/sec2. Draw a flowchart to
θ=50 compute each value of R when U
varied from 20-150 m/s and 400 to
yes
yes 500 m/s at θ=50° .
20<=U>=150 R =u2sin 2θ/g

No

400<=U>=500 R =u2sin 2θ/g

Display R
End
QUESTION?

•THANK YOU……..

You might also like