SlideShare ist ein Scribd-Unternehmen logo
1 von 19
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

Weitere ähnliche Inhalte

Was ist angesagt?

C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP Implementation
Fridz Felisco
 
C# for C++ programmers
C# for C++ programmersC# for C++ programmers
C# for C++ programmers
Mark Whitaker
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.ppt
Tareq Hasan
 

Was ist angesagt? (20)

Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
2. data, operators, io
2. data, operators, io2. data, operators, io
2. data, operators, io
 
C++ Training
C++ TrainingC++ Training
C++ Training
 
OOP in C++
OOP in C++OOP in C++
OOP in C++
 
Object Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World ScenarioObject Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World Scenario
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
 
The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
C# Basics
C# BasicsC# Basics
C# Basics
 
C++ OOP Implementation
C++ OOP ImplementationC++ OOP Implementation
C++ OOP Implementation
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
 
C# for C++ programmers
C# for C++ programmersC# for C++ programmers
C# for C++ programmers
 
(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.ppt
 
basics of c++
basics of c++basics of c++
basics of c++
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
 
Data types in c++
Data types in c++ Data types in c++
Data types in c++
 

Andere mochten auch

#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance
Hadziq Fabroyir
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
Swarup Kumar Boro
 
Chapter 14 management (10 th edition) by robbins and coulter
Chapter 14 management (10 th edition) by robbins and coulterChapter 14 management (10 th edition) by robbins and coulter
Chapter 14 management (10 th edition) by robbins and coulter
Md. Abul Ala
 
Valve types and selection
Valve types and selectionValve types and selection
Valve types and selection
Musa Sabri
 
VALVES AND THEIR TYPES
VALVES AND THEIR TYPESVALVES AND THEIR TYPES
VALVES AND THEIR TYPES
Madhur Mahajan
 

Andere mochten auch (16)

C++ Programming : Learn OOP in C++
C++ Programming : Learn OOP in C++C++ Programming : Learn OOP in C++
C++ Programming : Learn OOP in C++
 
Overview- Skillwise Consulting
Overview- Skillwise Consulting Overview- Skillwise Consulting
Overview- Skillwise Consulting
 
#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++
 
Pipe & its wall thickness calculation
Pipe & its wall thickness calculationPipe & its wall thickness calculation
Pipe & its wall thickness calculation
 
Valve selections
Valve selectionsValve selections
Valve selections
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Valve Selection & Sizing
Valve Selection & SizingValve Selection & Sizing
Valve Selection & Sizing
 
Chapter 14 management (10 th edition) by robbins and coulter
Chapter 14 management (10 th edition) by robbins and coulterChapter 14 management (10 th edition) by robbins and coulter
Chapter 14 management (10 th edition) by robbins and coulter
 
01 General Control Valves Training.
01 General Control Valves Training.01 General Control Valves Training.
01 General Control Valves Training.
 
Valve types and selection
Valve types and selectionValve types and selection
Valve types and selection
 
Control valve ppt
Control valve pptControl valve ppt
Control valve ppt
 
Basic Control Valve Sizing and Selection
Basic Control Valve Sizing and SelectionBasic Control Valve Sizing and Selection
Basic Control Valve Sizing and Selection
 
VALVES AND THEIR TYPES
VALVES AND THEIR TYPESVALVES AND THEIR TYPES
VALVES AND THEIR TYPES
 

Ähnlich wie Oop l2

Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
meharikiros2
 
Labsheet1 stud
Labsheet1 studLabsheet1 stud
Labsheet1 stud
rohassanie
 

Ähnlich wie Oop l2 (20)

Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
C++ basics
C++ basicsC++ basics
C++ basics
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
Object oriented programming 7 first steps in oop using c++
Object oriented programming 7 first steps in oop using  c++Object oriented programming 7 first steps in oop using  c++
Object oriented programming 7 first steps in oop using c++
 
Presentation c++
Presentation c++Presentation c++
Presentation c++
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to it
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
 
Hello world! Intro to C++
Hello world! Intro to C++Hello world! Intro to C++
Hello world! Intro to C++
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
C++ language basic
C++ language basicC++ language basic
C++ language basic
 
Parm
ParmParm
Parm
 
Parm
ParmParm
Parm
 
Chp1(c 2 c++)
Chp1(c 2 c++)Chp1(c 2 c++)
Chp1(c 2 c++)
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).doc
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
 
Labsheet1 stud
Labsheet1 studLabsheet1 stud
Labsheet1 stud
 

Kürzlich hochgeladen

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Kürzlich hochgeladen (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 

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