Lecture 01
Lecture 01
Programming
2
Dishonesty, Cheating in Quizzes,
Assignments & Presentations
• Copying material in any form (code or otherwise) is not allowed.
• This will still be cheating even if you try to substitute or restructure
words, structures, phrrases.
• You can always discuss to solve problem with your colleagues
however you should not copy code.
• Penalty can be a zero in that and one other assignment on to a penalty
of an F in the course.
3
Assignment = 20% Last two assignments
will be CCP
•5
Application Software:
Refers to programs that make the computer Software refers to the
useful to the user. These programs solve programs that runs on a
specific problems or perform general computer.
operations that satisfy the needs of the user.
A Programming Language is a
special language used to write
a computer program
Programming Process
• Design
• Create
• Test
• Debug Example:
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values for num1, num2.
Step 4: Add num1 and num2 and assign the result to a variable sum.
Step 5: Display sum
Step 6: Stop
Algorithm (example #2)
Read the Value of number1 and number2.
SUM = number1+number2.
Display SUM.
Stop.
Pseudocode
Start/Begin
Declare two numbers (number1 and number2)
Assign value to number1
Assign value to number2
Compute number1+number2
Display result
end
Flowcharts
• Flowcharts is a graph used to show a step by step solution using symbols
which represent a task.
• The symbols used consist of geometrical shapes that are connected by
flow lines.
• It is an alternative to pseudo coding; whereas a pseudocode description
is verbal, a flowchart is graphical in nature.
28
Flowchart symbols
Symbols Purpose Description
PRINT PRINT
“PASS” “FAIL”
STOP
Example 2
• Write an algorithm and draw a flowchart to convert the length in feet
to centimeter.
Pseudocode:
• Input the length in feet (Lft)
• Calculate the length in cm (Lcm) by multiplying LFT with 30
• Print length in cm (LCM)
Example 2
Flowchart
Algorithm
• Step 1: Input Lft START
Print
Lcm
STOP
Example 3
Write an algorithm and draw a flowchart that will read the two sides
of a rectangle and calculate its area.
Pseudocode
• Input the width (W) and Length (L) of a rectangle
• Calculate the area (A) by multiplying L with W
• Print A
Example 3
Algorithm START
• Step 3: Print A
ALxW
Print
A
STOP
Flowchart – sequence control structure
Statement 1
Statement 2
Statement 3
36
Flowchart – selection control structure
No Yes
Condition
else- then-
statement(s) statement(s)
37
Flowchart – repetition control structure
yes Loop
Condition
Statement(s)
no
38
Flowchart – example
Begin
Calculate
Age = current year – birth date
Display
age
End
39
Flowchart – example
Begin
Read age
End
40
Flowchart – example
Begin
sum = 0
current_number = 1
NO
current_number <= 10? print sum
YES
End
sum = sum + current_number
current_number = current_number + 1
41
Exercises: Algorithm & Flowchart
1.) Create an algorithm and a flowchart that will accept/read two numbers
and then display the bigger number.
2.) Create an algorithm and a flowchart that will compute the sum of two
numbers. If the sum is below or equal to twenty, two numbers will be
entered again. If the sum is above 20, it will display the sum.
3.) Create an algorithm and a flowchart that will output the largest number
among the three numbers.
Reference:
Tony Gaddis, “Starting out with C++”, 6th Edition, Pearson -> Chapter 01
Summary
Course Introduction:
Introduction to course, department, and university regulations and
culture; Course Outline
Problem Solving: Addition problem solve using pseudo-code
Introducing Decision Control:
Flowcharts for pictorial view of decisions (two-way)
if … else