SlideShare a Scribd company logo
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
DFC 20113
PROGRAMMING
FUDAMENTALS
CHAPTER 1
INTRODUCTION TO FUNDAMENTALS
OF PROGRAMMING
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
COURSE LEARNING
OUTCOMES
CLO 1: Implement programming element
and articulate how they are used to achieve
a working program.
( C3, PLO 2 )
CLO 2: Show simple programs by
developing code to solve problems in a
computer using C++ programming
language. ( P2, PLO 3 )
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
LEARNING OUTCOMES
at the end of this sub-chapter, students should be able
to:
• Describe the item in C++ program
structure
• Comments
• Preprocessor directives
• Header files
• main() function
• return statements.
• Describe two types of comments that
supported by C++ program
• Explain coding standard best practices
1.1 Define
the C++
program
basic
structure
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
• Probably the best way to start learning a programming
language is by writing a program.
• Therefore, here is our first program:
// my first program in C++
#include <iostream.h>
int main ()
{
cout << “My First Program!";
return 0;
}
Output:
My First Program!
OUTPUT
SOURCE CODE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
a) Comment Style
•Entries in the source code which are ignored by the compiler
•C++ support 2 style/form of comments:
i.//Single Line Comments
 for simple 'side' notes
 best places to put these comments are next to variable
declarations, and next to pieces of code that may need
explanation.
ii./ *block comment */or /*Multi-Line Comments*/
 most useful for long explanations of code.
 useful for two reasons: They make your functions easier
to understand, and they make it easier to spot errors in
code.
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Illustrate the valid & invalid comments within a program.
Comment statements
// this program displays a message valid
/ this program displays a message invalid
// this comment is invalid because its
extend over two lines
invalid
// this comment is used a comment that
//extend across two lines
valid
/*this comment is a block comment that
spans
three lines*/
valid
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
b) Pre Processor Directive
• What’s a #?
• Any line that begins with # symbol is a pre-processor directive
• Processed by preprocessor before compiling
• What’s pre-processor?
• A utility program, which processes special instructions are written in a
C/C++ program.
• Include a library or some special instructions to the compiler about
some certain terms used in the program
• Different preprocessor directives (commands) perform different tasks.
• Uses for?
• It is a message directly to the compiler.
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• How to write/syntax ?
• Begin with #
• No semicolon (;) is expected at the end of a preprocessor directive.
• Example:
Pre-processor directive Meaning
#include <iostream> Tells preprocessor to include the input/output stream
header file <iostream>
#define NAME “BOB” Define a constant
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
c) Header File
• sometimes known as an include file. Header files
almost always have a .h extension.
• Why use?
• For big projects having all the code in one file is impractical. But if we
split the project into smaller files, how can we share functions between
them? Headers!
 The purpose of a header file?
 To hold declarations for other files to use.
 When we use the line #include <iostream>, we are telling the compiler
to locate and then read all the declarations from a header file named
“iostream”.
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Consider the following program:
 Program never declare cout, so how does the compiler know what
cout is?
 The answer is that cout has been declared in a header file
called “iostream”.
Bear in mind that
header files typically
only contain
declarations. They do
not define how
something is
implemented
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
d) Main Function
• This line corresponds to the beginning of the definition of the
main function.
• A part of every C++ program and identify the start of the
program
Exactly one function in a program must be main
main is a Keyword.
• Keyword : A word in code that is reserved by C++ for
a specific use.
• Header of function main?
int main( )
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• The structure of a main Function:
int main ( )
{
C++ program statements goes here;
return 0;
}
Function
body
Type of
return value
Function name An empty
argument list
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• 4 common ways of main declaration:
int main()
{
return 0;
}
void main()
{
}
main(void)
{
}
main( )
{
}
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
e) Curly Braces {}
• Body is delimited by braces ({ })
• Identify a segment / body of a program
The start and end of a function
The start and end of the selection or repetition block.
• Since the opening brace indicates the start of a segment
with the closing brace indicating the end of a segment,
there must be just as many opening braces as closing
braces
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
f) C++ statement
• What's?
A specification of an action to be taken by the computer as the program
executes.
Instruct the program to perform an action
• Syntax?
All statements end with a semicolon (;)
• Statement has two parts :
Declaration
• The part of the program that tells the compiler the
names of memory cells in a program
Executable statements
• Program lines that are converted to machine language instructions
and executed by the computer
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
g) Return Statement
• Means?
The return statement causes the main function to finish.
Return may be followed by a return code (in our example
is followed by the return code with a value of zero).
A return code of 0 for the main function is generally
interpreted as the program worked as expected without
any errors during its execution.
• When used?
 At the end of main
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Two situations for return statement:
a) Return optional in void functions
A void function doesn't have to have a return statement when the end is
reached, it automatically returns.
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
b) Return required in non-void functions
 If a function returns a value, it must have a return
statement that specifies the value to return.
 It's possible to have more than one return.
 Example 1: return 0;
Return the value
0 to the
computer's
operating system
to signal that the
program has
completed
successfully
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Coding Standards Best Practices
Refer this link:
https://google.github.io/styleguide/cppguide.html
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Importance of following coding standards best practices:
easier for a developer to understand
easier to find and correct bugs
provides a better view of how that code fits within the
larger application
easier for someone to maintain that code
1.1 INTRODUCE THE C++
PROGRAM BASIC STRUCTURE
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
PROGRAMMING EXERCISE
Ahmad are asked to create a program that can calculate the
area of rectangle. He need to identify the IPO, draw a
flowchart and create a program. You are asked to help
Ahmad.
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
LEARNING OUTCOMES
at the end of this sub-chapter, students should
be able to:
• Explain identifier, variable and
constant.
• State the rules for naming an identifier.
• Name the variables according the
standards
• Explain the data types.
• List the data types and their respective
range with examples:
• Integer
• Floating point
• Character
• Boolean
• String
1.2 Explain
identifier
and data
types
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• IDENTIFIER: Words used to represent certain program
entities (variables, function names, etc).
• VARIABLE is identifier whose value can change during the
course of execution of a program
• KEYWORDS (reserved words) have standard, predefined
meanings and must be used only for their intended purpose. It
cannot be used as an identifier.
• CONSTANTS are values that do not change during program
execution. They can be any type of integer, character or
floating-point.
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
a) Identifier
• Words used to represent certain program entities
(variables, function names, etc).
• Example:
• int number;
• number is an identifier used as a program variable
• void CalculateTotal (int value)
• CalculateTotal is an identifier used as a function name
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
b) Variables
• What's? Is a Location in memory which:
we can refer to by an identifier, and
in which a data value that can be change
Where value can be stored
• Common data types (fundamental, primitive or built-in)
int – integer numbers : 1, 2, 4,….
char – characters : ‘a’, ‘c’, …
float, double: floating point numbers: 2.5, 4.96
• The value of a variable could be changed while the program is
running.
• Declaring a variable means specifying both its name and its data
type.
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
EXAMPLE OF VARIABLES
 int is an abbreviation for integer.
