SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
Programming Language Concepts 
Lecture 18 
Prepared by 
Manuel E. Bermúdez, Ph.D. 
Associate Professor 
University of Florida 
Object-Oriented Programming Part 1
Object Oriented Programming 
•Over time, data abstraction has become essential as programs became complicated. 
•Benefits: 
1. Reduce conceptual load (minimum detail). 
2. Fault containment. 
3. Independent program components. 
(difficult in practice). 
•Code reuse possible by extending and refining abstractions.
Object Oriented Programming 
•A methodology of programming 
•Four (Five ?) major principles: 
1.Data Abstraction. 
2.Encapsulation. 
3.Information Hiding. 
4.Polymorphism (dynamic binding). 
5.Inheritance. (particular case of polymorphism ?) 
Will describe these using C++, because ...
The C++ language 
•An object-oriented, general-purpose programming language, derived from C (C++ = C plus classes). 
•C++ adds the following to C: 
1.Inlining and overloading of functions. 
2.Default argument values. 
3.Argument pass-by-reference. 
4.Free store operators new and delete, instead of malloc() and free(). 
5.Support for object-oriented programming, through classes, information hiding, public interfaces, operator overloading, inheritance, and templates.
Design Objectives in C++ 
•Compatibility. Existing code in C can be used. Even existing, pre-compiled libraries can be linked with new C++ code. 
•Efficiency. No additional cost for using C++. Overheadof function calls is eliminated where possible. 
•Strict type checking. Aids debugging, allows generation of efficient code. 
•C++ designed by Bjarne Stroustrup of Bell Labs (now at TAMU). 
•Standardization: ANSI, ISO.
Non Object-Oriented Extensions to C 
•Major improvements over C. 
1.Stream I/O. 
2.Strong typing. 
3.Parameter passing by reference. 
4.Default argument values. 
5.Inlining. 
We’ve discussed some of these already.
Stream I/O in C++ 
•Input and output in C++ is handled by streams. 
•The directive #include <iostream.h> declares 2 streams: cin and cout. 
• cin is associated with standard input. Extraction: operator>>. 
• cout is associated with standard output. Insertion: operator<<. 
•In C++, input is line buffered, i.e. the user must press <RTN> before any characters are processed.
Example of Stream I/O in C++ 
A function that returns the sum of 
the numbers in the file Number.in 
int fileSum(); 
{ 
ifstream infile("Number.in"); 
int sum = 0; 
int value; 
//read until non-integer or <eof> 
while(infile >> value) 
sum = sum + value; 
return sum; 
}
Example of Stream I/O in C++ 
Example 2: A function to copy myfile into copy.myfile 
void copyfile() 
{ 
ifstream source("myfile"); 
ofstream destin("copy.myfile"); 
char ch; 
while (source.get(ch)) 
destin<<ch; 
}
Line-by-line textfile concatenation 
int ch; 
// Name1, Name2, Name3 are strings 
ifstream f1 (Name1); 
ifstream f2 (Name2); 
ofstream f3 (Name3); 
while ((ch = f1.get())!=-1 ) 
if (ch =='n') 
while ((ch = f2.get())!=-1) { 
f3.put(ch); 
if (ch == 'n') break; 
} 
else f3.put(ch); 
}
Why use I/O streams ? 
•Streams are type safe -- the type of object being I/O'd is known statically by the compiler rather than via dynamically tested '%' fields. 
•Streams are less error prone: 
– Difficult to make robust code using printf. 
•Streams are faster: printf interprets the language of '%' specs, and chooses (at runtime) the proper low-level routine. C++ picks these routines statically based on the actual types of the arguments.
Why use I/O streams ? (cont’d) 
•Streams are extensible -- the C++ I/O mechanism is extensible to new user-defined data types. 
•Streams are subclassable -- ostream and istream (C++ replacements for FILE*) are real classes, and hence subclassable. Can define types that look and act like streams, yet operate on other objects. Examples: 
–A stream that writes to a memory area. 
–A stream that listens to external port.
C++ Strong Typing 
•There are 6 principal situations in which C++ has stronger typing than C. 
1.The empty list of formal parameters means "no arguments" in C++. 
•In C, it means "zero or more arguments", with no type checking at all. Example: 
char * malloc();
C++ Strong Typing (cont’d) 
2.In C, it's OK to use an undefined function; no type checking will be performed. In C++, undefined functions are not allowed. 
Example: 
main() 
f( 3.1415 ); 
// C++: error, f not defined 
// C: OK, taken to mean int f()
C++ Strong Typing (cont’d) 
3.A C function, declared to be value- returning, can fail to return a value. Not in C++. Example: 
double foo() { 
/* ... */ 
return; 
} 
main() { 
if ( foo() ) { ... } 
... 
} 
// C : OK 
// C++: error, no return value.
C++ Strong Typing (cont’d) 
4.In C, assigning a pointer of type void* to a pointer of another type is OK. Not in C++. Example: 
int i = 1024; 
void *pv = &i; 
// C++: error, 
// explicit cast required. 
// C : OK. 
char *pc = pv; 
int len = strlen(pc);
C++ Strong Typing (cont’d) 
5.C++ is more careful about initializing arrays: Example: 
char A[2]="hi"; 
// C++: error, 
// not enough space for '0' 
// C : OK, but no '0' is stored. 
It's best to stick with char A[] = "hi“;
C++ Strong Typing (cont’d) 
6.Free store (heap) management. In C++, we use new and delete, instead of malloc and free. 
•malloc() doesn't call constructors, and free doesn't call destructors. 
•new and delete are type safe.
Object-Oriented Programming 
Object-oriented programming is a programming 
methodology characterized by the following concepts: 
1.Data Abstraction: problem solving via the formulation of abstract data types (ADT's). 
2.Encapsulation: the proximity of data definitions and operation definitions. 
3.Information hiding: the ability to selectively hide implementation details of a given ADT. 
4.Polymorphism: the ability to manipulate different kinds of objects, with only one operation. 
5.Inheritance: the ability of objects of one data type, to inherit operations and data from another data type. Embodies the "is a" notion: a horse is a mammal, a mammal is a vertebrate, a vertebrate is a lifeform.
O-O Principles and C++ Constructs 
O-O Concept C++ Construct(s) 
Abstraction Classes 
Encapsulation Classes 
Information Hiding Public and Private Members 
Polymorphism Operator overloading, 
templates, virtual functions 
Inheritance Derived Classes
O-O is a different Paradigm 
•Central questions when programming. 
–Imperative Paradigm: 
–What to do next ? 
–Object-Oriented Programming 
–What does the object do ? (vs. how) 
•Central activity of programming: 
–Imperative Paradigm: 
–Get the computer to do something. 
–Object-Oriented Programming 
–Get the object to do something.
C vs. C++, side-by-side
C vs. C++, side-by-side (cont’d) 
In C++, methods can appear inside the class definition 
(better encapsulation)
C vs. C++, side-by-side (cont’d) 
In C++, no explicit referencing. 
Could have overloaded <<, >> for Stacks: 
s << 1; s >> i;
Structures and Classes in C++ 
•Structures in C++ differ from those in C in that members can be functions. 
•A special member function is the “constructor”, whose name is the same as the structure. It is used to initialize the object: 
struct buffer { 
buffer() 
{size=MAXBUF+1; front=rear=0;} 
char buf[MAXBUF+1]; 
int size, front, rear; 
}
Structures and Classes in C++ 
The idea is to add some operations on objects 
of type buffer: 
struct buffer { 
buffer() {size=MAXBUF+1;front=rear=0;} 
char buf[MAXBUF+1]; 
int size, front, rear; 
int succ(int i) {return (i+1)%size;} 
int enter(char); 
char leave(); 
}
Structures and Classes in C++ 
The definition (body) of a member function can be 
included in the structure's declaration, or may 
appear later. If so, use the name resolution 
operator (::) 
int buffer::enter(char x) { 
// body of enter } 
char buffer::leave() { 
// body of leave }
Public and Private Members 
Structures and classes are closely related in C++: 
struct x { <member-dclns> }; 
is equivalent to 
class x { public: <member-dclns>}; 
Difference: by default, members of a structure are 
public; members of a class are private. So, 
class x { <member-dclns> }; 
is the same as 
struct x { private: <member-dclns> };
Header File Partitioning
Header File Partitioning (cont’d)
Header File Partitioning (cont’d)
Programming Language Concepts Lecture 18 
Prepared by 
Manuel E. Bermúdez, Ph.D. 
Associate Professor 
University of Florida 
Object-Oriented Programming Part 1

Más contenido relacionado

La actualidad más candente

Chapter Seven(2)
Chapter Seven(2)Chapter Seven(2)
Chapter Seven(2)bolovv
 
#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class Structure#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class StructureHadziq Fabroyir
 
(2) collections algorithms
(2) collections algorithms(2) collections algorithms
(2) collections algorithmsNico Ludwig
 
Contravariant functors in scala
Contravariant functors in scalaContravariant functors in scala
Contravariant functors in scalaPiotr Paradziński
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programsharman kaur
 
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementEelco Visser
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its functionFrankie Jones
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seoJinTaek Seo
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1Shashwat Shriparv
 
01. introduction to C++
01. introduction to C++01. introduction to C++
01. introduction to C++Haresh Jaiswal
 
Managing console i/o operation,working with files
Managing console i/o operation,working with filesManaging console i/o operation,working with files
Managing console i/o operation,working with filesramya marichamy
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Piotr Paradziński
 
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...Kamiya Toshihiro
 

La actualidad más candente (20)

basics of c++
basics of c++basics of c++
basics of c++
 
Chapter Seven(2)
Chapter Seven(2)Chapter Seven(2)
Chapter Seven(2)
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
 
Managing console input
Managing console inputManaging console input
Managing console input
 
C++ io manipulation
C++ io manipulationC++ io manipulation
C++ io manipulation
 
#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class Structure#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class Structure
 
(2) collections algorithms
(2) collections algorithms(2) collections algorithms
(2) collections algorithms
 
Contravariant functors in scala
Contravariant functors in scalaContravariant functors in scala
Contravariant functors in scala
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programs
 
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory Management
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 
Computer science sqp
Computer science sqpComputer science sqp
Computer science sqp
 
01. introduction to C++
01. introduction to C++01. introduction to C++
01. introduction to C++
 
Managing console i/o operation,working with files
Managing console i/o operation,working with filesManaging console i/o operation,working with files
Managing console i/o operation,working with files
 
Managing console
Managing consoleManaging console
Managing console
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...
 
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
 

Destacado

Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented TechnologiesTushar B Kute
 
Programming Language
Programming  LanguageProgramming  Language
Programming LanguageAdeel Hamid
 
Conceitos básicos de orientação a objetos
Conceitos básicos de orientação a objetosConceitos básicos de orientação a objetos
Conceitos básicos de orientação a objetosSérgio Souza Costa
 
Polymorphism (Ad-hoc and Universal)
Polymorphism (Ad-hoc and Universal)Polymorphism (Ad-hoc and Universal)
Polymorphism (Ad-hoc and Universal)Sérgio Souza Costa
 
Principles of programming languages. Detail notes
Principles of programming languages. Detail notesPrinciples of programming languages. Detail notes
Principles of programming languages. Detail notesVIKAS SINGH BHADOURIA
 
System concepts, elements and types of systems ppt
System concepts, elements and types of systems pptSystem concepts, elements and types of systems ppt
System concepts, elements and types of systems pptShobhit Sharma
 

Destacado (7)

Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
 
Programming Language
Programming  LanguageProgramming  Language
Programming Language
 
Conceitos básicos de orientação a objetos
Conceitos básicos de orientação a objetosConceitos básicos de orientação a objetos
Conceitos básicos de orientação a objetos
 
Polymorphism (Ad-hoc and Universal)
Polymorphism (Ad-hoc and Universal)Polymorphism (Ad-hoc and Universal)
Polymorphism (Ad-hoc and Universal)
 
Principles of programming languages. Detail notes
Principles of programming languages. Detail notesPrinciples of programming languages. Detail notes
Principles of programming languages. Detail notes
 
System concepts, elements and types of systems ppt
System concepts, elements and types of systems pptSystem concepts, elements and types of systems ppt
System concepts, elements and types of systems ppt
 
System concepts
System conceptsSystem concepts
System concepts
 

Similar a L6

Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Languagesatvirsandhu9
 
The Differences Between C and C++
The Differences Between C and C++The Differences Between C and C++
The Differences Between C and C++LingarajSenapati2
 
Getting Started Cpp
Getting Started CppGetting Started Cpp
Getting Started CppLong Cao
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++Amresh Raj
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++Ankur Pandey
 
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 itPushkarNiroula1
 
object oriented programming language fundamentals
object oriented programming language fundamentalsobject oriented programming language fundamentals
object oriented programming language fundamentalsChaithraCSHirematt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.pptDevliNeeraj
 

Similar a L6 (20)

C++ language
C++ languageC++ language
C++ language
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
The Differences Between C and C++
The Differences Between C and C++The Differences Between C and C++
The Differences Between C and C++
 
Getting Started Cpp
Getting Started CppGetting Started Cpp
Getting Started Cpp
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
 
SRAVANByCPP
SRAVANByCPPSRAVANByCPP
SRAVANByCPP
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
 
Chap 2 c++
Chap 2 c++Chap 2 c++
Chap 2 c++
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
 
C++ Version 2
C++  Version 2C++  Version 2
C++ Version 2
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
Lab 1.pptx
Lab 1.pptxLab 1.pptx
Lab 1.pptx
 
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
 
object oriented programming language fundamentals
object oriented programming language fundamentalsobject oriented programming language fundamentals
object oriented programming language fundamentals
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 

Más de lksoo

Más de lksoo (20)

Lo48
Lo48Lo48
Lo48
 
Lo43
Lo43Lo43
Lo43
 
Lo39
Lo39Lo39
Lo39
 
Lo37
Lo37Lo37
Lo37
 
Lo27
Lo27Lo27
Lo27
 
Lo17
Lo17Lo17
Lo17
 
Lo12
Lo12Lo12
Lo12
 
T3
T3T3
T3
 
T2
T2T2
T2
 
T1
T1T1
T1
 
T4
T4T4
T4
 
P5
P5P5
P5
 
P4
P4P4
P4
 
P3
P3P3
P3
 
P1
P1P1
P1
 
P2
P2P2
P2
 
L10
L10L10
L10
 
L9
L9L9
L9
 
L8
L8L8
L8
 
L7
L7L7
L7
 

Último

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
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.pdfQucHHunhnh
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 

Último (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
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
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

L6

  • 1. Programming Language Concepts Lecture 18 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Object-Oriented Programming Part 1
  • 2. Object Oriented Programming •Over time, data abstraction has become essential as programs became complicated. •Benefits: 1. Reduce conceptual load (minimum detail). 2. Fault containment. 3. Independent program components. (difficult in practice). •Code reuse possible by extending and refining abstractions.
  • 3. Object Oriented Programming •A methodology of programming •Four (Five ?) major principles: 1.Data Abstraction. 2.Encapsulation. 3.Information Hiding. 4.Polymorphism (dynamic binding). 5.Inheritance. (particular case of polymorphism ?) Will describe these using C++, because ...
  • 4. The C++ language •An object-oriented, general-purpose programming language, derived from C (C++ = C plus classes). •C++ adds the following to C: 1.Inlining and overloading of functions. 2.Default argument values. 3.Argument pass-by-reference. 4.Free store operators new and delete, instead of malloc() and free(). 5.Support for object-oriented programming, through classes, information hiding, public interfaces, operator overloading, inheritance, and templates.
  • 5. Design Objectives in C++ •Compatibility. Existing code in C can be used. Even existing, pre-compiled libraries can be linked with new C++ code. •Efficiency. No additional cost for using C++. Overheadof function calls is eliminated where possible. •Strict type checking. Aids debugging, allows generation of efficient code. •C++ designed by Bjarne Stroustrup of Bell Labs (now at TAMU). •Standardization: ANSI, ISO.
  • 6. Non Object-Oriented Extensions to C •Major improvements over C. 1.Stream I/O. 2.Strong typing. 3.Parameter passing by reference. 4.Default argument values. 5.Inlining. We’ve discussed some of these already.
  • 7. Stream I/O in C++ •Input and output in C++ is handled by streams. •The directive #include <iostream.h> declares 2 streams: cin and cout. • cin is associated with standard input. Extraction: operator>>. • cout is associated with standard output. Insertion: operator<<. •In C++, input is line buffered, i.e. the user must press <RTN> before any characters are processed.
  • 8. Example of Stream I/O in C++ A function that returns the sum of the numbers in the file Number.in int fileSum(); { ifstream infile("Number.in"); int sum = 0; int value; //read until non-integer or <eof> while(infile >> value) sum = sum + value; return sum; }
  • 9. Example of Stream I/O in C++ Example 2: A function to copy myfile into copy.myfile void copyfile() { ifstream source("myfile"); ofstream destin("copy.myfile"); char ch; while (source.get(ch)) destin<<ch; }
  • 10. Line-by-line textfile concatenation int ch; // Name1, Name2, Name3 are strings ifstream f1 (Name1); ifstream f2 (Name2); ofstream f3 (Name3); while ((ch = f1.get())!=-1 ) if (ch =='n') while ((ch = f2.get())!=-1) { f3.put(ch); if (ch == 'n') break; } else f3.put(ch); }
  • 11. Why use I/O streams ? •Streams are type safe -- the type of object being I/O'd is known statically by the compiler rather than via dynamically tested '%' fields. •Streams are less error prone: – Difficult to make robust code using printf. •Streams are faster: printf interprets the language of '%' specs, and chooses (at runtime) the proper low-level routine. C++ picks these routines statically based on the actual types of the arguments.
  • 12. Why use I/O streams ? (cont’d) •Streams are extensible -- the C++ I/O mechanism is extensible to new user-defined data types. •Streams are subclassable -- ostream and istream (C++ replacements for FILE*) are real classes, and hence subclassable. Can define types that look and act like streams, yet operate on other objects. Examples: –A stream that writes to a memory area. –A stream that listens to external port.
  • 13. C++ Strong Typing •There are 6 principal situations in which C++ has stronger typing than C. 1.The empty list of formal parameters means "no arguments" in C++. •In C, it means "zero or more arguments", with no type checking at all. Example: char * malloc();
  • 14. C++ Strong Typing (cont’d) 2.In C, it's OK to use an undefined function; no type checking will be performed. In C++, undefined functions are not allowed. Example: main() f( 3.1415 ); // C++: error, f not defined // C: OK, taken to mean int f()
  • 15. C++ Strong Typing (cont’d) 3.A C function, declared to be value- returning, can fail to return a value. Not in C++. Example: double foo() { /* ... */ return; } main() { if ( foo() ) { ... } ... } // C : OK // C++: error, no return value.
  • 16. C++ Strong Typing (cont’d) 4.In C, assigning a pointer of type void* to a pointer of another type is OK. Not in C++. Example: int i = 1024; void *pv = &i; // C++: error, // explicit cast required. // C : OK. char *pc = pv; int len = strlen(pc);
  • 17. C++ Strong Typing (cont’d) 5.C++ is more careful about initializing arrays: Example: char A[2]="hi"; // C++: error, // not enough space for '0' // C : OK, but no '0' is stored. It's best to stick with char A[] = "hi“;
  • 18. C++ Strong Typing (cont’d) 6.Free store (heap) management. In C++, we use new and delete, instead of malloc and free. •malloc() doesn't call constructors, and free doesn't call destructors. •new and delete are type safe.
  • 19. Object-Oriented Programming Object-oriented programming is a programming methodology characterized by the following concepts: 1.Data Abstraction: problem solving via the formulation of abstract data types (ADT's). 2.Encapsulation: the proximity of data definitions and operation definitions. 3.Information hiding: the ability to selectively hide implementation details of a given ADT. 4.Polymorphism: the ability to manipulate different kinds of objects, with only one operation. 5.Inheritance: the ability of objects of one data type, to inherit operations and data from another data type. Embodies the "is a" notion: a horse is a mammal, a mammal is a vertebrate, a vertebrate is a lifeform.
  • 20. O-O Principles and C++ Constructs O-O Concept C++ Construct(s) Abstraction Classes Encapsulation Classes Information Hiding Public and Private Members Polymorphism Operator overloading, templates, virtual functions Inheritance Derived Classes
  • 21. O-O is a different Paradigm •Central questions when programming. –Imperative Paradigm: –What to do next ? –Object-Oriented Programming –What does the object do ? (vs. how) •Central activity of programming: –Imperative Paradigm: –Get the computer to do something. –Object-Oriented Programming –Get the object to do something.
  • 22. C vs. C++, side-by-side
  • 23. C vs. C++, side-by-side (cont’d) In C++, methods can appear inside the class definition (better encapsulation)
  • 24. C vs. C++, side-by-side (cont’d) In C++, no explicit referencing. Could have overloaded <<, >> for Stacks: s << 1; s >> i;
  • 25. Structures and Classes in C++ •Structures in C++ differ from those in C in that members can be functions. •A special member function is the “constructor”, whose name is the same as the structure. It is used to initialize the object: struct buffer { buffer() {size=MAXBUF+1; front=rear=0;} char buf[MAXBUF+1]; int size, front, rear; }
  • 26. Structures and Classes in C++ The idea is to add some operations on objects of type buffer: struct buffer { buffer() {size=MAXBUF+1;front=rear=0;} char buf[MAXBUF+1]; int size, front, rear; int succ(int i) {return (i+1)%size;} int enter(char); char leave(); }
  • 27. Structures and Classes in C++ The definition (body) of a member function can be included in the structure's declaration, or may appear later. If so, use the name resolution operator (::) int buffer::enter(char x) { // body of enter } char buffer::leave() { // body of leave }
  • 28. Public and Private Members Structures and classes are closely related in C++: struct x { <member-dclns> }; is equivalent to class x { public: <member-dclns>}; Difference: by default, members of a structure are public; members of a class are private. So, class x { <member-dclns> }; is the same as struct x { private: <member-dclns> };
  • 32. Programming Language Concepts Lecture 18 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Object-Oriented Programming Part 1