Chapter 1 (Solid Mechanics).ppt
INTRODUCTION TO
COMPUTER
PROGRAMS
1
Chapter
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 3
At the end of this chapter, you should be able to:
Understand the concepts and importance of programs
and programming.
Differentiate between program, compiler, interpreter and
assembler.
Apply the steps in the program development life cycle.
Learning Outcomes
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 4
Introduction
 Computers can be found anywhere from the size of a
desktop to smaller than the palm of one’s hand such as
desktop computers, notebooks, netbooks, tablet PCs
and mobile devices.
 Many kinds of applications or apps can be downloaded
into the tablet or smartphone.
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 5
Introduction (cont.)
 There are many ways to develop these applications.
– Some websites provide templates to create apps
quickly
– Users with programming knowledge can create their
apps from scratch.
 Examples of systems/apps developed using
programming language:
– Automated Teller Machine (ATM) systems,
– Student Information Systems
– Online Ticketing Systems
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 6
Overview of Computers
and History of
Programming Language
19th
Century
• first general purpose computing device.
20th
Century
• early analogue computers have been invented.
1936
• first freely programmable computers were developed.
1940s
• electronic programmable computers using vacuum tubes and transistors have
been created.
1950-1960s
• commercial computers, computer games and programming languages were
developed.
1975
• mainframes and supercomputers were available.
1981
• IBM introduced its personal computers
1983
• The first personal computer with a graphical user interface was introduced
H
I
S
T
O
R
Y
O
F
C
O
M
P
U
T
E
R
S
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 7
Basic Operation of a Computer
 A computer is a device that can process data.
 Data consists of raw facts or unprocessed information.
• Input – accepts data from user
• Process – manipulate data
• Output – produce result
• Storage – store result
Basic operation of a computer
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 8
Computer Components
 Computers are electronic devices capable of performing
computations and making logical decisions at speeds
faster than human beings.
Hardware Software
Computer Component
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 9
Language of a Computer
 Computers can only understand machine language.
 Machine language is also called binary numbers or
binary code, which is a sequence of 0s and 1s.
 The digits 0 and 1 are called binary digits or bits.
 A sequence of 8 bits is called a byte.
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 10
 machine dependent
 language is
mnemonic
 use assembler as
translator to
translate to machine
language
 machine independent
 the instructions are quite
English-like
 use compiler/interpreter as
translator to translate to
machine language
 Example: JAVA, C++, COBOL
Types of Programming Language
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 11
Types of Programming Language
(cont.)
 Example:
To calculate the BMI of a user given the formula:
height(m)
x
(m)
height
(kg)
weight
BMI 
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 12
Differences Between
Programs and Programming
 A program is a set of instructions that tell the computer how to
solve a problem or perform a task.
 Programming is the process of designing and writing computer
programs.
 A program is like a recipe. It contains a list of ingredients (variables)
and a list of directions (statements) that tell the computer what to do
with the variables.
 A program can be as short as one line of code, or as long as several
million lines of code.
 Computer programs guide the computer through orderly sets of
actions specified by the computer programmers.
 The programmer must decide what the programs need to do,
develop the logic of how to do it and write instructions for the
computer in a programming language that the computer can
translate into its own language and execute.
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 13
The Importance of Computer
Programming
 Able to perform difficult tasks without making human-type errors
such as lack of focus, energy, attention or memory.
 Capable of performing extended tasks at greater serial speeds than
conscious human thoughts.
 Human brain cannot be duplicated or ‘re-booted’ like computers,
and has already achieved ‘optimization’ through design by
evolution, making it difficult to upgrade.
 Human brain does not physically integrate well, externally or
internally with current hardware and software.
 Non-existence of boredom in computers when performing repetitive
tasks allows jobs to be done faster and more efficiently.
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 14
The Importance of Writing a Good
Program
Names for variables, types and functions
 Variables and constants are storage locations in the computer’s
memory that match with associated names known as identifiers.
 The following are some standards that can be used when naming
