Computer Programming: P.B.Shehani Ariyathilake - RSGIS - Faculty of Geomatics - 0765251192 - Shehani@geo - Sab.ac - LK
Computer Programming: P.B.Shehani Ariyathilake - RSGIS - Faculty of Geomatics - 0765251192 - Shehani@geo - Sab.ac - LK
FC12323
Lecture 01
2
Scheme of Evaluation
• Continuous Assessments - 50%
• Mid Term Exam(MCQ) - 15%
• Quiz (In class) - 5%
• Practical Exam - 30%
• Final Examination(Most probably Online) - 50%
3
Recommended Reading
• Deitel & Deitel’s (2016), C++ How to Program, 9th Edition
•
4
What is a program?
• Collection of instructions that describes a task or set of tasks to be
carried out by a computer.
5
What is a program and programming Language?
Programming Language
C++
6
Programming Language
• Arti icial human created language, which translates instructions from a
readable format to a computer readable format.
• Each language has its own special set of keywords and syntax, which
makes each programming language unique.
7
f
f
Introduction to C++
• C++, an extension of C, was developed by Bjarne Stroustrup in 1979 at Bell
Laboratories. Originally called “C with Classes”, it was renamed to C++ in
the early 1983.
• As for C there is an ANSI/ISO standard ( inal draft 1998) for the C++
programming language. This will ensure that the C++ code is portable
between computers.
8
f
Introduction to C++
• Each component becomes a self-contained object that contains its own
instructions and data that relate to that object. In this way, complexity is
reduced and the programmer can manage larger program.
• Standard C++ is the one that is currently accepted by all major compilers
• Intermediate language
9
Introduction to C++
10
C Vs C++
// C Program // C++ Program
} }
12
Machine Language
• Any computer can directly understand only its own machine language
(also called machine code), de ined by its hardware architecture.
13
f
Assembly Language
• Programming in machine language was simply too slow and tedious for most
programmers. Instead, they began using English-like abbreviations to represent
elementary operations.
14
High Level Language
• To speed up the programming process further, high-level languages were
developed in which single statements could be written to accomplish such tasks.
• High-level languages, such as C++, Java, C# and Visual Basic, allow us to write
instructions that look more like everyday English and contain commonly used
mathematical expressions.
15
High Level Language
• The process of compiling a large high-level language program into
machine language can take a considerable amount of computer time.
16
High Level Language(Cont…)
17
Group Activity
18
ff
ff
Procedure oriented programming(POP) language
• Problem is viewed as sequence of things to be done such as reading ,
calculation and printing.
19
Procedure oriented programming(POP) language(Cont…)
20
Procedure oriented programming(POP) language(Cont…)
21
Object oriented programming (OOP) Language
• Object Oriented Programming is a method of implementation in which,
programs are organized as a collection of objects which cooperate to
solve a problem.
22
Object Oriented Programming (OOP) Language
• Complex system is developed using smaller sub systems.
• Sub systems are independent units containing their own data and functions
• Can reuse these independent units to solve many di erent problems.
• Object
• Class
• Inheritance
• Polymorphism
• Abstraction
• Encapsulation
23
ff
Object
Oxford Dictionary
24
What are real world Objects?
25
Objects in OOP
• An Object is a software entity that models something in the real world.
• A combination of data and program that represent some real word entity.
26
Objects in OOP
• It has two main properties:
!State: the object encapsulates information about itself attributes or
ields.
!Behaviour: the object can do some things on behalf of other objects
metmethods
27
f
Objects in OOP
28
Objects in OOP
Cannot be change - Attributes or type=“Ferrari”;
What do you have? color=“Red”;
nouns
weight=500;
Break break()
Action or verbs
What do you do? Accelerate accelerate()
Drive drive()
29
Objects in OOP
Cannot be change - Attributes or type=“Ferrari”;
What do you have? color=“Red”;
nouns
weight=500;
Break break()
What do you do? Accelerate accelerate()
Action or verbs Drive drive()
31
Classes
We can classify objects into concepts. To do this we focus on the essential
properties of an Object. Classes are Concepts
32
Classes in OOP
Class car
34
Inheritance
• A new class of objects can be created quickly and conveniently by
inheritance the new class absorbs the characteristics of an existing class,
possibly customizing them and adding unique characteristics of its own.
35
f
Encapsulation
• Classes encapsulate (i.e., wrap) attributes and member functions into objects—an
object’s attributes and member functions are intimately related.
• Data is not accessible to the outside world and only those functions which are
declared in the class, can access it.
• Objects may communicate with one another, but they’re normally not allowed to
know how other objects are implemented implementation details are hidden
within the objects themselves. This information hiding, is crucial to good software
engineering.
36
Polymorphism
• Polymorphism in OOP is the ability to treat an object of any subclass of a
base class as if it were an object of the base class.
• A base class has, therefore, many forms: the base class itself, and any of
its subclasses.
37
Object oriented programming (OOP) Language(Cont…)
38
Object oriented programming (OOP) Language(Cont…)
Advantages of the Object Oriented programming
• Through inheritance we can eliminate redundant code and extend the use of existing classes.
• We can build programs from the standard working modules that communicate with one another,
rather than having to start writing the code from scratch. This leads to saving of development
time and higher productivity.
• This principle of data hiding helps the programmer to build secure programs that can’t be
invaded by code in other parts of the program.
• It is possible to have multiple instances of an object to co-exist with out any interference.
• It is easy to partition the work in a project based on objects.
• Object-oriented systems can be easily upgraded from small to large systems.
• Message passing techniques for communication between objects makes the interface
description with external systems much simpler.
• Software complexity can be easily managed.
39
What makes C++ unique?
• Object oriented programming
• Simple
• High level programming language
• Case sensitive
• Compiler based
• Existence of libraries
• Reusability of codes
• Portability
40
C++ Applications
• Google : Some of the Google applications are also written in C++, including
Google ile system and Google Chrome
41
f
C++ Applications(Cont…)
• Mozilla : Internet browser Firefox and email client Thunderbird are
written in C++ programming language (open source projects)
42
C++ Applications(Cont…)
• Apple–OSX : Few parts of apple OS X are written in C++ programming
language. Few application for iPod are written in C++
• Microsoft : Windows 95, 98, Me, 200 and XP are also written in C++.
Also Microsoft O ice, Internet Explorer and Visual Studio are written in
Visual C++.
43
ff
GIS Applications using C++
44
C++ deployment environment
• C++ systems generally consist of three parts:
• The language
45
How C++ works
• C++ programs typically go through six phases
• Phase 1: Editing a Program
• Phase 2: Preprocessing a C++ Program
• Phase 3: Compiling a C++ Program
• Phase 4: Linking
• Phase 5: Loading
• Phase 6: Execution
46
How C++ works
• Phase 1: Editing a Program
47
How C++ works
• Phase 2: Preprocessing a C++ Program
48
How C++ works
• Phase 3: Compiling a C++ Program
49
How C++ works
• Phase 4: Linking
50
How C++ works
• Phase 5: Loading
51
How C++ works
• Phase 6: Execution
52
C++ compilers
• Computer software that translates (compiles) source code written in
a high-level language (e.g., C++) into a set of machine-
language instructions that can be understood by a digital
computer’s CPU.
53
C++ compilers
54
Console programs
• Console programs are programs that use text to communicate with the user and the environment,
such as printing text to the screen or reading input from a keyboard.
• A computer terminal where a user may input commands and view output such as the results of
inputted commands or status messages from the computer.
• Console programs are easy to interact with, and generally have a predictable behavior that is
identical across all platforms. They are also simple to implement and thus are very useful to learn the
basics of a programming language.
• The easiest way for beginners to compile C++ programs is by using an Integrated Development
Environment (IDE). An IDE generally integrates several development tools, including a text editor and
tools to compile programs directly from it.
55
Console programs
• Here you have instructions on how to compile and run console programs
using di erent free Integrated Development Interfaces (IDEs)
56
ff
f
Algorithms
• De inition: A step by step process to solve a particular problem
57
f
Symbols of low chart
Start or stop
Input or output
Process
Decision or condition
Flow
58
f
Problem solving
• In a programming environment the problem solving process requires the
following steps.
1. Analyse the problem, outline the problem and its solution
requirement and design algorithm to solve the problem.
2. Implement the algorithm in a programming language such as C++
and verify that the algorithm works.
3. Maintain the program by using and modifying it if the problem
domain changes.
59
Exercise
• Find the sum of two numbers by using a low chart and pseudo code.
60
f
Exercise Start
Pseudo code
Read 2 num x, y
Input x, y
Find sum S as x+y
Print S
S = x+ y
Print S
End
61
Exercise
• Find the average of three numbers by using a low chart and pseudo
code.
62
f