• Integer store value: 3, 102, 3211, -456, etc.
• Example variable : number_of_bars
 double represents numbers with a fractional
component
• double store value: 1.34, 4.0, -345.6, etc.
• Example variable : one_weight ,total_weight
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
c) Constant
• Entities that appear in the program code as fixed values.
• Any attempt to modify a CONSTANT will result in error.
• Declared using the const qualifier
• Also called named constants or read-only variables
• Must be initialized with a constant expression when they are
declared and cannot be modified
• Example: const int size = 5;
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Types of constant:
1. Literals
Literals are the most obvious kind of
constants.
They are used to express particular values
within the source code of a program.
 e.g:
a=5;
grade=‘A’;
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Types of constant:
2. Define Constant (#define)
You can define your own names for constants that
you use very often without having to resort to
memory-consuming variables, simply by using the
#define preprocessor directive.
 Its format is:
#define identifier value
Examples:
#define PI 3.14159
#define GRAVITY 9.8
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Types of Constant:
3. Declared Constants
With the const prefix you can declare constants with
A specific type in the same way as you would do with
A variable:
const int pathwidth = 100;
const char grade = ‘A';
They are treated just like regular variables except
that their values cannot be modified after their
definition.
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Rules Example
Can contain a mix of character and numbers. However it cannot start
a number
H2o
First character must be a letter or underscore Number1,
_area
Can be of mixed cases including underscore character XsquAre
my_num
Cannot contain any arithmetic operators R*S+T
… or any other punctuation marks #@x%!!
Cannot be a C keyword/reserved word struct; cout;
Cannot contain a space My height
… identifiers are case sensitive Tax != tax
NAMING CONVENTION RULES FOR IDENTIFIER
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• They are formed by combining letters, digits & underscores.
• Blank space is not allowed in an identifier.
• The first character of an identifier must be a letter.
Valid Invalid Reason
Monthly_Salary Monthly Salary Blank space cannot be used
Month1 1stMonth Digit cannot be used as a first
character
Email_add email@ Special characters cannot be
used
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Why variables needed in programming?
Variables are used to store information to be referenced and
manipulated in a computer program.
They also provide a way of labeling data with a descriptive name, so
our programs can be understood more clearly by the reader and
ourselves.
It is helpful to think of variables as containers that hold
information.
Their purpose is to label and store data in memory. This data can
then be used throughout a program.
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• When we create a program, we store the variables in
our computer's memory.
• But the computer has to know what kind of data we
want to store in them.
• Since it is not going to occupy the same amount of
memory to store a simple number than to store a
single letter or a large number.
• They are not going to be interpreted the same way.
Basic Data Types
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
DATA
TYPES
Numeric
• int
• float
• double
Non-numeric
• char
• string
• bool
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Name Description Size* Range*
string Sequence of character.
10 bytes +
string length
0 to approximately 2 billion
char Character or small integer. 1byte
signed: -128 to 127
unsigned: 0 to 255
bool
Boolean value. It can take one
of two values: true or false.
1byte true or false
float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits)
int Integer. 4bytes
signed: -2147483648 to
2147483647
unsigned: 0 to 4294967295
double
Double precision floating
point number.
8bytes +/- 1.7e +/- 308 (~15 digits)
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• There are 6 basic data types :
i. char
• equivalent to ‘letters’ in English language
• Example of characters:
• Numeric digits: 0 - 9
• Lowercase/uppercase letters: a - z and A - Z
• Space (blank)
• Special characters: , . ; ? “ / ( ) [ ] { } * & % ^ < > etc
• single character
• keyword: char
• Example code:
• Sample values
‘B’ ‘d’ ‘4’ ‘?’ ‘*’
The
declared
character
must be
enclosed
within a
single
quote!
char my_letter;
my_letter = 'U';
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
ii. int
• used to declare numeric program variables of integer type
• whole numbers, positive and negative
• keyword: int
• Example code :
• Sample values:
4578 -4578 0
int number;
number = 12;
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
iii. double
• used to declare floating point variable of higher
precision or higher range of numbers
• exponential numbers, positive and negative
• keyword: double
• Code example:
double valuebig;
valuebig = 12E-3;
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
iv. float
• fractional parts, positive and negative
• real numbers with a decimal point
• keyword: float
• Example code:
• sample values
95.274 95.5 2.265
float height;
height = 1.72;
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
v. bool
• The bool data type is capable of holding a
Boolean value.
• Objects of type bool may have only the values
true or false.
• To declare a variable of type bool:
bool old_enough;
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
vi. string
• a string is a sequence of characters enclosed in
double quotes
• string sample values:
“Hello” “Year 2000” “1234”
• the empty string (null string) contains no
characters and is written as “ ”
• Example code:
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
string name = “Ahmad Albab”;
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
// operating with variables
#include <iostream>
Using namespace std;
int main ()
{
// declaring variables
int a, b, result;
// process:
a = 5;
b = 2;
a = a + 1;
result = a - b;
// print out the result:
cout << result;
// terminate the program:
return 0;
}
Output:
4
Example 1:
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
// operating with variables
#include <iostream>
using namespace std;
int main ()
{
// declaring variables
string name;
//get input from user
cout<<“Enter your name: “;
cin>>name;
// print out name:
cout <<“Your name: “<<name;
// terminate the program:
return 0;
}
Output:
Enter your
name: ALI
Your name:
ALI
Example 2:
1.2 EXPLAIN IDENTIFIER AND
DATA TYPES
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
LEARNING OUTCOMES
AT THE END OF THIS SUB-CHAPTER,
STUDENTS SHOULD BE ABLE TO:
• Describe the features of C++
language.
• Develop C++ program using
Integrated Development
Enviroment (IDE).
• Get started with IDE
• Create a project file
• Create a simple C++ program
• Compile a C++ program
• Run a C++ program
1.3 Identify
the basic of
computer
program
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
1.3 APPLY THE BASIC OF
COMPUTER PROGRAM
Features of C++ language
C++ is object oriented programming language and it is a very simple and easy
language, this language have following features.
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Simple
Every C++ program can be written in simple English language so that it is very easy to
understand and developed by programmer.
• Portability
It is the concept of carrying the instruction from one system to another system. In C++
Language .cpp file contain source code, we can edit also this code. .exe file contain application,
only we can execute this file. When we write and compile any C++ program on window
operating system that program easily run on other window based system.
• Powerful
C++ is a very powerful programming language, it have a wide verity of data types, functions,
control statements, decision making statements, etc.
• Platform dependent
A language is said to be platform dependent whenever the program is execute in the same
operating system where that was developed and compiled but not run and execute on other
operating system. C++ is platform dependent language.
• Object oriented
This main advantage of C++ is, it is object oriented programming language. It follow concept
of oops like polymorphism, inheritance, encapsulation, abstraction.
1.3 APPLY THE BASIC OF
COMPUTER PROGRAM
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Case sensitive
C++ is a case sensitive programming language. In C++ programming 'break and BREAK'
both are different. If any language treats lower case latter separately and upper case latter
separately than they can be called as case sensitive programming language [Example c, c++,
java, .net are sensitive programming languages.] other wise it is called as case
insensitive programming language [Example HTML, SQL is case insensitive programming
languages].
• Compiler based
C++ is a compiler based programming language that means without compilation no C++
program can be executed. First we need compiler to compile our program and then execute.
• Syntax based language
C++ is a strongly tight syntax based programming language. If any language follow rules and
regulation very strictly known as strongly tight syntax based language. Example C, C++,
Java, .net etc. If any language not follow rules and regulation very strictly known as loosely
tight syntax based language.
Example HTML.
• Use of Pointers
Pointers is a variable which hold the address of another variable, pointer directly direct
access to memory address of any variable due to this performance of application is improve.
In C++ language also concept of pointer are available.
1.3 APPLY THE BASIC OF
COMPUTER PROGRAM
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Integrated Development Environment
An integrated development environment (IDE) is a software
application that provides comprehensive facilities to computer
programmers for software development.
All of the tools for writing, compiling and
testing code in one place.
An IDE normally consists of:
- a source code editor
- a compiler and/or an interpreter
- build automation tools
- a debugger
1.3 APPLY THE BASIC OF
COMPUTER PROGRAM
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Get start with IDE Software: Dev C++
Compile
Execute
New file
Compile & Execute
1.3 APPLY THE BASIC OF
COMPUTER PROGRAM
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
• Create a simple C++ program:
• Compile and run your code. Then display the output.
Write a program to display your name,
registration number and department in separate
line.
1.3 APPLY THE BASIC OF
COMPUTER PROGRAM
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
S
O
L
U
T
I
O
N
1.3 APPLY THE BASIC OF
COMPUTER PROGRAM
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
LEARNING OUTCOMES
AT THE END OF THIS SUB-CHAPTER,
STUDENTS SHOULD BE ABLE TO:
•Describe the compiling process of a
program
•Source code
•Compiler
•Linker
•Executable file
•Describe with example the errors in
programming:
•Syntax/ compile time errors
•Run time errors
•Logical errors
•Identify effective debugging process
•Debug simple programs to demonstrate
syntax/ compile time, run time and logical
error
1.4
Describe the
compiling and
debugging
process and
errors in
programming
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
1.4 IDENTIFY THE COMPILING AND
DEBUGGING PROCESS, AND ERRORS IN
PROGRAMMING.
COMPILING PROCESS
• A compiler is a computer program (or set of programs)
that transforms source code written in a computer
language (the source language) into another computer
language (the target language, often having a binary form
known as object code).
• The most common reason for wanting to transform source
code is to create an executable program.
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
1.4 IDENTIFY THE COMPILING AND
DEBUGGING PROCESS, AND ERRORS IN
PROGRAMMING.
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
HOW C++ WORKS?
https://www.youtube.com/watch?v=ZTu0kf-7h08
1.4 IDENTIFY THE COMPILING AND
DEBUGGING PROCESS, AND ERRORS IN
PROGRAMMING.
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
ERRORS IN PROGRAMMING
ERRORS
Syntax/
Compile
Run
Time
Logical
1.4 IDENTIFY THE COMPILING AND
DEBUGGING PROCESS, AND ERRORS IN
PROGRAMMING.
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
Error Descriptions Common examples
Syntax
errors/
compile
error
Grammar errors in the
of the programming
language.
 Misspelled variable and function names.
 Missing semicolons(;)
 Improperly matches parentheses, square
], and curly braces{ }
 Incorrect format in selection and loop statements
