SlideShare a Scribd company logo
OOP
Lecture-2
Dr. Mohammad Shahidul Islam
Assistant professor
2.1 What is C++
• Its an OOP Language
• Introduced by AT&T bell laboratory in 1980’s
• Still retains the power of C
• Initially it was named as “C with classes”
• C++ is a superset of C
• Some differences will prevent the C to run in
the C++ compiler
DMSI 2
2.1 What is C++
• Important features added over C are classes,
inheritance, function overloading and
operator overloading.
• C++ allows programmers to build large
programs with clarity, extensibility, and ease
of maintenance incorporating the spirit and
efficiency of C
• It facilitates(সহজসাধ্য করে ত ালা) bottom up
approach which was top down in case of C
DMSI 3
Applications of OOP
• OOP language like C++ or JAVA is capable of
handling large programs easily
• Task includes development of editors,
compilers, databases, communication systems
and any complex real time systems
DMSI 4
Applications of OOP
• Since C++ allows us to create hierarchy-related
objects, we can build special object oriented
libraries which can be used later by many
programmers.
• While C++ is able to map the real-world problem
properly, the C part of C++ gives the language the
ability to get close to the machine-level details.
• C++ programs are easily maintainable and
expandable. When a new feature needs to be
implemented, it is vary easy to add to the exiting
structure of an object.
DMSI 5
2.3 A Simple C++ Program
• Printing a string
# include <iostream> // include header file
using namespace std;
Int main()
{
Cout<< “my name is ………..”; //C++ statement
Return 0;
} // end of example
• Program Features
– only one function, main(). //can have more
– Like C the C++ statements terminate with semicolons
DMSI 6
Example (cont.)
• Comments
– C++ introduces a new comment symbol //
– Note that there is no closing symbol
• for*(j=0; j<n; /* loops n times */ J++)
– Can we use double slash?
• Output Operator:
• two ne C++ features, cout and <<.
• The operator << is called the insertion or put to
operator
DMSI 7
Output Operator:
• You may recall that the operator << is the bit-wise left-
shift operator and it can still be used for this purpose.
• This is an example of how one operator can be used for
different purposes, depending on the context.
• This concept is known an operator overloading, an
important aspect of polymorphism.
DMSI 8
The iostream File
• We have used the following #include directive in
the program;
– # include <iostream>
• This directive causes the preprocessor to add the
contents of the iostream file to the program.
• It contains declarations for the identifier cout and
the operator «.
• Some old versions of C++ use a header file called
ioslream.h.
• This is one of the changes introduced by ANSI
C++.
DMSI 9
Return Type of main ( )
• In C++, main() returns an integer type value to the operating
system.
• Therefore, every main() in C + + should end with a return(O)
statement; otherwise a warning or an error might occur.
• Since main() returns an integer type value, return type for main() is
explicitly specified as int. Note that the default return type for all
functions in C++ is int.
• The following main without type and return will run with a warning:
• main()
{
-----
-----
}
DMSI 10
More C+ + Statements
#include<iostream>
using namespace std;
int main()
{
float v1,v2,sum, average;
cout<< "entr the numversn";
cin>> v1;
cin>> v2;
sum=v1+v2;
average=sum/2;
cout<< "sum= "<<sum<<"n";
cout<< "average= "<<average<<"n";
return 0;
}
DMSI 11
• Variables?
• Input Operator?
• Cascading of I/O Operators?
– cout<< "sum= "<<sum<<"n";
– The multiple use of << in one statement is called
cascading
• What is the difference,
cout<< "sum= "<<sum<<“,"
<< "average= "<<average<<"n";
DMSI 12
Class
#include <iostream>
using namespace std;
class person
{
char name[30];
int age;
public:
void getdata(void);
void display(void);
};
void person:: getdata(void)
{
cout<<"enter the namen";
cin>> name;
cout<<"enter the agen";
cin>>age;
}
void person:: display(void)
{
cout<<"Name of the person:
"<<name<<"n";
cout<<"Age of the person:
"<<age<<"n";
}
int main()
{
person p;
p.getdata();
p.display();
return 0;
}
Class (cont.)
• Class person has two two functions called
member function.
• The main program uses person to declare
variables of its type.
• Here P is an object of type person.
Classes in Java:
public class Dog
{
String breed;
int age;
String color;
void barking(){ }
void hungry(){ }
void sleeping(){ }
}
Structure of C++ program
• The previous OOP code shows that a typical
code can have four sections….
– Include files
– Class declaration
– Member functions definition
– Main function program
Client-Server model
• The class definition includinf the member
functions are known as server and
• The main function is know as client
Creating source file
• In C++ we can use text editor to create it
• In UNIX we can use vi or ed editor
• In dos we can use edlin
• The created file should have appropritae
extension to be recognised.
Compiling and Linking
• The process of compiling and linking again
depends upon the operating system.
• Each system has its own command to run.
DMSI 19