variables, constants, types and functions:
1. Function names will start with a lowercase letter.
Example: double calculateBMI (double, double);
2. Variable names start with a lowercase letter and the length must
not be more than 40 characters.
Example: double weight, height;
3. Constant names can be all in capital letters.
Example: const int MAX_SIZE =10;
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 15
The Importance of Writing a Good
Program (cont.)
Indentation styles and spacing
In order to improve readability in programming, indentation can be
used to format the program source code.
• A text editor is used to create a program by following the rules or
syntax of different programming languages.
Spaces can also be added in between sentences to make programs
much more readable.
A new level of indentation should be used at every level of statement
nesting in the program.
The minimum number of spaces at each indentation should be at
least three.
• Many programmers use a tab mark (typically 8 spaces) which will be
easier when indenting source code.
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 16
The Importance of Writing a Good
Program (cont.)
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 17
C++ Relationship Between
Programs, Compiler, Interpreter and
Assembler
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 18
C++ Program Structure
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 19
C++ Program Structure (cont.)
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 20
The Flow of Program Execution
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 21
Comments
 Important in any program as they are very useful for documentation but it is
not compulsory to write comments in programs.
– Comments are not source code, thus they will not be read by the
compiler.
 Can be written in any way, according to the programmers’ preferences
 Explain the purpose, parts of the program and keep notes regarding
changes to the source code
 Store programmers’ name for future reference.
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 22
Pre-processor Directive
 Also known as a header file in C++.
 It is a line of code that begins with the # symbol.
 Header files are not executable code lines but instructions to the
compiler.
 Header files are usually included at the top of the program before
the main function.
 The most common and important header file is
#include<iostream>.
– This header file tells the pre-processor to include the contents of
the file <iostream> which are the input and output operations
(such as printing to the screen).
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 23
Function
 Main Function
– Every C++ program contains one or more functions,
but one of it must be named as main .
– A function is a block of code that carries out specific
tasks.
– Generally, a main function starts with the function
type void or int before it is followed by the word
main and a pair of parentheses ().
– It is more advisable to write the function type int in
the main function but the word return 0 must be
written at the end of the function before it is closed.
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 24
 Braces
– Body of the main function which is enclosed in braces
{}.
• Used to mark the beginning and end of blocks of
code in any program.
• The open brace { is placed at the beginning of
code after the main function and the close brace }
is used to show the closing of code.
• The code after the } will not be read/evaluated by
the compiler.
Function (cont.)
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 25
Function (cont.)
 Statement
– A function consists of a sequence of statements that
perform the work of the function.
– Every statement in C++
ends with a semicolon (;).
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 26
Program Development
Life Cycle
 The process of developing a program is called program
development.
 The process associated with creating successful
application programs is called the Program
Development Life Cycle (PDLC).
Analysis Design
Implementatio
n/Coding
Testing/
Debugging Maintenance
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 27
Analysis
 First step in the Program Development Life Cycle
(PDLC).
 This process is done by reviewing the program
specifications.
 Other criteria must also be identified, especially the data
that will be used as input, the process involved and the
output that will be produced.
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 28
Design
 A programmer needs to develop a series of steps with
logical order, which when applied would produce the
output of the problem.
 A solution is created using a structured programming
technique known as algorithm, which consists of
pseudocode and flowchart.
– A procedure or formula for solving a problem.
– A step-by-step problem solving process where the
result is attained in a limited amount of time.
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 29
Design (cont.)
 Some requirements must be satisfied when creating an
algorithm:
1. Unambiguousness
2. Generality
3. Correctness
4. Finiteness
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 30
 Before an algorithm is created, the three types of control
structure should be understood first.
 A control structure is a pattern to control the flow of a
program module.
Design (cont.)
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 31
Pseudocode
 A semiformal, English-like language with a limited
vocabulary used to design and describe algorithms.
 Every statement in pseudocode involves keywords
which define the process and operands.
 Each pseudocode statement should be written in a
separate line.
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 32
Pseudocode (cont.)
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 33
Flow Chart
 A graphic presentation of the detailed logical sequence
