Professional Documents
Culture Documents
CHAPTER 1
INTRODUCTION TO PROGRAMMING
Problem solving
CONCEPTS
with computers…
References:
References:
Problem Solv ing and Programming Concepts (9th Edition) . Maureen Sprankle, Jim Hubbard, Pearson Education Limited 2012. 3. Computer Science for Matriculation Semester 2. Yew Kwang Hooi, Oxford Fajar 2014.
Simple Program Design. A step by step approach (5th Edition). Lesley Anne Robertson. Cengage Learning 2006.
1
1/12/2018
References:
3. Computer Science for Matriculation Semester 2. Yew Kwang Hooi, Oxford Fajar 2014.
References:
3. Computer Science for Matriculation Semester 2. Yew Kwang Hooi, Oxford Fajar 2014.
2
1/12/2018
3
1/12/2018
End
4
1/12/2018
Syntax errors
– any violation of rules of the language results in syntax error.
– E.g. End of statement marker: Many languages insist on a
semi-colon ‘;’ to indicate an end-of-statement, such as,
✘ print z ✔ print z;
4 TEST THE ALGORITHM FOR CORRECTNESS 6 RUN THE PROGRAM ON THE COMPUTER
(CONT) (CONT)
Logic errors
– These errors are related to logic of the program
execution.
– Logic errors occur when the code does not run in the way
it was intended because of the way it is written.
– Logic errors can be easy-to-spot blatant mistakes or
subtle problems that are extremely difficult to spot.
– E.g. Wrong operations in a mathematical formula to
calculate length of hypotenuse of a right-angle triangle.
✘ h = sqrt(a*a – b*b);
✔ h = sqrt(a*a + b*b);
5
1/12/2018
Local declaration
Variables declared in a certain function.
Visible only to the functions that contain
them.
6
1/12/2018
7
1/12/2018
• The most common elementary data types are: • Variables declared as characters cannot be used
* integer * character * for calculations. E.g. ‘A’+ ‘1’ = ???
boolean
* float * double • One or more characters can be combined into a
“string”. E.g. : “a”, “abc”, “Hello World 123 !!”
8
1/12/2018
9
1/12/2018
SUMMARY
The steps in program development were
introduced and briefly described below:
1. Define the problem
2. Outline the solution
3. Develop the outline into an algorithm
4. Test the algorithm for correctness
5. Code the algorithm into a specific programming
language
6. Run the program on the computer
7. Document and maintain the program
10