More Related Content

What's hot (20)

PPTX
Presentation on C++ Programming Language
satvirsandhu9
 
PPT
2. data, operators, io
Srichandan Sobhanayak
 
PDF
C++ Training
SubhendraBasu5
 
PPT
OOP in C++
ppd1961
 
PDF
Object Oriented Programming With Real-World Scenario
Durgesh Singh
 
PPT
C++ Programming Course
Dennis Chang
 
PPT
C by balaguruswami - e.balagurusamy
Srichandan Sobhanayak
 
PPT
The smartpath information systems c plus plus
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
PPS
basics of C and c++ by eteaching
eteaching
 
PPTX
07. Virtual Functions
Haresh Jaiswal
 
PPT
C# Basics
Sunil OS
 
PPT
C++ OOP Implementation
Fridz Felisco
 
PPT
Introduction to C++
Bharat Kalia
 
PPTX
C# for C++ programmers
Mark Whitaker
 
ODP
(2) c sharp introduction_basics_part_i
Nico Ludwig
 
PPT
01 c++ Intro.ppt
Tareq Hasan
 
PPTX
basics of c++
gourav kottawar
 
PPTX
Introduction Of C++
Sangharsh agarwal
 
PPT
C++ polymorphism
Ganesh Hogade
 
PDF
Data types in c++
RushikeshGaikwad28
 
Presentation on C++ Programming Language
satvirsandhu9
 
2. data, operators, io
Srichandan Sobhanayak
 
C++ Training
SubhendraBasu5
 
OOP in C++
ppd1961
 
Object Oriented Programming With Real-World Scenario
Durgesh Singh
 
C++ Programming Course
Dennis Chang
 
C by balaguruswami - e.balagurusamy
Srichandan Sobhanayak
 
The smartpath information systems c plus plus
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
basics of C and c++ by eteaching
eteaching
 
07. Virtual Functions
Haresh Jaiswal
 
C# Basics
Sunil OS
 
C++ OOP Implementation
Fridz Felisco
 
Introduction to C++
Bharat Kalia
 
C# for C++ programmers
Mark Whitaker
 
(2) c sharp introduction_basics_part_i
Nico Ludwig
 
01 c++ Intro.ppt
Tareq Hasan
 
basics of c++
gourav kottawar
 
Introduction Of C++
Sangharsh agarwal
 
C++ polymorphism
Ganesh Hogade
 
Data types in c++
RushikeshGaikwad28
 

Viewers also liked (16)

PDF
C++ Programming : Learn OOP in C++
richards9696
 
PPTX
Overview- Skillwise Consulting
Skillwise Group
 
PPTX
#OOP_D_ITS - 6th - C++ Oop Inheritance
Hadziq Fabroyir
 
PPTX
Control structures in c++
Nitin Jawla
 
PPTX
Pipe & its wall thickness calculation
sandeepkrish2712
 
PDF
Valve selections
Sandip Sonawane
 
PDF
Implementation of oop concept in c++
Swarup Kumar Boro
 
PPTX
Learn c++ Programming Language
Steve Johnson
 
PPTX
Object Oriented Programming Using C++
Muhammad Waqas
 
PPT
Valve Selection & Sizing
Ranjeet Kumar
 
PPT
Chapter 14 management (10 th edition) by robbins and coulter
Md. Abul Ala
 
PPSX
01 General Control Valves Training.
SuryamshVikrama
 
PDF
Valve types and selection
Musa Sabri
 
PPTX
Control valve ppt
Tarit Mahata
 
PPT
Basic Control Valve Sizing and Selection
ISA Boston Section
 
PPT
VALVES AND THEIR TYPES
Madhur Mahajan
 
C++ Programming : Learn OOP in C++
richards9696
 
Overview- Skillwise Consulting
Skillwise Group
 