of steps needed to solve programming problems.
 Uses geometric symbols where different symbols are
used to represent different actions such as start/stop,
decision, input/output, processing and looping.
 Similar to pseudocode, keywords are written in
uppercase, while variable and constant names as well
as operations for the statements are written in lower
case.
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 34
Flow Chart (cont.)
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 35
Flow Chart (cont.)
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 36
Flow Chart (cont.)
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 37
Flow Chart (cont.)
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 38
Flow Chart (cont.)
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 39
Implementation/Coding
 The pseudocode and flow chart which have been done
in the design step will be converted into a program by
using certain programming languages such as BASIC,
JAVA, C or C++.
 This step solves the problem by enabling the user to
start writing the programs.
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 40
 Coding is the actual process of creating a program in a
programming language.
 The coded program is referred to as source code.
– Must follow certain rules which are called syntax.
– Must then be saved as a program which has the
extension ‘.cpp’.
 To be executed, the program is converted by the
computer into object code using a special program or
translator such as a compiler or interpreter.
Implementation/Coding (cont.)
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 41
Testing/Debugging
 The step for checking and verifying the correctness of
the program.
 The process of making sure a program is free of errors
or ‘bugs’ is called debugging.
 Preliminary debugging begins after the program has
been entered into the computer system.
All Rights Reserved
INTRODUCTION C++ PROGRAMMING
© Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 42
Maintenance
 Last step in the Program Development Life Cycle
(PDLC).
 Essentially, every program, if it is to last a long time,
requires ongoing maintenance.
 A process of updating software for any changes,
corrections, additions, moving to a different computing
platform and others so that it continues to be useful.
 A costly process.
 Can be very useful especially on extending the life of a
program.

More Related Content

PPT
Chapter 1
PDF
Cp week _2.
PDF
An introduction to programming
PPTX
Whole c++ lectures ITM1 Th
PDF
C++ advanced PPT.pdf
PDF
Introduction to c++
PPTX
introductiontocprogramming datatypespp.pptx
PPT
Programming of c++
Chapter 1
Cp week _2.
An introduction to programming
Whole c++ lectures ITM1 Th
C++ advanced PPT.pdf
Introduction to c++
introductiontocprogramming datatypespp.pptx
Programming of c++

Similar to Chapter 1 (Solid Mechanics).ppt (20)

PDF
Introduction to c++ ppt
PPTX
Object oriented programming 11 preprocessor directives and program structure
PPT
Ffghhhhfghhfffhjdsdhjkgffjjjkfdghhftgdhhhggg didi ucch JFK bcom
PPTX
Paksitan Zindabad in ITDevelopment of IT
PPT
Basic structure of C++ program
PPT
C PLUS PLUS FOR BS ELECTRICAL 2ND SEMSTERLecture01.ppt
PPT
01 introduction to cpp
DOCX
Comso c++
PPT
Overview of c++
PDF
PPT
2621008 - C++ 1
PDF
C Programming Program design including data structures 5ed. Edition Malik D.S.
PPTX
Introduction to c++ programming language
PDF
C Programming Program design including data structures 5ed. Edition Malik D.S.
PDF
C Programming Program Design Including Data Structures 5th Edition D. S. Malik
PDF
A Complete Guide to Programming in C 1st Edition Ulla Kirch-Prinz
PPTX
OODP Unit 1 OOPs classes and objects
PPT
C++ programming program design including data structures
PPTX
Chap_________________1_Introduction.pptx
PDF
C Programming Program Design Including Data Structures 5th Edition D. S. Malik
Introduction to c++ ppt
Object oriented programming 11 preprocessor directives and program structure
Ffghhhhfghhfffhjdsdhjkgffjjjkfdghhftgdhhhggg didi ucch JFK bcom
Paksitan Zindabad in ITDevelopment of IT
Basic structure of C++ program
C PLUS PLUS FOR BS ELECTRICAL 2ND SEMSTERLecture01.ppt
01 introduction to cpp
Comso c++
Overview of c++
2621008 - C++ 1
C Programming Program design including data structures 5ed. Edition Malik D.S.
Introduction to c++ programming language
C Programming Program design including data structures 5ed. Edition Malik D.S.
C Programming Program Design Including Data Structures 5th Edition D. S. Malik
A Complete Guide to Programming in C 1st Edition Ulla Kirch-Prinz
OODP Unit 1 OOPs classes and objects
C++ programming program design including data structures
Chap_________________1_Introduction.pptx
C Programming Program Design Including Data Structures 5th Edition D. S. Malik
Ad

