0% found this document useful (0 votes)
11 views40 pages

Chapter 01

The document provides an introduction to computer programming, problem solving, and algorithms, detailing the importance of programming languages and methodologies. It explains the concept of algorithms using pseudocode and flowcharts as tools for representing processes. Additionally, it includes examples and guidelines for creating flowcharts and pseudocode to solve problems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views40 pages

Chapter 01

The document provides an introduction to computer programming, problem solving, and algorithms, detailing the importance of programming languages and methodologies. It explains the concept of algorithms using pseudocode and flowcharts as tools for representing processes. Additionally, it includes examples and guidelines for creating flowcharts and pseudocode to solve problems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 40

DCT 1123

PROBLEM SOLVING & ALGORITHM

INTRODUCTION TO PROGRAMMING
CONTENTS

 COMPUTER PROGRAMMING
CONCEPTS
 PROBLEM SOLVING
OVERVIEW
 ALGORITHM OVERVIEW
(PSEUDOCODE &
FLOWCHART)
What is Computer Programming?

 Writing software, computer programs, is


describing how to do something.

 It is a lot like writing down the steps it


takes to do something - a process.
Programming Language
 We need a language to communicate with a
computer.
 Computer languages are used to tell the
computer what to do, you instruct it.
 Once it is written, the programmer uses a
compiler to turn it into a language that the
computer can understand.
 Most software written today is using high level
language such as C++, JAVA and etc.
Programming Language
Top Programming Language Rank

http://jacobian.web.id/2010/11/14/java-and-c-top-programming-language-rank/
History of Programming
History of Programming
History of Programming
History of Programming
History of Programming
History of Programming
History of Programming
Software
15

 Software: programs that do specific tasks


 Examples
 Word processors

 Operating systems

 Spreadsheets

 All software is written in programming languages


The Language of a
Computer
 Digital signals are sequences of 0s
and 1s
 Machine language: language of a
computer
 Binary digit (bit):
 The digit 0 or 1

 Binary code:
 A sequence of 0s and 1s

 Byte:
 A sequence of eight bits

16
Assembly Language
17

 Assembler: translates a program written in


assembly language into machine language
High-Level Languages
 High-level languages include Basic,
FORTRAN, COBOL, Pascal, C, C++, C#,
and Java

 Compiler: translates a program written


in a high-level language machine
language

 The equation wages = rate x hours


can be written in C++ as:
wages = rate * hours;
18
Processing a C++ Program
#include <iostream>
using namespace std;
int main()
{
cout << "Welcome to C++
programming." << endl;
return 0;
}

Sample Run:
???
19
Processing a C++ Program
(continued)
 To process a program written in C++:
 Use an editor (IDE) to create a source

program in C++
 Use the compiler to:

 Check that the program obeys the rules


 Translate into machine language (object
program)
 Run code through compiler

 If compiler generates errors


 Look at code and remove errors
 The final step is to execute the program

20
Programming Methodologies

 Two popular approaches to programming design


 Structured

 Implementing a structured design

 Object-oriented

 Identify components called objects

21
What is Problem Solving ?
 The process of working through details of a
problem to reach a solution.

 Problem solving may include mathematical or


systematic operations and can be a complicated
of an individual's critical thinking skills.
Algorithm Overview

 An algorithm is like a recipe; it lists the steps


involved in accomplishing a task
 In a programming, it is a set of detailed,
unambiguous and ordered instructions developed
to describe the processes necessary to produce
desired output
 Pseudocode & flowcharts are popular ways of
representing algorithms
 Written in simple English
Algorithm Overview

 For example, if you want to instruct someone to


add up a list of prices on a pocket calculator, you
might write:
 Turn on calculator
 Clear calculator
 Repeat the following instructions
 Key in ringgit amount
 Key in decimal point
 Key in cents amount
 Press addition (+) key
 Until all prices have been entered
 Write down total price
 Turn off calculator
Pseudocode

 Easy to read & write and allows programmer to concentrate


on the logic of the problem
 Statements are written in simple English
 Each instruction is written on a separate line
 Keyword & indentation are used to signify particular control
structures
 Each set of instructions is written from top to bottom, with
only one entry and one exit
 Groups of statements may be formed into modules, and
that group given a name
Example Pseudocode
 Write a program that obtains two integer
numbers from the user. It will print out the
sum of those numbers.

Pseudocode:
Begin
1. PROMPT user for the first number
2. READ user's first integer input (N1)
3. PROMPT user for thesecond number
4. READ user's second integer input (N2)
5. ADD first integer and second integer into sum
(SUM=N1+N2)
6. DISPLAY the result (SUM)
END
Flowchart

 Flowchart is an alternative method of


representing algorithms
 It is popular because they graphically represent
the program logic through series of standard
geometric symbols and connecting lines
Flowchart Symbols

Terminal Symbol
Indicates the starting or stopping point
in the logic. Every flowchart should
begin and end with a terminal symbol.

Input / Output Symbol


Represents an input or output process
in an algorithm, such as reading input
or writing output
Flowchart Symbols

Process Symbol
Represents any single process in an
algorithm, such as assigning a value or
performing a calculation

Predefined Process Symbol


Represents an input or output process
in an algorithm, such as reading input
or writing output
Flowchart Symbols

Decision Symbol
Represents a decision in the logic
involving the comparison of two values.
Alternative paths are followed,
depending on whether the decision
symbol is true or false
Flowlines
Connect various symbols in a
flowchart, and contain an arrowhead
only when the flow control is not from
top to bottom or left to right
Guidelines for Drawing a
Flowchart
 The following are some guidelines in
flowcharting:
1. All necessary requirements should be listed
out in logical order.
2. The flowchart should be clear, neat and easy
to follow.
3. The usual direction of the flow of a procedure
or system is from left to right or top to
bottom.
Guidelines for Drawing a
Flowchart (Cont.)

4. Only one flow line should come out from a


process symbol.

5. Only one flow line should enter a decision


symbol, but two should leave the decision
symbol.

X=9 TRUE
9

FALSE
Guidelines for Drawing a
Flowchart (Cont.)

6. Only one flow line is used in conjunction with


terminal symbol.

START

END
Sample Pseudocode &
Flowchart

Begin
Input letter
If letter is ‘M’
Display
‘Malaysian’
Else
Display
‘Foreigner’
End
End
Exercise

 Print Hello World 1 times

Pseudocode (in simple English)


Begin
 Print Hello World (I/O)
End

Flowchart
????
Exercise

 Print your name 1 times

Pseudocode (in simple English)


????

Flowchart
????
Exercise

 To solve this problem we will take a variable sum and set it


to zero.
 Then we will take the two numbers 10 and 20 as input.
 Next we will add both the numbers and save the result in
the variable sum i.e., sum = 10 + 20.
 Finally, we will print the value stored in the variable sum.
Answer

Pseudocode (in simple English)


Begin
 Initialize sum = 0 (PROCESS)
 Enter the numbers (I/O)
 Add them and store the result in sum (PROCESS)
 Print sum (I/O)
End

Flowchart
Exercise

 To solve this problem we will take a variable total and set it


to zero.
 Then we will take the three numbers 1, 2 and 3 as input.
 Next we will add three numbers and save the result in the
variable total
i.e., sum = 1 + 2 + 3.
 Finally, we will print the value stored in the variable total.

 Write your algorithm for this problem?

You might also like