#OOP_D_ITS - 6th - C++ Oop Inheritance
Hadziq Fabroyir
 
Control structures in c++
Nitin Jawla
 
Pipe & its wall thickness calculation
sandeepkrish2712
 
Valve selections
Sandip Sonawane
 
Implementation of oop concept in c++
Swarup Kumar Boro
 
Learn c++ Programming Language
Steve Johnson
 
Object Oriented Programming Using C++
Muhammad Waqas
 
Valve Selection & Sizing
Ranjeet Kumar
 
Chapter 14 management (10 th edition) by robbins and coulter
Md. Abul Ala
 
01 General Control Valves Training.
SuryamshVikrama
 
Valve types and selection
Musa Sabri
 
Control valve ppt
Tarit Mahata
 
Basic Control Valve Sizing and Selection
ISA Boston Section
 
VALVES AND THEIR TYPES
Madhur Mahajan
 
Ad

Similar to Oop l2 (20)

PDF
Prog1-L1.pdf
valerie5142000
 
PPTX
C++ basics
AllsoftSolutions
 
PPT
chapter_2_-_basic_c_elements (1)_c++_c++_Wadee3.ppt
yyu8u
 
PDF
C++ L01-Variables
Mohammad Shaker
 
PPTX
Object oriented programming 7 first steps in oop using c++
Vaibhav Khanna
 
PPTX
Presentation c++
JosephAlex21
 
PPTX
Intro in understanding to C programming .pptx
abadinasargie
 
PPTX
Intro in understanding to C programming .pptx
abadinasargie
 
PPTX
Introduction to cpp language and all the required information relating to it
PushkarNiroula1
 
PDF
Software Engineering
Tharindu Weerasinghe
 
PPTX
Introduction to c++ programming language
Ahmad177077
 
PPTX
C++ Constructs.pptx
LakshyaChauhan21
 
PPTX
Hello world! Intro to C++
DSCIGDTUW
 
PPTX
1. Introduction to C++ and brief history
Ahmad177077
 
PPT
Fp201 unit2 1
rohassanie
 
PPTX
C++ language basic
Waqar Younis
 
PPT
Parm
parmsidhu
 
PPT
Parm
parmsidhu
 
PPTX
Advantage and Disadvantages of C++ programming.pptx
phalapagol
 
Prog1-L1.pdf
valerie5142000
 
C++ basics
AllsoftSolutions
 
chapter_2_-_basic_c_elements (1)_c++_c++_Wadee3.ppt
yyu8u
 
C++ L01-Variables
Mohammad Shaker
 
Object oriented programming 7 first steps in oop using c++
Vaibhav Khanna
 
Presentation c++
JosephAlex21
 
Intro in understanding to C programming .pptx
abadinasargie
 
Intro in understanding to C programming .pptx
abadinasargie
 
Introduction to cpp language and all the required information relating to it
PushkarNiroula1
 
Software Engineering
Tharindu Weerasinghe
 
Introduction to c++ programming language
Ahmad177077
 
C++ Constructs.pptx
LakshyaChauhan21
 
Hello world! Intro to C++
DSCIGDTUW
 
1. Introduction to C++ and brief history
Ahmad177077
 
Fp201 unit2 1
rohassanie
 
C++ language basic
Waqar Younis
 
Parm
parmsidhu
 
Parm
parmsidhu
 
Advantage and Disadvantages of C++ programming.pptx
phalapagol
 
Ad

Recently uploaded (20)

PPTX
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PDF
John Keats introduction and list of his important works
vatsalacpr
 
PPTX
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
PPTX
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
PPTX
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
PPT
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PPTX
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
PPTX
LDP-2 UNIT 4 Presentation for practical.pptx
abhaypanchal2525
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
John Keats introduction and list of his important works
vatsalacpr
 
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
Virus sequence retrieval from NCBI database
yamunaK13
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
LDP-2 UNIT 4 Presentation for practical.pptx
abhaypanchal2525
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 