Recently uploaded (20)

PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PDF
Design Guidelines and solutions for Plastics parts
PDF
Soil Improvement Techniques Note - Rabbi
PDF
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
PPTX
mechattonicsand iotwith sensor and actuator
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PPTX
Amdahl’s law is explained in the above power point presentations
PPTX
Management Information system : MIS-e-Business Systems.pptx
PPTX
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
PDF
20250617 - IR - Global Guide for HR - 51 pages.pdf
PPTX
Information Storage and Retrieval Techniques Unit III
PPTX
Measurement Uncertainty and Measurement System analysis
PPTX
Module 8- Technological and Communication Skills.pptx
PDF
First part_B-Image Processing - 1 of 2).pdf
PDF
MLpara ingenieira CIVIL, meca Y AMBIENTAL
PDF
Abrasive, erosive and cavitation wear.pdf
PPTX
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
PPTX
"Array and Linked List in Data Structures with Types, Operations, Implementat...
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Design Guidelines and solutions for Plastics parts
Soil Improvement Techniques Note - Rabbi
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
Exploratory_Data_Analysis_Fundamentals.pdf
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
mechattonicsand iotwith sensor and actuator
distributed database system" (DDBS) is often used to refer to both the distri...
Amdahl’s law is explained in the above power point presentations
Management Information system : MIS-e-Business Systems.pptx
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
20250617 - IR - Global Guide for HR - 51 pages.pdf
Information Storage and Retrieval Techniques Unit III
Measurement Uncertainty and Measurement System analysis
Module 8- Technological and Communication Skills.pptx
First part_B-Image Processing - 1 of 2).pdf
MLpara ingenieira CIVIL, meca Y AMBIENTAL
Abrasive, erosive and cavitation wear.pdf
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
"Array and Linked List in Data Structures with Types, Operations, Implementat...
Ad

