unit 1 - object oriented programming / c++
TRANSCRIPT
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
1/25
Introduction To C++ Programming Language QF 002/1/1
UNIT 1
General Objective : To understand and recognize the fundamental
concept of C and C++ Programming.
Specific Objectives : At the end of the unit you should be able to:-
Describe the basic concept of the C and C++ programming
Identify the differences between C and C++ programming
Explain the evolution of C++ programming
Explain the structure of C++ programming
OBJECTIVES
INTRODUCTION TO
C++ PROGRAMMING
LANGUAGE
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
2/25
Introduction To C++ Programming Language QF 002/1/2
1.0 Introduction
INPUT
A program is a collection of instructions that
tell the computer what to do . A program iswritten in a programming language and is
converted into the computers machine language by software called assemblers, compilers andinterpreters.
noteMachine language - the native language of the computer
Sir.. What is a program?
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
3/25
Introduction To C++ Programming Language QF 002/1/3
1.1 Introduction To C Programming
The C language was first developed in 1972 by Danny Ritchie at AT &
T Bell Labs. C is high level programming language and the most popular
general purpose programming language.
C is written as a series of functions that call each other for processing.
Even the body of the program is a function named main. The function is
very flexible, allowing programmers to choose from the standard library that
comes with the compiler to use third party functions from other C suppliers or
to develop their own.
High level programminglanguages are closer to our human language as
in figure 1.1 below.
Example: Progamming C
printf (C Language);
printf ( High-Level);
printf ( Programming );
10001110010001000
10000010000111000
11100100111001111
C language is high
level programming.
Example: English
The Machine Language
The High-Level Programming
The Human Language
Example: Binary code
Figure 1.1: An Example of the Language Spectrum
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
4/25
Introduction To C++ Programming Language QF 002/1/4
The Advantages of the High-levelprogramming languages are:
Here is a simple C program example. Lets have a look.
The Output of the program is shown below.
Figure 1.3: Output from the sample of C Programming
/* Welcome To Simple C Programming */
#include
main()
{
printf ( I am the best, I am the best,
I am the best\n);
printf ( I never give
up,never,never,never\n);
printf ( I am a successful person);
return 0;
}
Figure 1.2: A Example of Simple C Programming
The program is easy to read
Readability.
The program is easy to maintain
Maintainability The program is easy to port around
on different computer platforms
Portability.
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
5/25
Introduction To C++ Programming Language QF 002/1/5
1.2 Introduction To C++ Programming
An object-oriented version of C created by B jarne Stroudtrup. C++
has become popular because it combines traditional C Programming with
OOPcapability. Most C++ compilers doesn't care what extension you give to
your source code, but if you don't specify otherwise, many will use .CPP by
default.
Figure 1.4 shows a simple C++ Program. Lets have a look at the first
C++ program.
The Output of the program is shown below.
// Welcome To Simple C++ Programming
#include
main()
{
cout
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
6/25
Introduction To C++ Programming Language QF 002/1/6
Test your comprehension before continuing the next input.
Check your answers on the next page.
1.1 Explain what is C programming?
1.2 Write simple sentences using C programming to display the output
as given below:-
i.
ii.
iii.
Activity 1a
Y Y Y
/ \
/ \/ \
G O O D
I U I
\ MM /
\ /
\ /
\ /
\ /
PPPPPPPPPPPPP
PPPPPPPPPPPPPPPPPP PPPP
PPPP PPPP
PPPP PPPP
PPPPPPPPPPPPPP
PPPPPPPPPPPPP
PPPP
PPPPPPPP
PPPPPPPP
HH HH
HH HH
HHHHHH
HH HH
HH HH
A
AAA
AA AA
AAAAAA
AA AA
III
III
III
III
III
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
7/25
Introduction To C++ Programming Language QF 002/1/7
1.3 Write simple sentences using C++ programming to display the
output as given below:-
i.
ii.
iii.
Y Y Y/ \
/ \
/ \
G O O D
I U I
\ MM /
\ /\ /
\ /\ /
PPPPPPPPPPPPP
PPPPPPPPPPPPPP
PPPP PPPP
PPPP PPPP
PPPP PPPP
PPPPPPPPPPPPPP
PPPPPPPPPPPPP
PPPP
PPPP
PPPPPPPP
PPPP
HH HH
HH HH
HHHHHH
HH HH
HH HH
A
AAA
AA AA
AAAAAA
AA AA
III
III
III
III
III
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
8/25
Introduction To C++ Programming Language QF 002/1/8
Make sure you have tried to answer all the questions given.you can check your
answers with the answers below.
1.1 C is the most popular general purpose and a High-Level
programming language. C language is closer to our human language.
1.2
i.
#include
main ()
{
printf ( \n);
printf ( \n);
printf ( \n);
printf ( \n);
printf ( \n);
printf ( \n);
printf ( \n);
printf ( \n); printf ( \n);
printf ( \n);
printf ( \n);return 0;
}
Feedback 1a
Y Y Y
/ \
/ \/ \
G O O DI U I
\ MM /
\ /\ /\ /
\ /
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
9/25
Introduction To C++ Programming Language QF 002/1/9
ii.
#include
main ()
{
printf ( \n); printf ( \n);
printf ( \n); printf ( \n);
printf ( \n); printf ( \n);
printf ( \n); printf ( \n);
printf ( \n);
printf ( \n);
printf ( \n);
printf ( \n);
return 0;}
iii.
#include
main ()
{
printf ( \n);
printf ( \n);
printf ( \n);
printf ( \n); printf ( \n);
return 0;}
PPPPPPPPPPPPPPPPPPPPPPPPPPP
PPPP PPPPPPPP PPPP
PPPP PPPPPPPPPPPPPPPPPP
PPPPPPPPPPPPPPPPP
PPPP
PPPP
PPPP
PPPP
HH HH
HH HH
HHHHHH
HH HHHH HH
A
AAA
AA AA
AAAAAAAA AA
III
III
III
III
III
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
10/25
Introduction To C++ Programming Language QF 002/1/10
1.3
i.
#include
main ()
{
cout
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
11/25
Introduction To C++ Programming Language QF 002/1/11
ii.
#include
main ()
{cout
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
12/25
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
13/25
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
14/25
Introduction To C++ Programming Language QF 002/1/14
1.5 Differences Between Structured Programming And Object
Oriented Programming
1.5.1 Structured Program
The structured program is viewed as a series of tasks to be done ,
such as reading data, processing data and generating report or output.
The main program fragmented into smaller functions which are then
arranged in a hierarchical structure.
Main Program
Function_a1 Function_a2
Function_b1
Function_c1 Function_b1
Figure 1.6: Typical structure of a Structured Program
noteHierarchical structure is one to many relationship; each item having
one or more items below it
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
15/25
Introduction To C++ Programming Language QF 002/1/15
i) The main characteristics of structured program
1.5.2 Object Oriented Program (OOP)
Object oriented Program approach and treats data is a critical
element in the development of a system. It does not allow data to move
freely through the system. Instead, it binds the data to the functions that
are needed to manipulate them. This is to protect the data from
accidental modifications by ex
ternal functions to an object.I
n Object-oriented Programming (OOP), problems are decomposed into a
number of entities called objects. All the data are to build function
around these objects.
It decomposes a large program into smaller functions.
It employs top-down approach
Most of the functions share global data.
The functions pass the data around the system openly.
Its emphasizes on algorithms
The functionstransform the data from one form to another.
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
16/25
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
17/25
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
18/25
Introduction To C++ Programming Language QF 002/1/18
ii) Basic OOP concepts
Object
Class
Polymorphis
Inheritance
Message
Encapsulation
Abstraction
A class is a group of objects that have
similar properties (data andbehaviors).
An object is an instance of a class. After user
created the objects, user can insert, modify or deletethe ob ects
Communicating between objects,
similar to a function call in traditionalprogramming.
Abstraction is oneof the basicprinciples of object-
oriented designwhich allows for
creating user-defined data types
known as objects.
The ability of one
class of objects toinherit propertiesfrom a higher class.
The ability of a generalized request
(message) to produce different resultsbased on the object that it is sent to.
Making the data and processingwithin the object private, which
allow the internal implementation ofthe object to be modified without
requiring any change to theapplication that uses it.
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
19/25
Introduction To C++ Programming Language QF 002/1/19
Test your comprehension before continuing the next input.
Check your answers on the next page.
1.4 List the differences between C and C++ in the blanks provided below.
Items C C++
Header file
Input function
Output Function
Comment
1.5 Give the main characteristics of structured program.
Activity 1b
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
20/25
Introduction To C++ Programming Language QF 002/1/20
Make sure you have tried to answer all the questions given.You can check
your answers with the answers below.
1.4
Items C C++
Header file #include #include
Input function scanf() cin>>
Output
Function
printf() Cout
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
21/25
Introduction To C++ Programming Language QF 002/1/21
A program is a collection of instructions that tell the computer
what to do.
C and C++ programming are the high level programming language
that closer to human language.
The Advantages of the High-levelprogramming languages are
readability, maintainability and portability.
OOP it is an evolutionary form of modular programming which
has more formal rules that allow pieces of software to be reused
and interchanged between programs
The difference between C and C++ are as in shown below:
Items C C++
Header file #include #include
Input function scanf() cin>>
Output Function printf() Cout
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
22/25
Introduction To C++ Programming Language QF 002/1/22
You are approaching success, please answer the questions below. If you have
any problems, please discuss it with your lecturer. Wish you good luck and all
the best.
Question 1 1
a. Write simple sentences using C programming to display the output as
given below:-
i. A program is a collection of instructions
ii. An object-oriented version of C created by Bjarne Stroudtrup
iii. Pokok Apakah Yang Berani?
iv. Apa Yang Anda Jumpa Di Tengah Malam?
b. Write simple sentences using C++ programming to display the output
as given below:-
i. A program is a collection of instructions
ii. An object-oriented version of C created by Bjarne Stroudtrup
iii. Pokok Apakah Yang Berani?
iv. Apa Yang Anda Jumpa Di Tengah Malam?
Question 1 2
a. Give the main characteristics of object oriented program.
b. List the differences between structured programming and object
oriented programming.
Self-Assessment
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
23/25
Introduction To C++ Programming Language QF 002/1/23
Make sure you have tried to answer all the questions given. You can check
your answers with the answers below.
Answers 1 1
a.
i.A program is a collection of instructions
ii. Anobject-oriented version of C created by Bjarne Stroud trup
iii. Pokok Apakah Yang Berani?
iv. Apa Yang Anda Jumpa Di Tengah Malam?
Feedback On Self-Assessment
#include
main()
{printf ( Aprogram is a collection of instructions \n);
return 0;}
#include
main()
{printf ( Anobject-oriented version of C created by Bjarne
Stroudtrup \n);
return 0;}
#include
main()
{printf ( sebut Pokok Apakah Yang Berani?? \n);
return 0;}
#include
main()
{printf ( Apa YangAnda Jumpa Di Tengah Malam? \n);
return 0;}
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
24/25
Introduction To C++ Programming Language QF 002/1/24
b.
i. A program is a collection of instructions
ii. An object-oriented version of C created by Bjarne Stroudtrup
iii. Pokok Apakah Yang Berani?
iv. Apa Yang Anda Jumpa Di Tengah Malam?
#include main()
{cout
-
8/6/2019 Unit 1 - Object Oriented Programming / C++
25/25
Introduction To C++ Programming Language QF 002/1/25
Answers 1 2
a.
i. Emphasis is on data rather than functions.
ii. A program consists of a set of objectsiii. Each object has its own data and functions.
iv. An objects data is hidden from external functions.
v. Functions that operate on objects are tied to each data structure.
vi. Objects communicate with one another through functions.
vii. New data and functions can be added easily whenever necessary.
viii. Follows bottom-up approach
b. List the differences between structured programming and object
oriented programming.
Structured programming Object Oriented Programming
Top-down approach Bottom-up approach
Functions share global data. Consist of a set of objects
Emphasis is on functions Emphasis is on data
Emphasis is on algorithms Emphasis is on objects
CONGRATULATIONSMay success be with you
always..