Oop l2

  • 1. OOP Lecture-2 Dr. Mohammad Shahidul Islam Assistant professor
  • 2. 2.1 What is C++ • Its an OOP Language • Introduced by AT&T bell laboratory in 1980’s • Still retains the power of C • Initially it was named as “C with classes” • C++ is a superset of C • Some differences will prevent the C to run in the C++ compiler DMSI 2
  • 3. 2.1 What is C++ • Important features added over C are classes, inheritance, function overloading and operator overloading. • C++ allows programmers to build large programs with clarity, extensibility, and ease of maintenance incorporating the spirit and efficiency of C • It facilitates(সহজসাধ্য করে ত ালা) bottom up approach which was top down in case of C DMSI 3
  • 4. Applications of OOP • OOP language like C++ or JAVA is capable of handling large programs easily • Task includes development of editors, compilers, databases, communication systems and any complex real time systems DMSI 4
  • 5. Applications of OOP • Since C++ allows us to create hierarchy-related objects, we can build special object oriented libraries which can be used later by many programmers. • While C++ is able to map the real-world problem properly, the C part of C++ gives the language the ability to get close to the machine-level details. • C++ programs are easily maintainable and expandable. When a new feature needs to be implemented, it is vary easy to add to the exiting structure of an object. DMSI 5
  • 6. 2.3 A Simple C++ Program • Printing a string # include <iostream> // include header file using namespace std; Int main() { Cout<< “my name is ………..”; //C++ statement Return 0; } // end of example • Program Features – only one function, main(). //can have more – Like C the C++ statements terminate with semicolons DMSI 6
  • 7. Example (cont.) • Comments – C++ introduces a new comment symbol // – Note that there is no closing symbol • for*(j=0; j<n; /* loops n times */ J++) – Can we use double slash? • Output Operator: • two ne C++ features, cout and <<. • The operator << is called the insertion or put to operator DMSI 7
  • 8. Output Operator: • You may recall that the operator << is the bit-wise left- shift operator and it can still be used for this purpose. • This is an example of how one operator can be used for different purposes, depending on the context. • This concept is known an operator overloading, an important aspect of polymorphism. DMSI 8
  • 9. The iostream File • We have used the following #include directive in the program; – # include <iostream> • This directive causes the preprocessor to add the contents of the iostream file to the program. • It contains declarations for the identifier cout and the operator «. • Some old versions of C++ use a header file called ioslream.h. • This is one of the changes introduced by ANSI C++. DMSI 9
  • 10. Return Type of main ( ) • In C++, main() returns an integer type value to the operating system. • Therefore, every main() in C + + should end with a return(O) statement; otherwise a warning or an error might occur. • Since main() returns an integer type value, return type for main() is explicitly specified as int. Note that the default return type for all functions in C++ is int. • The following main without type and return will run with a warning: • main() { ----- ----- } DMSI 10
  • 11. More C+ + Statements #include<iostream> using namespace std; int main() { float v1,v2,sum, average; cout<< "entr the numversn"; cin>> v1; cin>> v2; sum=v1+v2; average=sum/2; cout<< "sum= "<<sum<<"n"; cout<< "average= "<<average<<"n"; return 0; } DMSI 11
  • 12. • Variables? • Input Operator? • Cascading of I/O Operators? – cout<< "sum= "<<sum<<"n"; – The multiple use of << in one statement is called cascading • What is the difference, cout<< "sum= "<<sum<<“," << "average= "<<average<<"n"; DMSI 12
  • 13. Class #include <iostream> using namespace std; class person { char name[30]; int age; public: void getdata(void); void display(void); }; void person:: getdata(void) { cout<<"enter the namen"; cin>> name; cout<<"enter the agen"; cin>>age; } void person:: display(void) { cout<<"Name of the person: "<<name<<"n"; cout<<"Age of the person: "<<age<<"n"; } int main() { person p; p.getdata(); p.display(); return 0; }
  • 14. Class (cont.) • Class person has two two functions called member function. • The main program uses person to declare variables of its type. • Here P is an object of type person.
  • 15. Classes in Java: public class Dog { String breed; int age; String color; void barking(){ } void hungry(){ } void sleeping(){ } }
  • 16. Structure of C++ program • The previous OOP code shows that a typical code can have four sections…. – Include files – Class declaration – Member functions definition – Main function program
  • 17. Client-Server model • The class definition includinf the member functions are known as server and • The main function is know as client
  • 18. Creating source file • In C++ we can use text editor to create it • In UNIX we can use vi or ed editor • In dos we can use edlin • The created file should have appropritae extension to be recognised.
  • 19. Compiling and Linking • The process of compiling and linking again depends upon the operating system. • Each system has its own command to run. DMSI 19