Run time
errors
Occur when a program
with no syntax errors asks
the computer to do
something that the
computer is unable to
reliably do.
Trying to divide by a variable that contains a
of zero
Trying to open a file that doesn't exist
There is no way for the compiler to know about
these kinds of errors when the program is
Logic
errors
Logic errors occur when
there is a design flaw in
your program.
Multiplying when you should be dividing
Adding when you should be subtracting
Opening and using data from the wrong file
Displaying the wrong message
1.4 IDENTIFY THE COMPILING AND
DEBUGGING PROCESS, AND ERRORS IN
PROGRAMMING.
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
SPECIAL CHARACTERS IN C++ PROGRAMMING SYNTAX
Character Name Meaning
// Double slash Beginning of a comment
# Pound sign Beginning of preprocessor
directive
< > Open/close brackets Enclose filename in #include
( ) Open/close parentheses Used when naming a function
{ } Open/close brace Encloses a group of statements
" " Open/close quotation
marks
Encloses string of characters
; Semicolon End of a programming
statement
1.4 IDENTIFY THE COMPILING AND
DEBUGGING PROCESS, AND ERRORS IN
PROGRAMMING.
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
WHAT IS DEBUGGING???
• Debugging is the process of locating and fixing or by
passing bugs (errors) in computer program code or
the engineering of a hardware device.
• Debugging is a generalized term which essentially
means to step through a process in order to
systematically eliminate errors.
1.4 IDENTIFY THE COMPILING AND
DEBUGGING PROCESS, AND ERRORS IN
PROGRAMMING.
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
DEBUG PROGRAMS WITH SYNTAX /
COMPILE TIME, RUN TIME AND
LOGICAL ERROR
Do in Lab Activity 1
MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
THE END

