ICT role in 21st century education and its challenges
Chapter 2
1. Faculty of Mechanical and Manufacturing
Prepared by Alish Ahmad Al-shahab
alishahmad.alshahab@gmail.com
2. ◊ Understand and implement the basic
structure of computer programming.
◊ Write a computer program using C
programming language.
◊ Convert algorithm into computer
program.
3. Program Basic Syntax
Development of Programming
Environment
CHAPTER 2
Data Types
Variable
Declarations
4. Involves translating high-level language (programming
language such as C,C++, Visual Basic, C#)
Because computers do NOT
understand high level language!
00011101 01010101 11011111
5. Edit/Write
Preprocess
Compile
Link
Load
Execute
6. o Types or creates program in an editor
Editor or text
o Makes corrections if necessary editor is a
type of
o Saves or stores program on disk program used
such as C: for editing
or A: etc. plain text
files. E.g
dev/turbo
15. Terms Description
Machine language Binary number codes understood by a specific
CPU.
High-level Machine-independent programming
language language that combines algebraic
expressions and English symbols.
Source file File containing a program written in a high-
level language; the input for compiler
Compiler Software that translates a high-level language
program into machine language.
Linker Software that combines object files and create
an executable machine language program.
16.
17. 1 Syntax Error
Error occurred during compilation
normally due to syntax problem
Misplaced else.
Declaration syntax error
Undefined symbol „_main‟ in module.
Statement missing in function main()
21. C preprocessor directive Program block
components:
main function 1. Preprocessor
{ directive
//Identifiers/Variables 2. Program body
//C statements 3. Main function
} 4. Identifiers/Variable
5. C statements
6. Comment
22. Utility program which link files from compiler library to the
program code.
Must be included in the first line of a computer program.
Must be started with the symbol #, otherwise syntax errors
will be occurred.
Two types of common preprocessor directive: #include and
#define.
23. #include <header file> or #include “user defined files”
Example
#include <stdio.h>
#include <conio.h>
#include “jam.h”
25. Consists of built-in functions
Functions contains standard instructions
Function will be called and linked to program
via header file
Header file List of functions
stdio.h printf(), scanf(),fflush(), dll
conio.h clrscr(),putch().getc().dll
math.h sqrt(),pow(), log(),dll
26. Contain functions defined by programmer.
Developed by expert programmers.
List of header file and its
Header file List of user-defined
function functions
utama.h cetak(),baca(),papar(),dll
kira.h plus(),minus(), divide(),dll
28. The part in which the program code will be started to
execute.
Consists of main function, C statements and identifiers.
Use { to start the program code and } to end the
program code.
main function
{ //identifiers
//C statements }
30. Write the most basic structures of
C programming.
#include <stdio.h>
void main()
{
}
31. Instructions to be executed by computers
Every statements must be ended with semicolon
Function Declaration
statement statement
Control Types
Input/Output
statement statement
Compound
statement
32. Statement in program code that will be ignored by compiler
Differs in terms of colour : grey
To increase
To
program document
readability a program
Function
As a
To provide future
additional referen
information ces
33. Using references from any C book, fin
the following concepts (definition an
A) Reserved Word
B) Variable
C) Constant
34. Standard/special word in standard library
Contain special meaning understood by compiler
Rules
Case –sensitive
Cannot be used as ide
Must be written in
small case or variables
35. Example:
void int
Refer to the function that will not
The acronym for integer
return any value
case default switch break
for continue float double
return while if do int
36. Representing particular name in programming
Store values to be used in programming
Refers to the storage in computer
37. Standard Special built-in words
identifier Referred as function name
which will called from C library
printf() scanf()
puts() gets()
38. Name given to the declaration of
User-defined data to be used in program
Refer to the storage name
identifier Store data values/result/output
Constant Type Variable
39. RULES
Identifiers name can only consists of name, number
and underscore
Identifiers name cannot be started with numbers
Symbol cannot be used in identifier name
Cannot contains spaces between two identifiers
name
Identifiers name should be unique
Identifiers is not case sensitive
41. Name which used to store data value
Refer to name of one cell in computer
storage
Contants value is fixed
How to give
name to a Follow identifiers rules
constant
value?
42. Declaration format: 1
const data_type const_name = const_value;
Constant
Reserved word const float pi = 3.142; Value
43. Declaration format: 2
#define const_name const_value;
#define pi 3.142;
Reserved word
44. Example of constant:
#define minimum 0;
#define MAX 100;
const int counter = 100;
const char alphabet = ‘J’;
const float value = 4.5;
45. Name which used to store data/input
value
Refer to the name of one cell in computer
storage
Variable’s value can be modified/changed
during execution
Declaration Format:
data_type variable_name;
46. Declaration Example
Declaration of a variable
number of integer data
type.
Declaration of a variable
weight of
floating point data type.
Declaration of a variable
alphabet
of character data type.
47. Variable/constant declaration example
//Variable and constant declration
#include <stdio.h>
int number;
float weight; Variable declaration
void main()
{
const float pi =3.142; Constant declaration
int bilangan;
float berat; Variable declaration
char abjad;
}
49. Method to give/assign value to variable
Interactive Initialization
Assign value to variable
during declaration.
Input/enter data
through input devices Assign value to variable.
Use input statement Use assign symbol, “=“
(scanf/gets)
50. Assigning value to variables
#include <stdio.h>
void main()
{
Initialize a variable
int number = 10;
float weight;
weight = 60.00; Interactive
printf(“Enter the value of number :”);
scanf(“%d”,&number);
number = 50.00; Initialize a variable
}
51. Represents types of data can be stored in computer
Types of data to be stored and used in
programming should be
informed to the compiler/system
Types
Integer Character
Floating
point
52. Represents any round number with +/-
values.
Integer Divided into short and long integer.
Reserved word for integer – int
Valid until 5 places of integer number.
Example:
age is used to represent the age of students
between 18 and 25 years old. The declaration
for the
variable is as follow: int age;
53. Floating Represents any floating point numbers +/-
number Reserved word– double /float
Example:
height is used to represent the student’s height
between 150 cm and 180 cm. The declaration for the
variable is as follow:
float height;
54. Character Represents character data.
Reserved word – char
Example:
gender is used to represent the gender of a
student. The declaration for the variable is
as follow:
char gender;
55. Determine whether the following identifiers is
valid or invalid. Give reason for invalid cases.
1) Parit Raja
2) 20thCentury
3) int
4) INTEGER
5) _BMW2003
6) Reservedword
7) BIT1033
8) markah_pelajar
9) jam*kredit
10) printf
56. Write a suitable variable declaration for each
of the following statement:
i. Salary of an employee
ii. Student’s mark for programming subject
iii. ATM pin number
iv. Phone number
v. Price of one item
vi. Bus seat number
vii. Student name
57. Based on the following problem, determine the
appropriate
variables can be declared:
Given the value of x is 10 and a is 12,
find the result of the following equation:
y = 2x + a - 6
58. Based on the following problem, determine the appropriate
variables can be declared:
Mrs Leeya needs to determine her students grade for
programming subject based on the mark scored during
final examination. The ‘A’ grade will be given if the
Mark scored is between 85 to 100. If a student has scored
90 marks, what is the grade should Mrs Leeya
give to the student?
59. Based on the following problem, determine the appropriate
variables can be declared:
A box has height, width and length.
Calculate the volume of a box.
60. Based on the following problem, determine the appropriate
variables can be declared:
Uncle Degawan wants to buy 5 tins of paint from
Cinda’s shop. The price of each tin of the paint is
RM 15.60. Calculate the price which Uncle Degawan
have
to pay for all the tin of paints he bought.