Bab 1 - Introductory Concepts
Bab 1 - Introductory Concepts
Define programme, programmer and programming language Types of programming language Types of programming:
Structured programming Modular programming Object-oriented programming
List stages involved in problem solving Elements of problem analysis : Input, Process, Output Design tools for problem solving:
Flowchart Pseudo code IPO Chart (Input-Process-Output Chart)
Types of error in programming: syntax error, run-time error & logical error
Programme - A set of instructions that tells the computer what to do Programmer A person who is involved in the programming phases. Programming language is the language understood by the computer, used to tell the computer what to do.
Machine languages
is a true computer language machine specific instructions, consists of binary numbers i.e 0 and 1. lowest level representation of computer program
Assembly languages
Using mnemonics to represent machine language instructions (translated via assemblers) Example: mov ax, 1234h (mov value 1234h into register ax)
HighHigh-level languages
Codes similar to everyday English Use mathematical notations (translated via compilers) Example: grossPay = basePay + overTimePay
Structured Programming
Computer programming in which the statements are organized in a specific manner to minimize error or misinterpretation. Ada. ALGOL, Pascal, C, PL/I and Ada.
Problem requirements Problem Analysis Program Design (Algorithm) Writing Programme Testing and debugging Documentation
1. Problem Requirements
Before any problem can solve, we really have to understand what is to be solve. To understand, we should think and ask question
2. Problem Analysis
All computer programs have several elements in common.
Input Process Output
They receive data input from users, store the data on some storage device (e.g. hard disk), process the data into useful information, and finally produce output in the form of reports. (Figure 1)
I N P U T
P R O C E S S
O U T P U T
STORAGE
2. Problem Analysis
Identify and understand the problem to be solved. Problem analysis is done by determining 3 main things:
Input needed Output has to be produced Process to be carried out in order to get the output based on the input
INPUT INPUT
OUTPUT OUTPUT
Better known as Algorithm Algorithm is a list of sequential steps to solve a problem 2 methods in writing algorithm :
Pseudo Code steps in problem solving (logic) written using a combination of spoken language and some programming language semiformal. Flow Chart steps in problem solving (logic) using diagrams and specific symbols.
* PSEUDO CODE
Pseudo Code steps in problem solving (logic) written using a combination of spoken language and some programming language semiformal. Example :
INPUT / OUTPUT
DECISION
CONTINUE
ACTIVITY FLOW
Implementation phase, where the code is written and typed using the computer A logic problem solving represented by pseudo codes dan flow chart converted to computer programme, using suitable language Language example: C, C++, Visual Basic, Java, PHP
Program that have been complete, has to be teated/run to make sure the output is correct. Debugging that is by inserting true data to be tested If there is an error, correct it, depend on which error.
There tree types of error. Logical Error due to ways of solving and steps is not correct and the flow is not logic. Syntax Error due to syntax statement is not correct according to program language used. Run-time Error due to input data is not the input of the program required.
This the last steps, preparing a report for future upgrading and correction. Document consists:
Types of problem or a true specific requirement Types of input, output, constraint and formula for the problem. Logic algorithm used such as flow chart or pseudo code Example of output executed using test data. Steps or guidance of using a program
Define & Analyst Problem o Define & knowing problems o Define data problems input & output
Prepare documentation o Problem analysis document and program and modules involve
Correct Program Error
Program Design o Plan & fixed strategy o Knows data model, component & relation o Build algorithm/ flowchart
Code the program Translate the algorithm into program code using the specific programming language
Test Program o Test the program using computer for errors. o Correct output as define by user.
THE PROBLEM
A durian seller like to calculate the cost of the durian the customer have to pay. If the durian cost RM2.50 per kilogram. Program a way for calculating the total cost of durians for an amount in kilogram of durians sell.
problem: Analising the problem Define the input, output and the proces.
Total Weight (Kg) Cost = Total weigrt x RM2.50 Cost
display cost
End.
Total Weight
Cost=
Cost
End
#include <stdio.h> main () { int weight, payment; scanf ("%d", &weight); payment = weight * 2; printf ("The payment: RM%d.00", payment); getch(); return 0; }