Introduction To Programming Languages
Introduction To Programming Languages
M A N I L A , P H I L I P P I N E S
Computer Program
A computer program (also a software program, or just
a program) is a sequence of instructions written to perform a
specified task for a computer. A computer requires programs
to function, typically executing the program's instructions in
a central processor. The program has an executable form
that the computer can use directly to execute the instructions.
11/18/2019 2
M A N I L A , P H I L I P P I N E S
Source Code
Source code is text written in a computer programming
language. Such a language is specially designed to
facilitate the work of computer programmers, who specify
the actions to be performed by a computer mostly by
writing source code, which can then be automatically
translated to binary machine code that the computer can
directly read and execute.
11/18/2019 3
M A N I L A , P H I L I P P I N E S
Computer Programming
Computer programming (often shortened to programming
or coding) is the process of designing, writing, testing,
debugging/ troubleshooting, and maintaining the source
code of computer programs. This source code is written in a
programming language. The purpose of programming is to
create a program that exhibits a certain desired behavior.
The process of writing source code often requires expertise
in many different subjects, including knowledge of the
application domain, specialized algorithms and formal logic.
11/18/2019 4
M A N I L A , P H I L I P P I N E S
Introduction to Programming
• Program: self-contained set of instructions used to
operate a computer to produce a specific result
• Also called software
• Programming: the process of writing a program, or
software
11/18/2019
M A N I L A , P H I L I P P I N E S
5 5
Machine Language
• Machine language programs, also called executables,
consist of binary instructions
• Each instruction has two parts:
• Instruction part: the operation to be performed; also called an
opcode
• Address part: memory address of the data to be used
• Each class of computer has its own particular machine
language
• Writing in machine language is tedious!
11/18/2019
M A N I L A , P H I L I P P I N E S
6 6
Assembly Languages
• Assembly Language: programming language with
symbolic names for opcodes, and decimals or labels
for memory addresses
Example:
ADD 1, 2
MUL 2, 3
• Assembly language programs must be translated into
machine instructions, using an assembler
11/18/2019
M A N I L A , P H I L I P P I N E S
7 7
Introduction to Programming: Assembly Language (continued)
11/18/2019
M A N I L A , P H I L I P P I N E S
8 8
Introduction to Programming:
• Low-level languages: languages that use instructions
tied directly to one type of computer
Examples: machine language, assembly language
11/18/2019
M A N I L A , P H I L I P P I N E S
9 9
Introduction to Programming:
(continued)
• Source code: the programs written in a high- or low-
level language
• Source code must be translated to machine
instructions in one of two ways:
• Interpreter: each statement is translated individually and
executed immediately after translation
• Compiler: all statements are translated and stored as an
executable program, or object program; execution occurs
later
11/18/2019
M A N I L A , P H I L I P P I N E S
10 10
Low- and High-Level Languages (continued)
11/18/2019
M A N I L A , P H I L I P P I N E S
11 11
Low- and High-Level Languages (continued)
11/18/2019
M A N I L A , P H I L I P P I N E S
12 12
Procedural and Object Orientations
Figure 1.2
Creating an
executable C++
program.
11/18/2019
M A N I L A , P H I L I P P I N E S
13 13
History of C++
11/18/2019 M A N I L A , P H I L I P P I N E S
15
History of C++ (continued)
11/18/2019 M A N I L A , P H I L I P P I N E S
16
History of C++ (continued)
11/18/2019 M A N I L A , P H I L I P P I N E S
18
History of C++ (continued)
11/18/2019 M A N I L A , P H I L I P P I N E S
19
History of C++ (continued)
11/18/2019 M A N I L A , P H I L I P P I N E S
20
History of C++ (continued)
11/18/2019 M A N I L A , P H I L I P P I N E S
21
History of C++ (continued)
11/18/2019 M A N I L A , P H I L I P P I N E S
22
History of C++ (continued)
During the 80s, the C++ language was being refined until it
became a language with its own personality. All that with very
few losses of compatibility with the code with C, and without
resigning to its most important characteristics. In fact, the ANSI
standard for the C language published in 1989 took good part of
the contributions of C++ to structured programming.
11/18/2019 M A N I L A , P H I L I P P I N E S
24
Advantages of C++
11/18/2019 M A N I L A , P H I L I P P I N E S
25
List of differences between C and C++:
11/18/2019 M A N I L A , P H I L I P P I N E S
26
Difference of C and C++
• In C, main() doesn't provide return 0 automatically.
In C++, you are free to leave off the statement
'return 0;' at the end of main; it will be provided
automatically:
int main()
{ printf( "Hello, World" );
but }in C, you must manually add it:
int main()
{ printf( "Hello, World" );
return 0;
}
11/18/2019 M A N I L A , P H I L I P P I N E S
27
The Development of C++
11/18/2019 M A N I L A , P H I L I P P I N E S
28 28
The Development of C++ (continued)
• Early procedural languages included
• FORTRAN: Formula Translation
• ALGOL: Algorithmic Language
• COBOL: Common Business Oriented Language
• BASIC: Beginners All-purpose Symbolic Instruction Code
• Pascal
• C
11/18/2019
M A N I L A , P H I L I P P I N E S
29 29
The Development of C++ (continued)
• Early object-oriented language:
• C++
11/18/2019
M A N I L A , P H I L I P P I N E S
30 30
Program Development Cycle
1. Analyze: Define the problem
2. Design: Plan the solution to the problem
3. Choose the Interface: Select the objects
4. Code: Translate the algorithm into a programming
language.
5. Debug and Test: Locate and remove any errors in
the program.
6. Complete the Documentation: Organize all the
materials that describe the program.
11/18/2019 M A N I L A , P H I L I P P I N E S
31
Algorithms
11/18/2019
M A N I L A , P H I L I P P I N E S
32 32
Algorithms (continued)
11/18/2019 M A N I L A , P H I L I P P I N E S
33 33
Expressing Algorithms
Algorithms can be expressed in many kinds of notation,
including:
• Natural Languages
• Pseudocode
• Flowcharts
• Programming Languages
11/18/2019 M A N I L A , P H I L I P P I N E S
34
Pseudocode
• A program design technique that uses English words.
• Has no formal syntactical rules.
• Pseudo means false, thus pseudocode means false code. It looks like
(imitates) real code but it is NOT real code.
• Pseudocode cannot be compiled nor executed, and there are no real
formatting or syntax rules.
• Pseudocode should not include keywords in any specific computer
languages.
• The benefit of pseudocode is that it enables the programmer to concentrate
on the algorithms without worrying about all the syntactic details of a
particular programming language.
11/18/2019 M A N I L A , P H I L I P P I N E S
35
How do I write Pseudocode?
• First you may want to make a list of the main tasks that must
be accomplished on a piece of scratch paper.
11/18/2019 M A N I L A , P H I L I P P I N E S
36
• It is not necessary in pseudocode to mention the need to
declare variables. It is wise however to show the initialization
of variables.
11/18/2019 M A N I L A , P H I L I P P I N E S
38
Pseudocode Examples
Original Program Specification:
Pseudocode:
11/18/2019 M A N I L A , P H I L I P P I N E S
39
Original Program Specification:
Pseudocode:
11/18/2019 M A N I L A , P H I L I P P I N E S
40
Original Program Specification:
Write a program that will allow the student to input the grade
on his 5 subjects and will compute for his average grade.
11/18/2019 M A N I L A , P H I L I P P I N E S
41
Pseudocode example : If then Else
If age > 17
Display a message indicating you can vote.
Else
Display a message indicating you can't vote.
Endif
Case of age
0 to 17 Display "You can't vote."
18 to 64 Display "Your in your working years."
65 + Display "You should be retired."
Endcase
11/18/2019 M A N I L A , P H I L I P P I N E S
42
Pseudocode example : While loop
11/18/2019 M A N I L A , P H I L I P P I N E S
43
Pseudocode example : Do While loop
11/18/2019 M A N I L A , P H I L I P P I N E S
44
Pseudocode example : Function with no parameter
passing
11/18/2019 M A N I L A , P H I L I P P I N E S
45
Pseudocode of : Function main calling
the clear monitor function
Function main
Pass In: nothing
Doing some lines of code
Call: clear monitor
Doing some lines of code
Pass Out: value zero to the operating system
Endfunction
11/18/2019 M A N I L A , P H I L I P P I N E S
46
Flowcharts Symbols
11/18/2019 47
M A N I L A , P H I L I P P I N E S
Flowcharts Symbols (continued)
11/18/2019 48
M A N I L A , P H I L I P P I N E S
Flowcharts (continued)
11/18/2019
M A N I L A , P H I L I P P I N E S
49 49
Guidelines for Drawing a Flowchart
• In drawing a proper flowchart, all necessary requirements
should be listed out in logical order.
11/18/2019 50
M A N I L A , P H I L I P P I N E S
• Only one flow line should come out from a process
symbol.
• Only one flow line should enter a decision symbol, but two or
three flow lines, one for each possible answer, should leave the
decision symbol.
11/18/2019 51
M A N I L A , P H I L I P P I N E S
• If the flowchart becomes complex, it is better to use
connector symbols to reduce the number of flow lines.
Avoid the intersection of flow lines if you want to make it
more effective and better way of communication.
11/18/2019 52
M A N I L A , P H I L I P P I N E S
Advantages of using flowcharts
11/18/2019 53
M A N I L A , P H I L I P P I N E S
• Efficient Coding: The flowcharts act as a guide or blueprint during the systems
analysis and program development phase.
11/18/2019 54
M A N I L A , P H I L I P P I N E S
Limitations of using flowcharts
• Complex logic: Sometimes, the program logic is quite
complicated. In that case, flowchart becomes complex and
clumsy.
11/18/2019 55
M A N I L A , P H I L I P P I N E S
Flowcharting Examples
Example 1
11/18/2019 56
M A N I L A , P H I L I P P I N E S
Example 2
Draw a flowchart
to find the largest
of three numbers
A,B, and C.
11/18/2019 57
M A N I L A , P H I L I P P I N E S
Example 3
Draw a flowchart for
computing factorial N (N!)
Where N! = 1 ´ 2 ´ 3 ´ …… N
.
11/18/2019 58
M A N I L A , P H I L I P P I N E S
Problem Solving Process
11/18/2019 M A N I L A , P H I L I P P I N E S
59
Example Problem #1
11/18/2019 M A N I L A , P H I L I P P I N E S
60
Pseudocode
1. Start
2. Read quantity
3. Read price_per_kg
4. price quantity *
price_per_kg
5. Print price
6. End
11/18/2019 M A N I L A , P H I L I P P I N E S
61
Flowchart: Calculate Price of Apples
Start
Input
Quantity
Input
Price_per_kg
Output
Price
End
11/18/2019 M A N I L A , P H I L I P P I N E S
62
Source Code
#include<iostream> Pre-processor
using namespace std;
int main() Main function
{ Start
int price = 0, quantity = 0;
Variable declarations
float price_per_kg = 0;
cout << "Enter quantity of an apple : " ;
cin >> quantity; Input
cout << "Enter price of an apple per kilogram : " ;
cin >> price_per_kg; Input
price = quantity * price_per_kg; computations
cout << "The price of an apple in kilogram is " << price << "\n";
system ("pause");
return 0;
Output
}
Stop
11/18/2019 M A N I L A , P H I L I P P I N E S
63
Example #2
• Entry_time Charge
????
• Exit_time
11/18/2019 M A N I L A , P H I L I P P I N E S
64
Flowchart:
Calculate Car Park Charge
Start
Input Entry_time
Input Exit_time
Output
Charge
End
11/18/2019 M A N I L A , P H I L I P P I N E S
65
C++ Program: Calculate Car Park Charge
#include<iostream>
using namespace std;
int main()
{
int entry_time = 0, exit_time = 0, period = 0;
float charge = 0;
cout << "Enter entry time : " ;
cin >> entry_time;
cout << "Enter exit time : " ;
cin >> exit_time;
period = exit_time – entry_time;
If (period > 1)
charge = (period – 1)* 2;
else
charge = 5;
cout << “The total parking charge is “ << charge << “\n”;
system ("pause");
return 0;
11/18/2019 } M A N I L A , P H I L I P P I N E S
66
End of Module
Credit to FEU Institute of Technology
11/18/2019 M A N I L A , P H I L I P P I N E S
67
ASSIGNMENT 1
List and differentiate C++ from Python and in your research, which
is better?
ASSIGNMENT 2
How Python is applied in a Business Degree?
11/18/2019 M A N I L A , P H I L I P P I N E S
68
ACTIVITY 2
11/18/2019 M A N I L A , P H I L I P P I N E S
69