More Related Content

What's hot

Kemajuan peradaban Islam Andalusia
Kemajuan peradaban Islam AndalusiaKemajuan peradaban Islam Andalusia
Kemajuan peradaban Islam Andalusia
Abdul Algafur
 
SEJARAH PERANG KHANDAQ
SEJARAH PERANG KHANDAQSEJARAH PERANG KHANDAQ
SEJARAH PERANG KHANDAQ
dayat7
 
6. ta'arudh tarjih nasakh
6. ta'arudh tarjih nasakh6. ta'arudh tarjih nasakh
6. ta'arudh tarjih nasakhMarhamah Saleh
 
Hasani Ahmad S, Corak pemikiran kalam tafsir fath al-qadir al-syaukani, TESIS...
Hasani Ahmad S, Corak pemikiran kalam tafsir fath al-qadir al-syaukani, TESIS...Hasani Ahmad S, Corak pemikiran kalam tafsir fath al-qadir al-syaukani, TESIS...
Hasani Ahmad S, Corak pemikiran kalam tafsir fath al-qadir al-syaukani, TESIS...
Hasaniahmadsaid
 
Sirah Nabawiyah: Perang Tabuk
Sirah Nabawiyah: Perang TabukSirah Nabawiyah: Perang Tabuk
Sirah Nabawiyah: Perang Tabuk
PAUSIL ABU
 
Ppi kh. hasyim asy'ari (power poin)
Ppi kh. hasyim asy'ari (power poin)Ppi kh. hasyim asy'ari (power poin)
Ppi kh. hasyim asy'ari (power poin)Fayi Gober
 
Teknologi dalam pendidikan Islam
Teknologi dalam pendidikan IslamTeknologi dalam pendidikan Islam
Teknologi dalam pendidikan Islam
Fatimah Nour Syarha Mohidin
 
Tips Usrah
Tips UsrahTips Usrah
Tips Usrah
Tarbiyyah Kreatif
 
Lmcp 1522 zakat
Lmcp 1522 zakatLmcp 1522 zakat
Lmcp 1522 zakat
syahirah1996
 
Khalifah umar bin al khattab r
Khalifah umar bin al khattab rKhalifah umar bin al khattab r
Khalifah umar bin al khattab rraydaryl
 
Hadith Daif
Hadith DaifHadith Daif
Hadith Daifdr2200s
 
Calon Ahli Syurga dan Neraka
Calon Ahli Syurga dan NerakaCalon Ahli Syurga dan Neraka
Calon Ahli Syurga dan Neraka
Tazkirah PTAR
 
Makkiyyah dan Madaniyyah
Makkiyyah dan MadaniyyahMakkiyyah dan Madaniyyah
Makkiyyah dan Madaniyyah
Feldi Huda Yustian
 
SEJARAH KEBUDAYAAN ISLAM
SEJARAH KEBUDAYAAN ISLAMSEJARAH KEBUDAYAAN ISLAM
SEJARAH KEBUDAYAAN ISLAM
fira152
 
PENGEMBANGAN KURIKULUM
PENGEMBANGAN KURIKULUMPENGEMBANGAN KURIKULUM
PENGEMBANGAN KURIKULUM
UNIVERSITY OF ADI BUANA SURABAYA
 
Ppt al qur'an
Ppt al qur'anPpt al qur'an
Ppt al qur'an
Velayati As'ad
 
Akidah ahli sunnah wal jamaah
Akidah ahli sunnah wal jamaahAkidah ahli sunnah wal jamaah
Akidah ahli sunnah wal jamaah
Khairul Anwar
 
Sumbangan kerajaan uthmaniyah
Sumbangan kerajaan uthmaniyahSumbangan kerajaan uthmaniyah
Sumbangan kerajaan uthmaniyahImtiyazZahra
 
PPT ILMU KALAM KELOMPOK 1.pptx
PPT ILMU KALAM KELOMPOK 1.pptxPPT ILMU KALAM KELOMPOK 1.pptx
PPT ILMU KALAM KELOMPOK 1.pptx
miduwidang
 

What's hot (20)

Kemajuan peradaban Islam Andalusia
Kemajuan peradaban Islam AndalusiaKemajuan peradaban Islam Andalusia
Kemajuan peradaban Islam Andalusia
 
SEJARAH PERANG KHANDAQ
SEJARAH PERANG KHANDAQSEJARAH PERANG KHANDAQ
SEJARAH PERANG KHANDAQ
 
6. ta'arudh tarjih nasakh
6. ta'arudh tarjih nasakh6. ta'arudh tarjih nasakh
6. ta'arudh tarjih nasakh
 
Hasani Ahmad S, Corak pemikiran kalam tafsir fath al-qadir al-syaukani, TESIS...
Hasani Ahmad S, Corak pemikiran kalam tafsir fath al-qadir al-syaukani, TESIS...Hasani Ahmad S, Corak pemikiran kalam tafsir fath al-qadir al-syaukani, TESIS...
Hasani Ahmad S, Corak pemikiran kalam tafsir fath al-qadir al-syaukani, TESIS...
 
Sirah Nabawiyah: Perang Tabuk
Sirah Nabawiyah: Perang TabukSirah Nabawiyah: Perang Tabuk
Sirah Nabawiyah: Perang Tabuk
 
Ppi kh. hasyim asy'ari (power poin)
Ppi kh. hasyim asy'ari (power poin)Ppi kh. hasyim asy'ari (power poin)
Ppi kh. hasyim asy'ari (power poin)
 
Teknologi dalam pendidikan Islam
Teknologi dalam pendidikan IslamTeknologi dalam pendidikan Islam
Teknologi dalam pendidikan Islam
 
Tips Usrah
Tips UsrahTips Usrah
Tips Usrah
 
