penyelesaian masalah

Post on 24-Jun-2015

140 Views

Category:

Technology

7 Downloads

Preview:

Click to see full reader

TRANSCRIPT

PROBLEM SOLVING

Problem solving involves: Analysis Algorithm or pseudo code or flow chart or

combination of them.

PROBLEMS ANALYSIS

Identify problems: Input Output Process

INPUT PROCESS OUTPUT

ALGORITHM

Algorithm Any computing problem can be done by

executing a series of actions in a specific order. A procedure for solving a problem in terms of the

actions to be executed and the order in which these actions are to be executed is called an algorithm.

Is a logical solution that is inline with our daily language or mother tongue language.

ALGORITHM

Start1. Set sum = 0 and average = 02. Read 3 numbers: nom1, nom2, nom33. Add 3 numbers4. Calculate the average, average = (sum)/35. Print 3 numbers(nom1, nom2, nom3) and the average

End

PSEUDO CODE

Pseudo codeIs an artificial and informal language

Usually it is use English languageQuite similar to programming language

The purpose of pseudo code is to make humans who do not understand computer programming can easily understand the flow of the problem solving.

PSEUDO CODE

STARTSET sum = 0, average = 0INPUT nom1, nom2, nom3sum = nom1 + nom2 + nom3average = sum / 3PRINT nom1, nom2, nom3PRINT average

END

FLOW CHART

Flow Chart It is represents by using geometry shapes with

connected line Use a standard symbol

FLOW CHART

TERMINALIndicates the beginning or end of an algorithm

PROCESSIndicates an input computational or data manipulation.

INPUT / OUTPUTIndicates an input or output operation

FLOW CHARTDECISIONIndicates a decision point in the algorithm

CONNECTOR Indicates an entry to or exit from another part of the flowchart

FLOW LINESUsed to connect the flowchart symbols and indicate the logic flow

LOOP Indicates the initial, final and increment values of a loop

CONTROL STRUCTURE

•It’s a technique in producing program logic which is simple and easy to understand•.It show the problem solution whether it’s a jujukan, selection or repetition control structure or the combination of two or three control structure.•Every programmer should analyze the problem to indentify the suitable control structure that must use .

CONTROL STRUCTURE

There are three type of control structure : Sequence Selection Repetition

SEQUENCE CONTROL STRUCTURE

Sequence control structure used when a problem is solved sequentially from start to end. Every instruction is perform once only. It used to solve problems that easy. This solution does not involve any condition and there is no repetition of instructions.

CONTROL STRUCTURE :

in

Process 1

Process 2

Process 3

out

Example 1: Kebajikan FTMK mengenakan yuran sebanyak 1% dari jumlah gaji setiap ahli untuk tabung kebajikannya. Lukiskan cartalir dan tuliskan aturcara untuk mencetak nama dan yuran yang diterima dari seorang ahlinya.

Anaylze :  input : name, salary

process : fee = salary * 1%

output : fee

FLOWCHART :

start

end

Input

salary

Print fee

Fee = 1% * salary

# include <iostream.h> // Program to calculate and display club fee main () { // Initialization of variables char name [15]; // staff name float salary =0, fee=0; // salary and fee // Data entry section cout << “please enter staff name"; cin >> name; cout << “please enter salary "; cin >> gaji; // Processing section fee = salary *.01; // Printing Section cout << “Staff name “<<name<<endl; cout << "\n The club fee is RM"<<fee; // end of programme return 0; }

EXAMPLE 2

Assume N number of students have to take MTS1033 course in UPSI and each student is required to buy C++ book with a price of RMX. The publisher will get 10% profit for each book that is sold. Write a program to calculate and print the profit that earned by the publisher.

CONTROL STRUCTURE - SELECTION

Selection control structure is used when the execution of instructions are depend on the result of a decision/selection that the program must make

if ..else StatementFormat :

if <(condition)> statement1;else statement2;

or if <(condition)> no semicolon statement1; else no semicolon statement2;

SELECTION CONTROL STRUCTURE -FLOWCHART

condition

Statement 2

statement 1

y

n

If the value of condition is true, then statement1 will be executed, otherwise statement2 will be executed

SELECTION CONTROL STRUCTURE -FLOWCHART

syarat

Kenyataan 1

y

t

Selection without else statement

if <(condition)> or if <(condition)> statement1 { statement1 statement2 : }

CONTROL STRUCTURE -SELECTION

Cost of printing price for coloured poster is RM2000 for the first 500 pieces and RM1000 for black and white poster. For each piece above then 500, the cost is RM2 for coloured and RM1.50for the black an white. Write a pseudo code and a programme to calculate payment that need to be paid by a customer.

top related