Chapter 1 (Solid Mechanics).ppt

  • 3. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 3 At the end of this chapter, you should be able to: Understand the concepts and importance of programs and programming. Differentiate between program, compiler, interpreter and assembler. Apply the steps in the program development life cycle. Learning Outcomes
  • 4. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 4 Introduction  Computers can be found anywhere from the size of a desktop to smaller than the palm of one’s hand such as desktop computers, notebooks, netbooks, tablet PCs and mobile devices.  Many kinds of applications or apps can be downloaded into the tablet or smartphone.
  • 5. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 5 Introduction (cont.)  There are many ways to develop these applications. – Some websites provide templates to create apps quickly – Users with programming knowledge can create their apps from scratch.  Examples of systems/apps developed using programming language: – Automated Teller Machine (ATM) systems, – Student Information Systems – Online Ticketing Systems
  • 6. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 6 Overview of Computers and History of Programming Language 19th Century • first general purpose computing device. 20th Century • early analogue computers have been invented. 1936 • first freely programmable computers were developed. 1940s • electronic programmable computers using vacuum tubes and transistors have been created. 1950-1960s • commercial computers, computer games and programming languages were developed. 1975 • mainframes and supercomputers were available. 1981 • IBM introduced its personal computers 1983 • The first personal computer with a graphical user interface was introduced H I S T O R Y O F C O M P U T E R S
  • 7. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 7 Basic Operation of a Computer  A computer is a device that can process data.  Data consists of raw facts or unprocessed information. • Input – accepts data from user • Process – manipulate data • Output – produce result • Storage – store result Basic operation of a computer
  • 8. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 8 Computer Components  Computers are electronic devices capable of performing computations and making logical decisions at speeds faster than human beings. Hardware Software Computer Component
  • 9. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 9 Language of a Computer  Computers can only understand machine language.  Machine language is also called binary numbers or binary code, which is a sequence of 0s and 1s.  The digits 0 and 1 are called binary digits or bits.  A sequence of 8 bits is called a byte.
  • 10. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 10  machine dependent  language is mnemonic  use assembler as translator to translate to machine language  machine independent  the instructions are quite English-like  use compiler/interpreter as translator to translate to machine language  Example: JAVA, C++, COBOL Types of Programming Language
  • 11. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 11 Types of Programming Language (cont.)  Example: To calculate the BMI of a user given the formula: height(m) x (m) height (kg) weight BMI 
  • 12. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 12 Differences Between Programs and Programming  A program is a set of instructions that tell the computer how to solve a problem or perform a task.  Programming is the process of designing and writing computer programs.  A program is like a recipe. It contains a list of ingredients (variables) and a list of directions (statements) that tell the computer what to do with the variables.  A program can be as short as one line of code, or as long as several million lines of code.  Computer programs guide the computer through orderly sets of actions specified by the computer programmers.  The programmer must decide what the programs need to do, develop the logic of how to do it and write instructions for the computer in a programming language that the computer can translate into its own language and execute.
  • 13. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 13 The Importance of Computer Programming  Able to perform difficult tasks without making human-type errors such as lack of focus, energy, attention or memory.  Capable of performing extended tasks at greater serial speeds than conscious human thoughts.  Human brain cannot be duplicated or ‘re-booted’ like computers, and has already achieved ‘optimization’ through design by evolution, making it difficult to upgrade.  Human brain does not physically integrate well, externally or internally with current hardware and software.  Non-existence of boredom in computers when performing repetitive tasks allows jobs to be done faster and more efficiently.
  • 14. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 14 The Importance of Writing a Good Program Names for variables, types and functions  Variables and constants are storage locations in the computer’s memory that match with associated names known as identifiers.  The following are some standards that can be used when naming variables, constants, types and functions: 1. Function names will start with a lowercase letter. Example: double calculateBMI (double, double); 2. Variable names start with a lowercase letter and the length must not be more than 40 characters. Example: double weight, height; 3. Constant names can be all in capital letters. Example: const int MAX_SIZE =10;
  • 15. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 15 The Importance of Writing a Good Program (cont.) Indentation styles and spacing In order to improve readability in programming, indentation can be used to format the program source code. • A text editor is used to create a program by following the rules or syntax of different programming languages. Spaces can also be added in between sentences to make programs much more readable. A new level of indentation should be used at every level of statement nesting in the program. The minimum number of spaces at each indentation should be at least three. • Many programmers use a tab mark (typically 8 spaces) which will be easier when indenting source code.
  • 16. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 16 The Importance of Writing a Good Program (cont.)
  • 17. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 17 C++ Relationship Between Programs, Compiler, Interpreter and Assembler
  • 18. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 18 C++ Program Structure
  • 19. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 19 C++ Program Structure (cont.)
  • 20. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 20 The Flow of Program Execution
  • 21. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 21 Comments  Important in any program as they are very useful for documentation but it is not compulsory to write comments in programs. – Comments are not source code, thus they will not be read by the compiler.  Can be written in any way, according to the programmers’ preferences  Explain the purpose, parts of the program and keep notes regarding changes to the source code  Store programmers’ name for future reference.
  • 22. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 22 Pre-processor Directive  Also known as a header file in C++.  It is a line of code that begins with the # symbol.  Header files are not executable code lines but instructions to the compiler.  Header files are usually included at the top of the program before the main function.  The most common and important header file is #include<iostream>. – This header file tells the pre-processor to include the contents of the file <iostream> which are the input and output operations (such as printing to the screen).
  • 23. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 23 Function  Main Function – Every C++ program contains one or more functions, but one of it must be named as main . – A function is a block of code that carries out specific tasks. – Generally, a main function starts with the function type void or int before it is followed by the word main and a pair of parentheses (). – It is more advisable to write the function type int in the main function but the word return 0 must be written at the end of the function before it is closed.
  • 24. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 24  Braces – Body of the main function which is enclosed in braces {}. • Used to mark the beginning and end of blocks of code in any program. • The open brace { is placed at the beginning of code after the main function and the close brace } is used to show the closing of code. • The code after the } will not be read/evaluated by the compiler. Function (cont.)
  • 25. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 25 Function (cont.)  Statement – A function consists of a sequence of statements that perform the work of the function. – Every statement in C++ ends with a semicolon (;).
  • 26. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 26 Program Development Life Cycle  The process of developing a program is called program development.  The process associated with creating successful application programs is called the Program Development Life Cycle (PDLC). Analysis Design Implementatio n/Coding Testing/ Debugging Maintenance
  • 27. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 27 Analysis  First step in the Program Development Life Cycle (PDLC).  This process is done by reviewing the program specifications.  Other criteria must also be identified, especially the data that will be used as input, the process involved and the output that will be produced.
  • 28. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 28 Design  A programmer needs to develop a series of steps with logical order, which when applied would produce the output of the problem.  A solution is created using a structured programming technique known as algorithm, which consists of pseudocode and flowchart. – A procedure or formula for solving a problem. – A step-by-step problem solving process where the result is attained in a limited amount of time.
  • 29. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 29 Design (cont.)  Some requirements must be satisfied when creating an algorithm: 1. Unambiguousness 2. Generality 3. Correctness 4. Finiteness
  • 30. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 30  Before an algorithm is created, the three types of control structure should be understood first.  A control structure is a pattern to control the flow of a program module. Design (cont.)
  • 31. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 31 Pseudocode  A semiformal, English-like language with a limited vocabulary used to design and describe algorithms.  Every statement in pseudocode involves keywords which define the process and operands.  Each pseudocode statement should be written in a separate line.
  • 32. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 32 Pseudocode (cont.)
  • 33. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 33 Flow Chart  A graphic presentation of the detailed logical sequence of steps needed to solve programming problems.  Uses geometric symbols where different symbols are used to represent different actions such as start/stop, decision, input/output, processing and looping.  Similar to pseudocode, keywords are written in uppercase, while variable and constant names as well as operations for the statements are written in lower case.
  • 34. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 34 Flow Chart (cont.)
  • 35. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 35 Flow Chart (cont.)
  • 36. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 36 Flow Chart (cont.)
  • 37. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 37 Flow Chart (cont.)
  • 38. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 38 Flow Chart (cont.)
  • 39. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 39 Implementation/Coding  The pseudocode and flow chart which have been done in the design step will be converted into a program by using certain programming languages such as BASIC, JAVA, C or C++.  This step solves the problem by enabling the user to start writing the programs.
  • 40. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 40  Coding is the actual process of creating a program in a programming language.  The coded program is referred to as source code. – Must follow certain rules which are called syntax. – Must then be saved as a program which has the extension ‘.cpp’.  To be executed, the program is converted by the computer into object code using a special program or translator such as a compiler or interpreter. Implementation/Coding (cont.)
  • 41. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 41 Testing/Debugging  The step for checking and verifying the correctness of the program.  The process of making sure a program is free of errors or ‘bugs’ is called debugging.  Preliminary debugging begins after the program has been entered into the computer system.
  • 42. All Rights Reserved INTRODUCTION C++ PROGRAMMING © Oxford Fajar Sdn. Bhd. (008974-T), 2015 1– 42 Maintenance  Last step in the Program Development Life Cycle (PDLC).  Essentially, every program, if it is to last a long time, requires ongoing maintenance.  A process of updating software for any changes, corrections, additions, moving to a different computing platform and others so that it continues to be useful.  A costly process.  Can be very useful especially on extending the life of a program.