Lmcp 1522 zakat
Lmcp 1522 zakatLmcp 1522 zakat
Lmcp 1522 zakat
 
Khalifah umar bin al khattab r
Khalifah umar bin al khattab rKhalifah umar bin al khattab r
Khalifah umar bin al khattab r
 
Sebab nuzul
Sebab nuzulSebab nuzul
Sebab nuzul
 
Hadith Daif
Hadith DaifHadith Daif
Hadith Daif
 
Calon Ahli Syurga dan Neraka
Calon Ahli Syurga dan NerakaCalon Ahli Syurga dan Neraka
Calon Ahli Syurga dan Neraka
 
Makkiyyah dan Madaniyyah
Makkiyyah dan MadaniyyahMakkiyyah dan Madaniyyah
Makkiyyah dan Madaniyyah
 
SEJARAH KEBUDAYAAN ISLAM
SEJARAH KEBUDAYAAN ISLAMSEJARAH KEBUDAYAAN ISLAM
SEJARAH KEBUDAYAAN ISLAM
 
PENGEMBANGAN KURIKULUM
PENGEMBANGAN KURIKULUMPENGEMBANGAN KURIKULUM
PENGEMBANGAN KURIKULUM
 
Ppt al qur'an
Ppt al qur'anPpt al qur'an
Ppt al qur'an
 
Akidah ahli sunnah wal jamaah
Akidah ahli sunnah wal jamaahAkidah ahli sunnah wal jamaah
Akidah ahli sunnah wal jamaah
 
Sumbangan kerajaan uthmaniyah
Sumbangan kerajaan uthmaniyahSumbangan kerajaan uthmaniyah
Sumbangan kerajaan uthmaniyah
 
PPT ILMU KALAM KELOMPOK 1.pptx
PPT ILMU KALAM KELOMPOK 1.pptxPPT ILMU KALAM KELOMPOK 1.pptx
PPT ILMU KALAM KELOMPOK 1.pptx
 

Similar to Chapter 1-INTRO TO PF.pptx

C programming Tutorial Session 1
C programming Tutorial Session 1C programming Tutorial Session 1
C programming Tutorial Session 1
Muhammad Ehtisham Siddiqui
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
Appili Vamsi Krishna
 
5. Functions in C.pdf
5. Functions in C.pdf5. Functions in C.pdf
5. Functions in C.pdf
santosh147365
 
Chapter 1 - Basic concepts of programming.pdf
Chapter 1 - Basic concepts of programming.pdfChapter 1 - Basic concepts of programming.pdf
Chapter 1 - Basic concepts of programming.pdf
KirubelWondwoson1
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
Manivannan837728
 
C AND DATASTRUCTURES PREPARED BY M V B REDDY
C AND DATASTRUCTURES PREPARED BY M V B REDDYC AND DATASTRUCTURES PREPARED BY M V B REDDY
C AND DATASTRUCTURES PREPARED BY M V B REDDY
Malikireddy Bramhananda Reddy
 
Problem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CProblem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to C
Prabu U
 
Lesson slides for C programming course
Lesson slides for C programming courseLesson slides for C programming course
Lesson slides for C programming course
Jean-Louis Gosselin
 
C PROGRAMMING p-2.pdf
C PROGRAMMING p-2.pdfC PROGRAMMING p-2.pdf
C PROGRAMMING p-2.pdf
D.K.M college for women
 
trial
trialtrial
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
Malikireddy Bramhananda Reddy
 
Notes of c programming 1st unit BCA I SEM
Notes of c programming  1st unit BCA I SEMNotes of c programming  1st unit BCA I SEM
Notes of c programming 1st unit BCA I SEM
Mansi Tyagi
 
Unit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxUnit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptx
saivasu4
 
Embedded C.pptx
Embedded C.pptxEmbedded C.pptx
Embedded C.pptx
MusthafaKadersha
 
C++ language basic
C++ language basicC++ language basic
C++ language basic
Waqar Younis
 
Ch2 C Fundamentals
Ch2 C FundamentalsCh2 C Fundamentals
Ch2 C Fundamentals
SzeChingChen
 
C session 1.pptx
C session 1.pptxC session 1.pptx
C session 1.pptx
NIRMALRAJSCSE20
 
Object oriented programming 7 first steps in oop using c++
Object oriented programming 7 first steps in oop using  c++Object oriented programming 7 first steps in oop using  c++
Object oriented programming 7 first steps in oop using c++
Vaibhav Khanna
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
Batra Centre
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
nTier Custom Solutions
 

Similar to Chapter 1-INTRO TO PF.pptx (20)

C programming Tutorial Session 1
C programming Tutorial Session 1C programming Tutorial Session 1
C programming Tutorial Session 1
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
5. Functions in C.pdf
5. Functions in C.pdf5. Functions in C.pdf
5. Functions in C.pdf
 
Chapter 1 - Basic concepts of programming.pdf
Chapter 1 - Basic concepts of programming.pdfChapter 1 - Basic concepts of programming.pdf
Chapter 1 - Basic concepts of programming.pdf
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
 
C AND DATASTRUCTURES PREPARED BY M V B REDDY
C AND DATASTRUCTURES PREPARED BY M V B REDDYC AND DATASTRUCTURES PREPARED BY M V B REDDY
C AND DATASTRUCTURES PREPARED BY M V B REDDY
 
Problem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CProblem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to C
 
Lesson slides for C programming course
Lesson slides for C programming courseLesson slides for C programming course
Lesson slides for C programming course
 
C PROGRAMMING p-2.pdf
C PROGRAMMING p-2.pdfC PROGRAMMING p-2.pdf
C PROGRAMMING p-2.pdf
 
trial
trialtrial
trial
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
 
Notes of c programming 1st unit BCA I SEM
Notes of c programming  1st unit BCA I SEMNotes of c programming  1st unit BCA I SEM
Notes of c programming 1st unit BCA I SEM
 
Unit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxUnit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptx
 
Embedded C.pptx
Embedded C.pptxEmbedded C.pptx
Embedded C.pptx
 
C++ language basic
C++ language basicC++ language basic
C++ language basic
 
Ch2 C Fundamentals
Ch2 C FundamentalsCh2 C Fundamentals
Ch2 C Fundamentals
 
C session 1.pptx
C session 1.pptxC session 1.pptx
C session 1.pptx
 
Object oriented programming 7 first steps in oop using c++
Object oriented programming 7 first steps in oop using  c++Object oriented programming 7 first steps in oop using  c++
Object oriented programming 7 first steps in oop using c++
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 

Recently uploaded

Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
melliereed
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
JomonJoseph58
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 

Recently uploaded (20)

Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 

Chapter 1-INTRO TO PF.pptx

  • 1. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH DFC 20113 PROGRAMMING FUDAMENTALS CHAPTER 1 INTRODUCTION TO FUNDAMENTALS OF PROGRAMMING MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH
  • 2. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH COURSE LEARNING OUTCOMES CLO 1: Implement programming element and articulate how they are used to achieve a working program. ( C3, PLO 2 ) CLO 2: Show simple programs by developing code to solve problems in a computer using C++ programming language. ( P2, PLO 3 )
  • 3. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH LEARNING OUTCOMES at the end of this sub-chapter, students should be able to: • Describe the item in C++ program structure • Comments • Preprocessor directives • Header files • main() function • return statements. • Describe two types of comments that supported by C++ program • Explain coding standard best practices 1.1 Define the C++ program basic structure
  • 4. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE • Probably the best way to start learning a programming language is by writing a program. • Therefore, here is our first program: // my first program in C++ #include <iostream.h> int main () { cout << “My First Program!"; return 0; } Output: My First Program! OUTPUT SOURCE CODE
  • 5. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH a) Comment Style •Entries in the source code which are ignored by the compiler •C++ support 2 style/form of comments: i.//Single Line Comments  for simple 'side' notes  best places to put these comments are next to variable declarations, and next to pieces of code that may need explanation. ii./ *block comment */or /*Multi-Line Comments*/  most useful for long explanations of code.  useful for two reasons: They make your functions easier to understand, and they make it easier to spot errors in code. 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 6. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH • Illustrate the valid & invalid comments within a program. Comment statements // this program displays a message valid / this program displays a message invalid // this comment is invalid because its extend over two lines invalid // this comment is used a comment that //extend across two lines valid /*this comment is a block comment that spans three lines*/ valid 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 7. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH b) Pre Processor Directive • What’s a #? • Any line that begins with # symbol is a pre-processor directive • Processed by preprocessor before compiling • What’s pre-processor? • A utility program, which processes special instructions are written in a C/C++ program. • Include a library or some special instructions to the compiler about some certain terms used in the program • Different preprocessor directives (commands) perform different tasks. • Uses for? • It is a message directly to the compiler. 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 8. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH • How to write/syntax ? • Begin with # • No semicolon (;) is expected at the end of a preprocessor directive. • Example: Pre-processor directive Meaning #include <iostream> Tells preprocessor to include the input/output stream header file <iostream> #define NAME “BOB” Define a constant 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 9. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH c) Header File • sometimes known as an include file. Header files almost always have a .h extension. • Why use? • For big projects having all the code in one file is impractical. But if we split the project into smaller files, how can we share functions between them? Headers!  The purpose of a header file?  To hold declarations for other files to use.  When we use the line #include <iostream>, we are telling the compiler to locate and then read all the declarations from a header file named “iostream”. 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 10. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH • Consider the following program:  Program never declare cout, so how does the compiler know what cout is?  The answer is that cout has been declared in a header file called “iostream”. Bear in mind that header files typically only contain declarations. They do not define how something is implemented 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 11. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH d) Main Function • This line corresponds to the beginning of the definition of the main function. • A part of every C++ program and identify the start of the program Exactly one function in a program must be main main is a Keyword. • Keyword : A word in code that is reserved by C++ for a specific use. • Header of function main? int main( ) 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 12. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH • The structure of a main Function: int main ( ) { C++ program statements goes here; return 0; } Function body Type of return value Function name An empty argument list 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 13. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH • 4 common ways of main declaration: int main() { return 0; } void main() { } main(void) { } main( ) { } 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 14. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH e) Curly Braces {} • Body is delimited by braces ({ }) • Identify a segment / body of a program The start and end of a function The start and end of the selection or repetition block. • Since the opening brace indicates the start of a segment with the closing brace indicating the end of a segment, there must be just as many opening braces as closing braces 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 15. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH f) C++ statement • What's? A specification of an action to be taken by the computer as the program executes. Instruct the program to perform an action • Syntax? All statements end with a semicolon (;) • Statement has two parts : Declaration • The part of the program that tells the compiler the names of memory cells in a program Executable statements • Program lines that are converted to machine language instructions and executed by the computer 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 16. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH g) Return Statement • Means? The return statement causes the main function to finish. Return may be followed by a return code (in our example is followed by the return code with a value of zero). A return code of 0 for the main function is generally interpreted as the program worked as expected without any errors during its execution. • When used?  At the end of main 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 17. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH Two situations for return statement: a) Return optional in void functions A void function doesn't have to have a return statement when the end is reached, it automatically returns. 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 18. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH b) Return required in non-void functions  If a function returns a value, it must have a return statement that specifies the value to return.  It's possible to have more than one return.  Example 1: return 0; Return the value 0 to the computer's operating system to signal that the program has completed successfully 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 19. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH • Coding Standards Best Practices Refer this link: https://google.github.io/styleguide/cppguide.html 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 20. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH • Importance of following coding standards best practices: easier for a developer to understand easier to find and correct bugs provides a better view of how that code fits within the larger application easier for someone to maintain that code 1.1 INTRODUCE THE C++ PROGRAM BASIC STRUCTURE
  • 21. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH PROGRAMMING EXERCISE Ahmad are asked to create a program that can calculate the area of rectangle. He need to identify the IPO, draw a flowchart and create a program. You are asked to help Ahmad.
  • 22. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH LEARNING OUTCOMES at the end of this sub-chapter, students should be able to: • Explain identifier, variable and constant. • State the rules for naming an identifier. • Name the variables according the standards • Explain the data types. • List the data types and their respective range with examples: • Integer • Floating point • Character • Boolean • String 1.2 Explain identifier and data types
  • 23. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH • IDENTIFIER: Words used to represent certain program entities (variables, function names, etc). • VARIABLE is identifier whose value can change during the course of execution of a program • KEYWORDS (reserved words) have standard, predefined meanings and must be used only for their intended purpose. It cannot be used as an identifier. • CONSTANTS are values that do not change during program execution. They can be any type of integer, character or floating-point. 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 24. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH a) Identifier • Words used to represent certain program entities (variables, function names, etc). • Example: • int number; • number is an identifier used as a program variable • void CalculateTotal (int value) • CalculateTotal is an identifier used as a function name 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 25. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH b) Variables • What's? Is a Location in memory which: we can refer to by an identifier, and in which a data value that can be change Where value can be stored • Common data types (fundamental, primitive or built-in) int – integer numbers : 1, 2, 4,…. char – characters : ‘a’, ‘c’, … float, double: floating point numbers: 2.5, 4.96 • The value of a variable could be changed while the program is running. • Declaring a variable means specifying both its name and its data type. 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 26. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH EXAMPLE OF VARIABLES  int is an abbreviation for integer. • Integer store value: 3, 102, 3211, -456, etc. • Example variable : number_of_bars  double represents numbers with a fractional component • double store value: 1.34, 4.0, -345.6, etc. • Example variable : one_weight ,total_weight 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 27. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH c) Constant • Entities that appear in the program code as fixed values. • Any attempt to modify a CONSTANT will result in error. • Declared using the const qualifier • Also called named constants or read-only variables • Must be initialized with a constant expression when they are declared and cannot be modified • Example: const int size = 5; 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 28. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH Types of constant: 1. Literals Literals are the most obvious kind of constants. They are used to express particular values within the source code of a program.  e.g: a=5; grade=‘A’; 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 29. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH Types of constant: 2. Define Constant (#define) You can define your own names for constants that you use very often without having to resort to memory-consuming variables, simply by using the #define preprocessor directive.  Its format is: #define identifier value Examples: #define PI 3.14159 #define GRAVITY 9.8 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 30. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH Types of Constant: 3. Declared Constants With the const prefix you can declare constants with A specific type in the same way as you would do with A variable: const int pathwidth = 100; const char grade = ‘A'; They are treated just like regular variables except that their values cannot be modified after their definition. 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 31. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH Rules Example Can contain a mix of character and numbers. However it cannot start a number H2o First character must be a letter or underscore Number1, _area Can be of mixed cases including underscore character XsquAre my_num Cannot contain any arithmetic operators R*S+T … or any other punctuation marks #@x%!! Cannot be a C keyword/reserved word struct; cout; Cannot contain a space My height … identifiers are case sensitive Tax != tax NAMING CONVENTION RULES FOR IDENTIFIER 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 32. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH • They are formed by combining letters, digits & underscores. • Blank space is not allowed in an identifier. • The first character of an identifier must be a letter. Valid Invalid Reason Monthly_Salary Monthly Salary Blank space cannot be used Month1 1stMonth Digit cannot be used as a first character Email_add email@ Special characters cannot be used 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 33. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH • Why variables needed in programming? Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their purpose is to label and store data in memory. This data can then be used throughout a program. 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 34. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH • When we create a program, we store the variables in our computer's memory. • But the computer has to know what kind of data we want to store in them. • Since it is not going to occupy the same amount of memory to store a simple number than to store a single letter or a large number. • They are not going to be interpreted the same way. Basic Data Types 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 35. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH DATA TYPES Numeric • int • float • double Non-numeric • char • string • bool 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 36. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH Name Description Size* Range* string Sequence of character. 10 bytes + string length 0 to approximately 2 billion char Character or small integer. 1byte signed: -128 to 127 unsigned: 0 to 255 bool Boolean value. It can take one of two values: true or false. 1byte true or false float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits) int Integer. 4bytes signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 double Double precision floating point number. 8bytes +/- 1.7e +/- 308 (~15 digits) 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 37. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH • There are 6 basic data types : i. char • equivalent to ‘letters’ in English language • Example of characters: • Numeric digits: 0 - 9 • Lowercase/uppercase letters: a - z and A - Z • Space (blank) • Special characters: , . ; ? “ / ( ) [ ] { } * & % ^ < > etc • single character • keyword: char • Example code: • Sample values ‘B’ ‘d’ ‘4’ ‘?’ ‘*’ The declared character must be enclosed within a single quote! char my_letter; my_letter = 'U'; 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 38. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH ii. int • used to declare numeric program variables of integer type • whole numbers, positive and negative • keyword: int • Example code : • Sample values: 4578 -4578 0 int number; number = 12; 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 39. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH iii. double • used to declare floating point variable of higher precision or higher range of numbers • exponential numbers, positive and negative • keyword: double • Code example: double valuebig; valuebig = 12E-3; 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 40. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH iv. float • fractional parts, positive and negative • real numbers with a decimal point • keyword: float • Example code: • sample values 95.274 95.5 2.265 float height; height = 1.72; 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 41. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH v. bool • The bool data type is capable of holding a Boolean value. • Objects of type bool may have only the values true or false. • To declare a variable of type bool: bool old_enough; 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 42. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH vi. string • a string is a sequence of characters enclosed in double quotes • string sample values: “Hello” “Year 2000” “1234” • the empty string (null string) contains no characters and is written as “ ” • Example code: 1.2 EXPLAIN IDENTIFIER AND DATA TYPES string name = “Ahmad Albab”;
  • 43. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH // operating with variables #include <iostream> Using namespace std; int main () { // declaring variables int a, b, result; // process: a = 5; b = 2; a = a + 1; result = a - b; // print out the result: cout << result; // terminate the program: return 0; } Output: 4 Example 1: 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 44. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH // operating with variables #include <iostream> using namespace std; int main () { // declaring variables string name; //get input from user cout<<“Enter your name: “; cin>>name; // print out name: cout <<“Your name: “<<name; // terminate the program: return 0; } Output: Enter your name: ALI Your name: ALI Example 2: 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 45. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH LEARNING OUTCOMES AT THE END OF THIS SUB-CHAPTER, STUDENTS SHOULD BE ABLE TO: • Describe the features of C++ language. • Develop C++ program using Integrated Development Enviroment (IDE). • Get started with IDE • Create a project file • Create a simple C++ program • Compile a C++ program • Run a C++ program 1.3 Identify the basic of computer program
  • 46. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH 1.3 APPLY THE BASIC OF COMPUTER PROGRAM Features of C++ language C++ is object oriented programming language and it is a very simple and easy language, this language have following features.
  • 47. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH • Simple Every C++ program can be written in simple English language so that it is very easy to understand and developed by programmer. • Portability It is the concept of carrying the instruction from one system to another system. In C++ Language .cpp file contain source code, we can edit also this code. .exe file contain application, only we can execute this file. When we write and compile any C++ program on window operating system that program easily run on other window based system. • Powerful C++ is a very powerful programming language, it have a wide verity of data types, functions, control statements, decision making statements, etc. • Platform dependent A language is said to be platform dependent whenever the program is execute in the same operating system where that was developed and compiled but not run and execute on other operating system. C++ is platform dependent language. • Object oriented This main advantage of C++ is, it is object oriented programming language. It follow concept of oops like polymorphism, inheritance, encapsulation, abstraction. 1.3 APPLY THE BASIC OF COMPUTER PROGRAM
  • 48. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH • Case sensitive C++ is a case sensitive programming language. In C++ programming 'break and BREAK' both are different. If any language treats lower case latter separately and upper case latter separately than they can be called as case sensitive programming language [Example c, c++, java, .net are sensitive programming languages.] other wise it is called as case insensitive programming language [Example HTML, SQL is case insensitive programming languages]. • Compiler based C++ is a compiler based programming language that means without compilation no C++ program can be executed. First we need compiler to compile our program and then execute. • Syntax based language C++ is a strongly tight syntax based programming language. If any language follow rules and regulation very strictly known as strongly tight syntax based language. Example C, C++, Java, .net etc. If any language not follow rules and regulation very strictly known as loosely tight syntax based language. Example HTML. • Use of Pointers Pointers is a variable which hold the address of another variable, pointer directly direct access to memory address of any variable due to this performance of application is improve. In C++ language also concept of pointer are available. 1.3 APPLY THE BASIC OF COMPUTER PROGRAM
  • 49. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH Integrated Development Environment An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. All of the tools for writing, compiling and testing code in one place. An IDE normally consists of: - a source code editor - a compiler and/or an interpreter - build automation tools - a debugger 1.3 APPLY THE BASIC OF COMPUTER PROGRAM
  • 50. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH Get start with IDE Software: Dev C++ Compile Execute New file Compile & Execute 1.3 APPLY THE BASIC OF COMPUTER PROGRAM
  • 51. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH • Create a simple C++ program: • Compile and run your code. Then display the output. Write a program to display your name, registration number and department in separate line. 1.3 APPLY THE BASIC OF COMPUTER PROGRAM
  • 52. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH S O L U T I O N 1.3 APPLY THE BASIC OF COMPUTER PROGRAM
  • 53. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH LEARNING OUTCOMES AT THE END OF THIS SUB-CHAPTER, STUDENTS SHOULD BE ABLE TO: •Describe the compiling process of a program •Source code •Compiler •Linker •Executable file •Describe with example the errors in programming: •Syntax/ compile time errors •Run time errors •Logical errors •Identify effective debugging process •Debug simple programs to demonstrate syntax/ compile time, run time and logical error 1.4 Describe the compiling and debugging process and errors in programming
  • 54. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH 1.4 IDENTIFY THE COMPILING AND DEBUGGING PROCESS, AND ERRORS IN PROGRAMMING. COMPILING PROCESS • A compiler is a computer program (or set of programs) that transforms source code written in a computer language (the source language) into another computer language (the target language, often having a binary form known as object code). • The most common reason for wanting to transform source code is to create an executable program.
  • 55. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH 1.4 IDENTIFY THE COMPILING AND DEBUGGING PROCESS, AND ERRORS IN PROGRAMMING.
  • 56. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH HOW C++ WORKS? https://www.youtube.com/watch?v=ZTu0kf-7h08 1.4 IDENTIFY THE COMPILING AND DEBUGGING PROCESS, AND ERRORS IN PROGRAMMING.
  • 57. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH ERRORS IN PROGRAMMING ERRORS Syntax/ Compile Run Time Logical 1.4 IDENTIFY THE COMPILING AND DEBUGGING PROCESS, AND ERRORS IN PROGRAMMING.
  • 58. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH Error Descriptions Common examples Syntax errors/ compile error Grammar errors in the of the programming language.  Misspelled variable and function names.  Missing semicolons(;)  Improperly matches parentheses, square ], and curly braces{ }  Incorrect format in selection and loop statements Run time errors Occur when a program with no syntax errors asks the computer to do something that the computer is unable to reliably do. Trying to divide by a variable that contains a of zero Trying to open a file that doesn't exist There is no way for the compiler to know about these kinds of errors when the program is Logic errors Logic errors occur when there is a design flaw in your program. Multiplying when you should be dividing Adding when you should be subtracting Opening and using data from the wrong file Displaying the wrong message 1.4 IDENTIFY THE COMPILING AND DEBUGGING PROCESS, AND ERRORS IN PROGRAMMING.
  • 59. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH SPECIAL CHARACTERS IN C++ PROGRAMMING SYNTAX Character Name Meaning // Double slash Beginning of a comment # Pound sign Beginning of preprocessor directive < > Open/close brackets Enclose filename in #include ( ) Open/close parentheses Used when naming a function { } Open/close brace Encloses a group of statements " " Open/close quotation marks Encloses string of characters ; Semicolon End of a programming statement 1.4 IDENTIFY THE COMPILING AND DEBUGGING PROCESS, AND ERRORS IN PROGRAMMING.
  • 60. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH WHAT IS DEBUGGING??? • Debugging is the process of locating and fixing or by passing bugs (errors) in computer program code or the engineering of a hardware device. • Debugging is a generalized term which essentially means to step through a process in order to systematically eliminate errors. 1.4 IDENTIFY THE COMPILING AND DEBUGGING PROCESS, AND ERRORS IN PROGRAMMING.
  • 61. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH DEBUG PROGRAMS WITH SYNTAX / COMPILE TIME, RUN TIME AND LOGICAL ERROR Do in Lab Activity 1
  • 62. MADAM SITI ZAHARAH BINTI SIDEK | JTMK, POLITEKNIK MUADZAM SHAH THE END