The document discusses various C++ concepts including static class members, the this pointer, friend functions and classes, dynamic memory management using new and delete operators, function overloading, operator overloading, templates, and inheritance. Static class members are accessible to all objects of the class and only one copy is created for the entire class. The this pointer refers to the current object from within non-static member functions. Friend functions and classes can access private members of other classes. Dynamic memory is allocated using new and freed using delete.
The document discusses object-oriented programming concepts such as classes, objects, encapsulation, inheritance, polymorphism, and dynamic binding. It compares procedural programming with object-oriented programming, highlighting differences in their approaches and emphases. Key advantages of OOP include reusability, extensibility, and simplicity. Real-world examples are provided to illustrate OOP concepts. Input/output operations in C++ using streams are also overviewed.
The document discusses classes and objects in object-oriented programming. It defines what a class is, how classes are declared with public and private members, and how objects are instantiated from classes. It also describes defining member functions inside and outside of classes, and the use of static class members and friend functions.
This Powerpoint presentation covers following topics of C Plus Plus:
Features of OOP
Classes in C++
Objects & Creating the Objects
Constructors & Destructors
Friend Functions & Classes
Static data members & functions
Classes and objects allow bundling of related data and functions. An object is an instance of a class that contains the class's data members and can access its member functions. Classes improve on procedural programming by avoiding issues when data structures change. A class defines the data types and functions for a user-defined type using a class name, data members, and member functions. Objects are instances of classes that hold separate copies of class data. Access specifiers like public, private, and protected control access to class members.
Basic Of C++ , Classes and Objects
1. A class defines a new data type that encapsulates data members and member functions. Classes allow for creating user-defined data types.
2. A class declaration specifies the data members and member functions of the class, while class definitions provide the implementation of member functions.
3. Objects are variables of a class type that allocate memory to store the class's data members. Member functions can access and manipulate the data members of an object.
Here is a Python class with the specifications provided in the question:
class PICTURE:
def __init__(self, pno, category, location):
self.pno = pno
self.category = category
self.location = location
def FixLocation(self, new_location):
self.location = new_location
This defines a PICTURE class with three instance attributes - pno, category and location as specified in the question. It also defines a FixLocation method to assign a new location as required.
This document discusses classes and objects in C++. It defines a class as a collection of related data and functions under a single name. A class is a user-defined type that combines data representation and methods for manipulating that data into a single unit. Objects are instances of a class - variables that are declared based on a class type. The document covers defining classes, declaring objects, accessing class members, arrays within classes, access modifiers like public, private and protected, static class members, inline functions, friend functions and classes.
The document discusses object-oriented programming concepts such as classes, objects, encapsulation, inheritance, polymorphism, and dynamic binding. It compares procedural programming with object-oriented programming, highlighting differences in their approaches and emphases. Key advantages of OOP include reusability, extensibility, and simplicity. Real-world examples are provided to illustrate OOP concepts. Input/output operations in C++ using streams are also overviewed.
The document discusses classes and objects in object-oriented programming. It defines what a class is, how classes are declared with public and private members, and how objects are instantiated from classes. It also describes defining member functions inside and outside of classes, and the use of static class members and friend functions.
This Powerpoint presentation covers following topics of C Plus Plus:
Features of OOP
Classes in C++
Objects & Creating the Objects
Constructors & Destructors
Friend Functions & Classes
Static data members & functions
Classes and objects allow bundling of related data and functions. An object is an instance of a class that contains the class's data members and can access its member functions. Classes improve on procedural programming by avoiding issues when data structures change. A class defines the data types and functions for a user-defined type using a class name, data members, and member functions. Objects are instances of classes that hold separate copies of class data. Access specifiers like public, private, and protected control access to class members.
Basic Of C++ , Classes and Objects
1. A class defines a new data type that encapsulates data members and member functions. Classes allow for creating user-defined data types.
2. A class declaration specifies the data members and member functions of the class, while class definitions provide the implementation of member functions.
3. Objects are variables of a class type that allocate memory to store the class's data members. Member functions can access and manipulate the data members of an object.
Here is a Python class with the specifications provided in the question:
class PICTURE:
def __init__(self, pno, category, location):
self.pno = pno
self.category = category
self.location = location
def FixLocation(self, new_location):
self.location = new_location
This defines a PICTURE class with three instance attributes - pno, category and location as specified in the question. It also defines a FixLocation method to assign a new location as required.
This document discusses classes and objects in C++. It defines a class as a collection of related data and functions under a single name. A class is a user-defined type that combines data representation and methods for manipulating that data into a single unit. Objects are instances of a class - variables that are declared based on a class type. The document covers defining classes, declaring objects, accessing class members, arrays within classes, access modifiers like public, private and protected, static class members, inline functions, friend functions and classes.
The document discusses structures and classes in C++. It explains that structures in C++ allow grouping of related data items but do not provide data hiding. Classes in C++ address this limitation by allowing data and functions as members, and designating some members as private. The key aspects of a class include its declaration with data and function members, creation of objects from the class, and accessing members using objects and dot operator (for public members) or within class functions (for private members). Static members are also discussed which are shared among all class objects.
The document discusses object-oriented programming concepts like classes, objects, member functions, data members, constructors, and encapsulation. It explains that a class defines the structure and behavior of objects, with data members representing attributes and member functions representing behaviors. Constructors initialize an object's data when it is created. Encapsulation protects data by making it private and only accessible through public member functions.
The document discusses Java collection framework. It defines that an array is a collection of elements stored in continuous memory locations with fixed size. Collections were introduced in Java 1.2 to overcome array limitations. The document describes common collection interfaces like List, Set, Map and their implementation classes like ArrayList, LinkedList, HashSet, TreeSet, HashMap etc. It provides details about various collection classes like their creation, methods and differences.
This is the object oriented lecture nmbr 3rd , if you want lecture 2 or 1 u can check it my account , this is the programing tutorial, please follow me and thank you
1. The document introduces classes, explaining concepts like data hiding, abstraction, and encapsulation. It defines a class as a way to bind data and associated functions together to represent real-world entities.
2. A class has four attributes - data members to describe characteristics, member functions for behaviors, an access level to control access, and a class name used to create objects. An example class Account is given with attributes like account number, type, balance and functions like deposit and withdraw.
3. Objects are instances of a class that allow manipulating the data and calling the functions of the class. Some examples of class objects are given.
This document discusses classes and objects in C++. It defines a class as a user-defined data type that implements an abstract object by combining data members and member functions. Data members are called data fields and member functions are called methods. An abstract data type separates logical properties from implementation details and supports data abstraction, encapsulation, and hiding. Common examples of abstract data types include Boolean, integer, array, stack, queue, and tree structures. The document goes on to describe class definitions, access specifiers, static members, and how to define and access class members and methods.
This document provides an overview of classes and objects in C++. It defines object-oriented programming as encapsulating data and functions into packages called classes. A class defines both data members (attributes) and member functions (behavior). Class members can be declared as private or public, with private only accessible within the class and public accessible outside. The document also discusses creating objects from classes, constructors, destructors, and accessing class members. Examples are provided of defining a Circle class to represent geometric circles and a Time class to represent time values.
The document discusses key concepts in C++ classes including encapsulation, information hiding, access specifiers, and constructors. It defines a class as a way to combine attributes and behaviors of real-world objects into a single unit. A class uses encapsulation to associate code and data, and information hiding to secure data from direct access. Access specifiers like public, private, and protected determine member visibility. Constructors are special member functions that initialize objects upon instantiation.
The document provides an introduction to object-oriented programming concepts and Java. It discusses key OOP concepts like objects, classes, encapsulation, inheritance, and polymorphism. It also explains the basics of Java, including its history, features like being platform independent and secure, and the structure of a Java program with main components like packages, import statements, and class definitions.
This document provides an overview of Unit 1 and Unit 2 of the B.Tech II Yr II Semester course. Unit 1 covers object-oriented programming concepts like classes, inheritance, polymorphism over 5 lectures. The slides cover topics such as the need for OOP, classes and instances, method binding and exceptions. Unit 2 covers Java fundamentals like data types, variables, control statements and classes over 7 lectures across 85 slides, including the history of Java and its evolution from C and C++.
Object oriented programming is a technique where programs are written as objects. Some common object oriented languages are C++, Smalltalk, and Java. Object oriented programming models real world entities like people, things, and concepts as objects that have properties and functions. Classes are collections of similar objects that define their characteristics. Object oriented programming is based on real world modeling, reuseability, information hiding, and polymorphism.
This document provides information about various concepts related to classes in C++, including defining a class, creating objects, special member functions like constructors and destructors, implementing class methods, accessing class members, and class abstraction. It defines a Circle class with private data member radius and public member functions to set and get radius and calculate diameter, area, and circumference. It demonstrates defining member functions inside and outside the class and using operators like dot and arrow to access class members.
In this you learn about
--Constructors in Java
--Types of Constructors
1. Default Constructor
2. Parameterized Constructor
Difference between Constructor and Method
This document introduces classes and objects in Java. It defines a class as a collection of fields and methods that operate on those fields. It shows how to define a Circle class with fields for the x and y coordinates and radius, and methods to calculate the circumference and area. It demonstrates how to create Circle objects, access the object fields and methods, and use the Circle class in a sample program.
The document discusses key concepts of object-oriented programming using C++ including defining classes, encapsulation, static vs non-static members, and polymorphism. A class defines a category of objects by grouping related data and functions. Classes encapsulate data by hiding implementation details and exposing an interface. Static members are shared across all objects while non-static members are unique to each object instance. Polymorphism allows the same operation to behave differently based on the object type.
How to write you first class in c++ object oriented programmingSyed Faizan Hassan
The document discusses how to write a first class in C++ using object-oriented programming. It explains that a class defines functions and variables and is like a blueprint for creating objects. An object is an instance of a class that stores values and allows access to class functions. The document provides an example class for calculating the sum of two numbers by getting input, processing the calculation, and outputting the result. It demonstrates creating an object of the class in the main function and calling the class functions through the object.
The static keyword in Java is used for memory management. It allows variables and methods to belong to the class rather than instances of the class. Static variables and methods are associated with the class, not objects, so they can be accessed without creating an object of the class. Static variables only have one copy in memory and static methods can access static variables and change their values without creating an object. Examples demonstrate how to declare static variables and methods and how they differ from non-static variables and methods.
This document discusses data members and member functions in object-oriented programming. It defines data members as variables declared inside a class and member functions as functions declared inside a class. It covers accessing public, private, and protected data members, defining member functions inside and outside the class, and different types of member functions like static, const, inline, and friend functions. The document provides examples and explanations for each concept to help explain how data members and member functions work in object-oriented programming.
This document provides an overview of object-oriented programming concepts in C++, including classes, objects, encapsulation, inheritance, polymorphism, and more. Key concepts are defined, such as classes containing data members and methods. Inheritance allows derived classes to inherit properties of base classes. Polymorphism allows calling the correct overridden method at runtime based on the object type. Virtual functions provide late binding so the correct derived class method is called.
Here is the implementation of the DayType class with the required operations:
[CODE]
#include <iostream>
using namespace std;
class DayType {
private:
string day;
public:
DayType(string d="Sun") {
day = d;
}
void setDay(string d) {
day = d;
}
void printDay() {
cout << day << endl;
}
string returnDay() {
return day;
}
string nextDay() {
if(day == "Sat")
return "Sun";
else {
int index = 0;
if(day == "Sun")
index = 0;
The document discusses various C++ concepts including static class members and static member functions, the this pointer, friend functions, dynamic memory allocation using new and delete operators, function overloading and operator overloading, restrictions on operator overloading, type conversion, and templates and inheritance. It provides examples to illustrate concepts like static class members, friend functions, new and delete operators, function overloading, and operator overloading. The document serves as a reference for various advanced C++ programming concepts.
The document discusses structures and classes in C++. It explains that structures in C++ allow grouping of related data items but do not provide data hiding. Classes in C++ address this limitation by allowing data and functions as members, and designating some members as private. The key aspects of a class include its declaration with data and function members, creation of objects from the class, and accessing members using objects and dot operator (for public members) or within class functions (for private members). Static members are also discussed which are shared among all class objects.
The document discusses object-oriented programming concepts like classes, objects, member functions, data members, constructors, and encapsulation. It explains that a class defines the structure and behavior of objects, with data members representing attributes and member functions representing behaviors. Constructors initialize an object's data when it is created. Encapsulation protects data by making it private and only accessible through public member functions.
The document discusses Java collection framework. It defines that an array is a collection of elements stored in continuous memory locations with fixed size. Collections were introduced in Java 1.2 to overcome array limitations. The document describes common collection interfaces like List, Set, Map and their implementation classes like ArrayList, LinkedList, HashSet, TreeSet, HashMap etc. It provides details about various collection classes like their creation, methods and differences.
This is the object oriented lecture nmbr 3rd , if you want lecture 2 or 1 u can check it my account , this is the programing tutorial, please follow me and thank you
1. The document introduces classes, explaining concepts like data hiding, abstraction, and encapsulation. It defines a class as a way to bind data and associated functions together to represent real-world entities.
2. A class has four attributes - data members to describe characteristics, member functions for behaviors, an access level to control access, and a class name used to create objects. An example class Account is given with attributes like account number, type, balance and functions like deposit and withdraw.
3. Objects are instances of a class that allow manipulating the data and calling the functions of the class. Some examples of class objects are given.
This document discusses classes and objects in C++. It defines a class as a user-defined data type that implements an abstract object by combining data members and member functions. Data members are called data fields and member functions are called methods. An abstract data type separates logical properties from implementation details and supports data abstraction, encapsulation, and hiding. Common examples of abstract data types include Boolean, integer, array, stack, queue, and tree structures. The document goes on to describe class definitions, access specifiers, static members, and how to define and access class members and methods.
This document provides an overview of classes and objects in C++. It defines object-oriented programming as encapsulating data and functions into packages called classes. A class defines both data members (attributes) and member functions (behavior). Class members can be declared as private or public, with private only accessible within the class and public accessible outside. The document also discusses creating objects from classes, constructors, destructors, and accessing class members. Examples are provided of defining a Circle class to represent geometric circles and a Time class to represent time values.
The document discusses key concepts in C++ classes including encapsulation, information hiding, access specifiers, and constructors. It defines a class as a way to combine attributes and behaviors of real-world objects into a single unit. A class uses encapsulation to associate code and data, and information hiding to secure data from direct access. Access specifiers like public, private, and protected determine member visibility. Constructors are special member functions that initialize objects upon instantiation.
The document provides an introduction to object-oriented programming concepts and Java. It discusses key OOP concepts like objects, classes, encapsulation, inheritance, and polymorphism. It also explains the basics of Java, including its history, features like being platform independent and secure, and the structure of a Java program with main components like packages, import statements, and class definitions.
This document provides an overview of Unit 1 and Unit 2 of the B.Tech II Yr II Semester course. Unit 1 covers object-oriented programming concepts like classes, inheritance, polymorphism over 5 lectures. The slides cover topics such as the need for OOP, classes and instances, method binding and exceptions. Unit 2 covers Java fundamentals like data types, variables, control statements and classes over 7 lectures across 85 slides, including the history of Java and its evolution from C and C++.
Object oriented programming is a technique where programs are written as objects. Some common object oriented languages are C++, Smalltalk, and Java. Object oriented programming models real world entities like people, things, and concepts as objects that have properties and functions. Classes are collections of similar objects that define their characteristics. Object oriented programming is based on real world modeling, reuseability, information hiding, and polymorphism.
This document provides information about various concepts related to classes in C++, including defining a class, creating objects, special member functions like constructors and destructors, implementing class methods, accessing class members, and class abstraction. It defines a Circle class with private data member radius and public member functions to set and get radius and calculate diameter, area, and circumference. It demonstrates defining member functions inside and outside the class and using operators like dot and arrow to access class members.
In this you learn about
--Constructors in Java
--Types of Constructors
1. Default Constructor
2. Parameterized Constructor
Difference between Constructor and Method
This document introduces classes and objects in Java. It defines a class as a collection of fields and methods that operate on those fields. It shows how to define a Circle class with fields for the x and y coordinates and radius, and methods to calculate the circumference and area. It demonstrates how to create Circle objects, access the object fields and methods, and use the Circle class in a sample program.
The document discusses key concepts of object-oriented programming using C++ including defining classes, encapsulation, static vs non-static members, and polymorphism. A class defines a category of objects by grouping related data and functions. Classes encapsulate data by hiding implementation details and exposing an interface. Static members are shared across all objects while non-static members are unique to each object instance. Polymorphism allows the same operation to behave differently based on the object type.
How to write you first class in c++ object oriented programmingSyed Faizan Hassan
The document discusses how to write a first class in C++ using object-oriented programming. It explains that a class defines functions and variables and is like a blueprint for creating objects. An object is an instance of a class that stores values and allows access to class functions. The document provides an example class for calculating the sum of two numbers by getting input, processing the calculation, and outputting the result. It demonstrates creating an object of the class in the main function and calling the class functions through the object.
The static keyword in Java is used for memory management. It allows variables and methods to belong to the class rather than instances of the class. Static variables and methods are associated with the class, not objects, so they can be accessed without creating an object of the class. Static variables only have one copy in memory and static methods can access static variables and change their values without creating an object. Examples demonstrate how to declare static variables and methods and how they differ from non-static variables and methods.
This document discusses data members and member functions in object-oriented programming. It defines data members as variables declared inside a class and member functions as functions declared inside a class. It covers accessing public, private, and protected data members, defining member functions inside and outside the class, and different types of member functions like static, const, inline, and friend functions. The document provides examples and explanations for each concept to help explain how data members and member functions work in object-oriented programming.
This document provides an overview of object-oriented programming concepts in C++, including classes, objects, encapsulation, inheritance, polymorphism, and more. Key concepts are defined, such as classes containing data members and methods. Inheritance allows derived classes to inherit properties of base classes. Polymorphism allows calling the correct overridden method at runtime based on the object type. Virtual functions provide late binding so the correct derived class method is called.
Here is the implementation of the DayType class with the required operations:
[CODE]
#include <iostream>
using namespace std;
class DayType {
private:
string day;
public:
DayType(string d="Sun") {
day = d;
}
void setDay(string d) {
day = d;
}
void printDay() {
cout << day << endl;
}
string returnDay() {
return day;
}
string nextDay() {
if(day == "Sat")
return "Sun";
else {
int index = 0;
if(day == "Sun")
index = 0;
The document discusses various C++ concepts including static class members and static member functions, the this pointer, friend functions, dynamic memory allocation using new and delete operators, function overloading and operator overloading, restrictions on operator overloading, type conversion, and templates and inheritance. It provides examples to illustrate concepts like static class members, friend functions, new and delete operators, function overloading, and operator overloading. The document serves as a reference for various advanced C++ programming concepts.
A class defines a data structure that can contain both data and functions as members. An object is an instance of a class that allocates memory for the class's data members. Classes allow the declaration of multiple objects that each have their own copies of the class's data members and can access the class's member functions. Constructors initialize an object's data members when it is created, while destructors perform cleanup tasks when an object is destroyed.
The document provides information about object-oriented programming concepts in C++ including class, object, constructor, destructor, access specifiers, data members, member functions, static members, and friend functions. It defines each concept, provides syntax examples, and explains how to create a class, make objects, and access members. Constructors are used to initialize objects while destructors deallocate memory. Access specifiers determine public, private, and protected access.
This document discusses various concepts related to classes and objects in C++, including member functions, data members, constructors, destructors, friend functions, and nested classes. It provides examples of defining member functions inside and outside the class, different access specifiers for data members, examples of friend functions and classes, returning objects from functions, arrays of objects, and nested classes. It also discusses constructors in more detail, including overloaded constructors, copy constructors, dynamic initialization of objects, constructors for primitive types, and constructors with default arguments.
The document discusses various object-oriented programming concepts in C++ like classes, objects, member functions, data members, constructors, destructors, friend functions, and namespaces. It provides examples of defining classes with data members and member functions, declaring objects of a class, and using constructors and destructors. It also explains concepts like overloaded constructors, copy constructors, nested classes, dynamic initialization of objects, and friend functions.
The document discusses classes and objects in C++. Some key points:
- A class defines a new user-defined data type that encapsulates data members and member functions. Data members represent the attributes of an object, while member functions represent the behaviors.
- When a class is defined, objects can be instantiated from that class. Objects are instances of a class that allocate memory to store the class's data members. Multiple objects of the same class can exist.
- Member functions can access private data members, while non-member functions cannot. Member functions can be defined inside or outside the class. Static members exist only once per class rather than per object.
- Classes allow data abstraction by hiding implementation
This document discusses object-oriented programming concepts in C++ including classes, objects, constructors, destructors, and friend functions. It begins by explaining that classes are abstract data types that contain data members and member functions. It then provides examples of declaring a class, creating objects, and accessing class members. It also covers topics like static class members, arrays of objects, constructor and destructor definitions and uses, and declaring friend functions to allow non-member functions access to private class members.
Lecture-11 Friend Functions and inline functions.pptxrayanbabur
This document discusses various object-oriented programming concepts in C++ including friend functions, inline functions, the this pointer, and static members. Friend functions can access private members of a class but are not member functions themselves. Inline functions avoid code duplication. The this pointer refers to the invoking object inside member functions. Static members are shared across all class objects rather than each object having its own copy. The document provides examples to demonstrate how each concept works in C++ code.
This document discusses key concepts of classes and objects in C++ including access specifiers, constructors, destructors, mutators and accessors, inline functions, polymorphism through operator and function overloading, static class members, friend functions and classes, inheritance, and virtual functions. It provides examples of how these concepts are implemented in C++ code.
The document discusses several key concepts in C++ classes including:
1. Friend classes allow one class to access the private members of another class.
2. Inline functions expand the function code in place rather than calling the function.
3. Parameterized constructors allow passing arguments to initialize object properties.
4. Static class members are shared across all objects rather than each object having its own copy.
- A class is the most important feature of C++ that supports object-oriented programming (OOP). It allows a program to be designed using classes which are a collection of data and functions.
- When an object of a class is declared, memory is allocated for that object's data members. However, defining a class alone does not allocate memory - it only specifies the data members and member functions.
- Member functions can access and manipulate the class's data members. They are called through an object using the dot operator. Constructors are special member functions that initialize an object's data members when it is created.
Static class data in C++ allows for data that is shared across all instances of a class. A static data member exists only once in memory and is shared by all objects of the class. Static member functions can access private static data without an object instance. The example shows a static count variable that is incremented by the constructor and can be accessed through a getcount() member function, returning the same value for all objects.
Classes extend the built-in capabilities of C++ able you in representing and solving complex, real-world problems. A class is an organization of data and functions which operate on them. Data structures are called data members and the functions are called member functions, the combination of data members and member functions constitute a data
object or simply an object.
Class is a group of data member and member functions. Another word class is a collection of objects of similar type.
To create a class, use the class keyword followed by a name for the object. Like any other declared variable, the class declaration ends with a semi-colon. The name of a class follows the rules we have applied for variable and function names.
This document summarizes key concepts in object-oriented programming (OOP) in Java, including static keyword, instance member, class member, inheritance, encapsulation, polymorphism, object, class, constructor, and more. It provides examples to illustrate static variables and methods, the this keyword, super keyword, final keyword, abstract classes vs interfaces, and method overloading as a form of compile-time polymorphism.
Static Keyword Static is a keyword in C++ used to give special chara.pdfKUNALHARCHANDANI1
Static Keyword Static is a keyword in C++ used to give special characteristics to an element.
Static elements are allocated storage only once in a program lifetime in static storage area. And
they have a scope till the program lifetime. Static Keyword can be used with following, Static
variable in functions Static Class Objects Static member Variable in class Static Methods in class
Static variables inside Functions Static variables when used inside function are initialized only
once, and then they hold there value even through function calls. These static variables are stored
on static storage area , not in stack. void counter() { static int count=0; cout << count++; } int
main(0 { for(int i=0;i<5;i++) { counter(); } } Output : 0 1 2 3 4 Let\'s se the same program\'s
output without using static variable. void counter() { int count=0; cout << count++; } int main(0
{ for(int i=0;i<5;i++) { counter(); } } Output : 0 0 0 0 0 If we do not use static keyword, the
variable count, is reinitialized everytime when counter() function is called, and gets destroyed
each time when counter() functions ends. But, if we make it static, once initialized count will
have a scope till the end of main() function and it will carry its value through function calls too.
If you don\'t initialize a static variable, they are by default initialized to zero. Static class Objects
Static keyword works in the same way for class objects too. Objects declared static are allocated
storage in static storage area, and have scope till the end of program. Static objects are also
initialized using constructors like other normal objects. Assignment to zero, on using static
keyword is only for primitive datatypes, not for user defined datatypes. class Abc { int i; public:
Abc() { i=0; cout << \"constructor\"; } ~Abc() { cout << \"destructor\"; } }; void f() { static Abc
obj; } int main() { int x=0; if(x==0) { f(); } cout << \"END\"; } Output : constructor END
destructor You must be thinking, why was destructor not called upon the end of the scope of if
condition. This is because object was static, which has scope till the program lifetime, hence
destructor for this object was called when main() exits. Static data member in class Static data
members of class are those members which are shared by all the objects. Static data member has
a single piece of storage, and is not available as separate copy with each object, like other non-
static data members. Static member variables (data members) are not initialied using constructor,
because these are not dependent on object initialization. Also, it must be initialized explicitly,
always outside the class. If not initialized, Linker will give error. class X { static int i; public:
X(){}; }; int X::i=1; int main() { X obj; cout << obj.i; // prints value of i } Once the definition for
static data member is made, user cannot redefine it. Though, arithmetic operations can be
performed on it. Static Member Functions These functions work for the .
C++ Object oriented concepts & programmingnirajmandaliya
This document discusses various C++ concepts related to functions and operators. It defines what a default pointer is and how it receives addresses passed to a called function. It also discusses reference variables, inline functions, friend functions, default arguments, passing objects as parameters, function overloading, static members, function pointers, and operator overloading. It provides examples and explanations for each concept.
The document discusses various concepts related to classes in C++. It defines scope resolution operator as used to access static data members of a class. It differentiates between local and global classes and objects. It describes how to declare and access arrays of objects, pass objects as function arguments, return objects from functions, and allocate memory for classes and objects. It also explains inline functions, friend functions, constant member functions, and static member functions.
This document provides an overview of wound healing, its functions, stages, mechanisms, factors affecting it, and complications.
A wound is a break in the integrity of the skin or tissues, which may be associated with disruption of the structure and function.
Healing is the body’s response to injury in an attempt to restore normal structure and functions.
Healing can occur in two ways: Regeneration and Repair
There are 4 phases of wound healing: hemostasis, inflammation, proliferation, and remodeling. This document also describes the mechanism of wound healing. Factors that affect healing include infection, uncontrolled diabetes, poor nutrition, age, anemia, the presence of foreign bodies, etc.
Complications of wound healing like infection, hyperpigmentation of scar, contractures, and keloid formation.
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumMJDuyan
(𝐓𝐋𝐄 𝟏𝟎𝟎) (𝐋𝐞𝐬𝐬𝐨𝐧 𝟏)-𝐏𝐫𝐞𝐥𝐢𝐦𝐬
𝐃𝐢𝐬𝐜𝐮𝐬𝐬 𝐭𝐡𝐞 𝐄𝐏𝐏 𝐂𝐮𝐫𝐫𝐢𝐜𝐮𝐥𝐮𝐦 𝐢𝐧 𝐭𝐡𝐞 𝐏𝐡𝐢𝐥𝐢𝐩𝐩𝐢𝐧𝐞𝐬:
- Understand the goals and objectives of the Edukasyong Pantahanan at Pangkabuhayan (EPP) curriculum, recognizing its importance in fostering practical life skills and values among students. Students will also be able to identify the key components and subjects covered, such as agriculture, home economics, industrial arts, and information and communication technology.
𝐄𝐱𝐩𝐥𝐚𝐢𝐧 𝐭𝐡𝐞 𝐍𝐚𝐭𝐮𝐫𝐞 𝐚𝐧𝐝 𝐒𝐜𝐨𝐩𝐞 𝐨𝐟 𝐚𝐧 𝐄𝐧𝐭𝐫𝐞𝐩𝐫𝐞𝐧𝐞𝐮𝐫:
-Define entrepreneurship, distinguishing it from general business activities by emphasizing its focus on innovation, risk-taking, and value creation. Students will describe the characteristics and traits of successful entrepreneurs, including their roles and responsibilities, and discuss the broader economic and social impacts of entrepreneurial activities on both local and global scales.
The chapter Lifelines of National Economy in Class 10 Geography focuses on the various modes of transportation and communication that play a vital role in the economic development of a country. These lifelines are crucial for the movement of goods, services, and people, thereby connecting different regions and promoting economic activities.
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...PECB
Denis is a dynamic and results-driven Chief Information Officer (CIO) with a distinguished career spanning information systems analysis and technical project management. With a proven track record of spearheading the design and delivery of cutting-edge Information Management solutions, he has consistently elevated business operations, streamlined reporting functions, and maximized process efficiency.
Certified as an ISO/IEC 27001: Information Security Management Systems (ISMS) Lead Implementer, Data Protection Officer, and Cyber Risks Analyst, Denis brings a heightened focus on data security, privacy, and cyber resilience to every endeavor.
His expertise extends across a diverse spectrum of reporting, database, and web development applications, underpinned by an exceptional grasp of data storage and virtualization technologies. His proficiency in application testing, database administration, and data cleansing ensures seamless execution of complex projects.
What sets Denis apart is his comprehensive understanding of Business and Systems Analysis technologies, honed through involvement in all phases of the Software Development Lifecycle (SDLC). From meticulous requirements gathering to precise analysis, innovative design, rigorous development, thorough testing, and successful implementation, he has consistently delivered exceptional results.
Throughout his career, he has taken on multifaceted roles, from leading technical project management teams to owning solutions that drive operational excellence. His conscientious and proactive approach is unwavering, whether he is working independently or collaboratively within a team. His ability to connect with colleagues on a personal level underscores his commitment to fostering a harmonious and productive workplace environment.
Date: May 29, 2024
Tags: Information Security, ISO/IEC 27001, ISO/IEC 42001, Artificial Intelligence, GDPR
-------------------------------------------------------------------------------
Find out more about ISO training and certification services
Training: ISO/IEC 27001 Information Security Management System - EN | PECB
ISO/IEC 42001 Artificial Intelligence Management System - EN | PECB
General Data Protection Regulation (GDPR) - Training Courses - EN | PECB
Webinars: https://pecb.com/webinars
Article: https://pecb.com/article
-------------------------------------------------------------------------------
For more information about PECB:
Website: https://pecb.com/
LinkedIn: https://www.linkedin.com/company/pecb/
Facebook: https://www.facebook.com/PECBInternational/
Slideshare: http://www.slideshare.net/PECBCERTIFICATION
How to Make a Field Mandatory in Odoo 17Celine George
In Odoo, making a field required can be done through both Python code and XML views. When you set the required attribute to True in Python code, it makes the field required across all views where it's used. Conversely, when you set the required attribute in XML views, it makes the field required only in the context of that particular view.
Chapter wise All Notes of First year Basic Civil Engineering.pptxDenish Jangid
Chapter wise All Notes of First year Basic Civil Engineering
Syllabus
Chapter-1
Introduction to objective, scope and outcome the subject
Chapter 2
Introduction: Scope and Specialization of Civil Engineering, Role of civil Engineer in Society, Impact of infrastructural development on economy of country.
Chapter 3
Surveying: Object Principles & Types of Surveying; Site Plans, Plans & Maps; Scales & Unit of different Measurements.
Linear Measurements: Instruments used. Linear Measurement by Tape, Ranging out Survey Lines and overcoming Obstructions; Measurements on sloping ground; Tape corrections, conventional symbols. Angular Measurements: Instruments used; Introduction to Compass Surveying, Bearings and Longitude & Latitude of a Line, Introduction to total station.
Levelling: Instrument used Object of levelling, Methods of levelling in brief, and Contour maps.
Chapter 4
Buildings: Selection of site for Buildings, Layout of Building Plan, Types of buildings, Plinth area, carpet area, floor space index, Introduction to building byelaws, concept of sun light & ventilation. Components of Buildings & their functions, Basic concept of R.C.C., Introduction to types of foundation
Chapter 5
Transportation: Introduction to Transportation Engineering; Traffic and Road Safety: Types and Characteristics of Various Modes of Transportation; Various Road Traffic Signs, Causes of Accidents and Road Safety Measures.
Chapter 6
Environmental Engineering: Environmental Pollution, Environmental Acts and Regulations, Functional Concepts of Ecology, Basics of Species, Biodiversity, Ecosystem, Hydrological Cycle; Chemical Cycles: Carbon, Nitrogen & Phosphorus; Energy Flow in Ecosystems.
Water Pollution: Water Quality standards, Introduction to Treatment & Disposal of Waste Water. Reuse and Saving of Water, Rain Water Harvesting. Solid Waste Management: Classification of Solid Waste, Collection, Transportation and Disposal of Solid. Recycling of Solid Waste: Energy Recovery, Sanitary Landfill, On-Site Sanitation. Air & Noise Pollution: Primary and Secondary air pollutants, Harmful effects of Air Pollution, Control of Air Pollution. . Noise Pollution Harmful Effects of noise pollution, control of noise pollution, Global warming & Climate Change, Ozone depletion, Greenhouse effect
Text Books:
1. Palancharmy, Basic Civil Engineering, McGraw Hill publishers.
2. Satheesh Gopi, Basic Civil Engineering, Pearson Publishers.
3. Ketki Rangwala Dalal, Essentials of Civil Engineering, Charotar Publishing House.
4. BCP, Surveying volume 1
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxEduSkills OECD
Iván Bornacelly, Policy Analyst at the OECD Centre for Skills, OECD, presents at the webinar 'Tackling job market gaps with a skills-first approach' on 12 June 2024
1. Unit-VI
Static class members
this pointer
friend functions and classes
Dynamic memory management with operators
new and delete.
Overloading-functions.
overloading -Operator overloading
restrictions on operator overloading.
overloading unary and binary operators.
type conversion.
Templates.
Inheritance.
2. Static class members
In some situations, we need to have one or more data which are
accessible to all objects of the class.
Syntax
class classname
{
static data_type data member;
………
};
data_type classname:: data member=initial values;
Note:- static data members should be declared inside the class and it
should defined out side the class.
Initialization
is optional
3. Characteristics of static data members:
The variable which is declared as static is initialized to zero when the first
object of its class is created. No other initialization is possible.
static data members should be declared inside the class and it should
defined out side the class.
The static data members could be initialized during their definition out side
all the member functions.
Only one copy of that member is created for the entire class and is shared
by all the objects of that class, no matter how many objects are created
It is visible only within the class, but its lifetime is the entire program.
Public static data members accessed through scope resolution operator or
through objects.
• Class test
{
public:
static int a;
private:
static int b;
};
.
Void main()
{
test:: a=12;
test::b=19;// wrong
test t;
t.a=18;
t.b=90;// wrong
}
4. #include<iostream>
class item
{
static int count;
int number;
public:
void getdata(int a)
{
number=a;
count++;
}
void getcount(void)
{
cout<<"count:"<<count;
}
};
int item :: count;
int main()
{
item x,y,z;
x.getcount();->0
y.getcount();->0
z.getcount();->0
x.getdata(100);
y.getdata(200);
z.getdata(300);
x.getcount();->3
y.getcount();->3
z.getcount();->3
getch();
return 0;}
Ommit this
statement would
get linker error
5. • Note:- the scope and type of the static variable is defined
separately outside of the class. This is necessary because the
static data members are stored separately rather than as a part
of object.
Object1
number
Object2
number
Object3
number
100
3
300200
count
Common to all three objects
6. #include<iostream.h>
#include<conio.h>
class SE{
public:
int i;
static int
count;
};
int SE::count;
void main(){
SE s1,s2,s3;
clrscr();
s1.i=10;
s2.i=20;
s3.i=30;
s1.count=100;
s2.count=200;
s3.count=300;
cout<<s1.i<<" "<<s2.i<<" "<<s3.i<<"n";
cout<<s1.count<<" "<<s2.count<<"
"<<s3.count;
getch();
}
Example program for Static Class Variable
Output:
10 20 30
300 300 300
30
S3
i
20
S2
i
10
S1
i
300
count
(Common to all three objects)
7. Static member function
How to declare a static member function in a class.
Syntax
static return_type functionname(arglist);
ex static void displaly();
Characteristics of static member function:
• A static function can have access to only other static members (data or functions)
declared in the same class.
• Class test
{
static int a;
int b;
public:
static void display()
{
cout<<“a=“<<a;// correct
cout<<“b=“<<b;// wrong- since static member function can access to static
members.
};
• Non static data cannot be access to the static member functions.
• A static member function can be called using the class name (instead of its objects)
as follows
class-name :: function-name;
8. #include<iostream>
class test
{
int x;
static int count;
public:
void setdata(void)
{
x=++count;
}
void showdata(void)
{
cout<<"object number:"<<x<<"n";
}
static void showcount(void)
{
cout<<"count:"<<count<<"n";
}
};
int test :: count;
int main()
{
test t1,t2;
t1. setdata();
t2.setdata();
test :: showcount();
test t3;
t3.setdata();
test ::showcount();
t1.showdata();1
t2.showdata();2
t3.showdata();3
return 0;
}
9. “this” Pointer
Within a member function, the this keyword is a pointer to the current object, i.e.
the object through which the function was called.
The this pointer is a constant pointer.
Every object has access to its own address through a pointer called this.
A static member function does not have a this pointer.
this pointer can be used inside the member functions only.
Member functions use the this pointer implicitly or explicitly
Implicitly when accessing members directly
Explicitly when using keyword this
10. this pointer
Example program
#include<iostream>
class test
{
private:
int a;
public:
void setdata(int x)
{
a=x;// normal way to set data
cout<<“address of my bject”<<this;
this->a=x;// another way to set data
}
void showdata()
{
cout<<“n address of object for
showdata()”<<this;
cout<<“a=“<<a;
cout<<“ this->a”<<this->a;
}
void main()
{
test t,s;
t.setdata(30);
t.showdata();
s.setdata(40);
s.showdata();
}
The member function of a
class always with the pointer
called this, which points to the
object with which the function
is invoked.
11. friend functions and classes
Private and protected members of a class cannot be accessible to out side
the class. The non member functions cannot have an access to these data of
a class.
When two classes need to access the same function- make such function to
be friend to both the classes.
Allow the function to have access to the private members of these two
classes.
Such a function need not be member function of any of these classes.
Friend functions
• Allow the non-member function to access even the private members of a
class using the friend function or friend classes.
• Friend functions are used to access private members of a class
• syntax
class classname
{
…..
…..
public:
friend returntype functionname(object arg);
};
12. Characteristics of friend function
1. Function declaration is preceded by the keyword friend.
2. Its not a member function of the class. However, access to private
members of a class.
3. The scope of the friend is not limited to the class in which it has been
declared.
4. Since it is not in the scope of the class, It cannot be invoked using the
object of that class.
5. Invoked like a normal function.
6. It can be declared either in the public or the private part of a class.
7. It takes object as an argument.
8. Unlike the member functions, it cannot access the class members directly.
However, it can use the object and dot operator with each member name
to access both the private and public data.
9. The function is defined any where in the program
10. Function definition need not required any scope resolution operator.
13. Example on friend function
Class xyz;// advanced class declaration
class abc
{
private:
int a;
public:
void setdata(int x)
{
a=x; }
friend int add( abc ab,xyz xy);
};
Class xyz
{
private:
int b;
public:
void setdata(int y)
{
b=y; }
friend int add( abc ab,xyz xy);
};
int add( abc ab, xyz xy)
{
return ab.a+xy.b;
}// a and b are private
int main()
{
abc ab;
xyz xy;
ab.setdata(10);
xy.setdata(20);
cout<<“sum of the two no=“ <<add(ab,xy);
return 0;
}
14. Friend class
• Whenever all the functions of one class can have access to the private
members of the another class.
• It is possible to make the entire class as a friend of another class. So that all
the members of the friend class can have access to the private members of
the another class.
Syntax
class A
{
……..
………………..
friend class B;
};
Class B
{
………
……….
}
15. Example on friend class
class ABC
{
private:
int a,b;
public:
ABC(int x,int y)
{
a=x;
b=y;
}
// make a class XYZ as friend class
to ABC
friend class XYZ;
};
class XYZ{
public:
void display( ABC ab){
cout<<“n a in ABC class=“<<ab.a;
cout<<“n b in ABC class=“<<ab.b;
}
};
void main()
{
ABC ab(10,20);
XYZ xy;//object of XYZ
xy.display(ab);
}
Display is function of friend class so
that pass class object as argument
16. Dynamic memory management operators new and delete
Dynamic memory allocation- the requested memory allocated during run time of the
program
Dynamic memory allocation used when the amount of memory required is not
known in advance.
In c, we have used malloc() and calloc() functions and free() for de allocating the
memory.
In c++, we can use two unary operators like new and delete.
They perform allocating and freeing the memory. They are also called free store
operators.
An object can be created using the new and destroyed using the delete.
New operator
New operator allocates the memory dynamically similar to the standard library function malloc().
general form
pointer variable=new datatype;
Pointer variable is a pointer of type data type
- new operator allocates sufficient memory to hold an object of type
data type and return the address of the object.
17. New operator
• An object is created using new, and destroyed by using delete, as and when
required.
• Any object created with the new within a block, will remain exist until it is
destroyed by using the delete operator.
• Hence, the life time of object is under the control of programmer.
- If requested memory is not available in the memory pool, new operator
returns null pointer. Example
• int *p;//declaration
• p=new int;// initialization
Delete operator
• Object created with new is no longer needed, it must be destroyed with the
operator delete to release the memory for the reuse.
• general form
delete pointer_variable;
delete p;
delete q;
18. -Example
int *p;//declaration
p=new int;// initialization
float *q;
q=new float;
We can also combine the declaration and assignment like-
int *p=new int;
float *q= new float;
We can initialize the memory using new operator
int *p= new int(30);
float *q=new float(10.5);
New can be used to create a memory dynamically for any data type like arrays, classes
General form is
Pointer- variable= new data_type[size];
Ex- int *p= new int[10];
19. Example on new and delete
• #include<iostream>
using namespace std;
int main()
{
char *name;
name=new char[];
cout<<“enter the name”;
cin>>name;
cout<<name;
delete [ ] name;
return 0;
}
20. Create objects using new
class ABC
{
int a,b;
public:
ABC(int x,int y)
{
a=x;
b=y;
}
void display()
{
cout<<"n a value is="<<a;
cout<<"n b value
is="<<b;
}
};//class
int main()
{
ABC *ab=new ABC(10,20);
ab->display();
delete ab;
return 0;
}//main
21. Lab programs- 24/05/2014
• Write a C++ program with class that prints all real solutions to the quadratic equation
ax2+bx+c=0. Read in a, b, c and use the quadratic formula. If the descremainant b2-4ac is
negative, display a message stating that there are no real solutions.
2. A Fibonacci sequence is defined as follows: the first and second terms in the sequence are 0
and Subsequent terms are found by adding the preceding two terms in the sequence. Write a
C++ program with class to generate the first n terms of the sequence.
3. Write a C++ with class program that checks whether a given string is palindrome or not.
4. Write a C++ program which implements all types of constructors.
5. Write a C++ program which implements class defined outside the class using scope resolution
operator.
6. Write a C++ program which implements static class members.
7. Write a C++ program which uses this pointer
8. Write a C++ program which implements friend function.
22. Compile-time polymorphism
Binding of a function call to the function definition at compile time is called
compile-time polymorphism.
This is also called static binding or early binding.
Function overloading and operator overloading comes under compile-time
polymorphism.
Function overloading
Function overloading- The process of two or more functions having same
name and different in their signature( no. of arguments, type of arguments).
However, the overloading function differ only in their return type is not
allowed.
Use of function overloading
Function overloading is one of the most powerful features of C++ programming
language. It forms the basis of polymorphism (compile-time polymorphism).
Most of the time you’ll be overloading the constructor of a class.
23. • Swapping of two numbers
void swap_float(float a, float b)
{
float temp;
temp=a;
a=b;
b=temp;
}
void swap_int(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;
}
Function overloading
Void swap(int a,int b);
Void swap(float a,float b);
Void swap(char a,char b);
void add();
void add(int a);
void add(int a, int b);
int add(int a,int b);
last two functions are not overloading
24. Overloading Functions that differ in terms of no of
arguments
#include<iostream.h>
//FUNTION PROTOTYPES
int func(int i);
int func(int i, int j);
int main()
{
cout<<func(10);//func(int i)is called
cout<<func(10,10);//func(int i, int j) is called
return 0;
}
int func(int i)
{ return i;
}
int func(int i, int j)
{
return i+j;
}
25. • Overloading Functions that differ in terms of TYPE OF
arguments
#include<iostream.h>
int func(int i);
double func(double i);
void main()
{
cout<<func(10);//func(int i)is called
cout<<func(10.201);//func(double i) is called
}
int func(int i)
{
return i;
}
double func(double i)
{
return i;
}
26. • include<iostream.h>
int func(int i);
double func(int i);
int main()
{
cout<<func(10);
cout<<func(10.201);
return 0;
}
int func(int i)
{
return i;
}
double func(int i)
{
return i;
}
This program wont work because you cant
over load the functions if they are differ only
in terms of data type they return.
Write a c++ program to calculate area of circle,
rectangle, square using function overloading.?
27. Operator overloading
a1 = a2 + a3;
The above operation is valid, as you know if a1, a2
and a3 are variable of in-built Data Types(int, float,
double etc). But what if those are, say objects of a
Class; is the operation valid?
Yes, it is, if you overload the ‘+’ Operator in the
class, to which a1, a2 and a3 belong.
Operator overloading gives the special meaning to the
operators such as +, -, *, /,etc. with respect to the
class objects.
Using operator overloading we can extend the
capability of an operator to operate on the class
objects.
28. • Operators are overloaded by creating operator functions either
as a member or as a Friend Function of a class.
• declare using the following general form:
Return_type operator operator_symbol (arg-list);
Here, the Return_ type is commonly name of the class itself or any
datatype
Operator is a keyword
Operator symbol can be replaced by the any valid operator such as +, -,
*, <, etc.
-> it could be invoked as
objectname.operator#(arg_list); or #objectname;
ex- o1.operator+(a,b); or +o1;
• The following operators cannot be overloaded.
1. class member access operators(.,.*)
2. scope resolution operator.(::)
3. sizeof() operator.
4. conditional operator- :?
29. Restrictions on operator overloading
• The following are over loadable operators
1. arithmetic- +,-,*,/,%
2. bit- wise- &,|, ~,^
3. logical - &&,||, !
4. relational- >,<,==,<=
5. assignment - =
6. arithmetic assignment- +=,-=,*=
7. shift- <<, >>
8. unary- ++, --
9. subscripting- [ ]
10. function call- ()
11. dereferencing- ->
12. unary sign prefix- +, -
13. Allocate and free- new, delete.
30. C++ operators that can be overloaded:
C++ Operators that cannot be overloaded:
Operators that can be overloaded
+ - * / % ^ & |
~ ! = < > += -= *=
/= %= ^= &= |= << >> >>=
<<= == != <= >= && || ++
-- ->* , -> [] () new delete
new[] delete[]
Operators that cannot be overloaded
. .* :: ?: sizeof
31. Overloading unary operator(++,--)
class ABC
{
private:
int index;
public:
ABC( )
{
index=0;
}
int getindex()
{
return index;
}
void operator ++()
{
index= index+1;
}
};
void main()
{
ABC a1, a2;
cout<<“index=“<<a1.getindex;
cout<<“index=“<<a2.getindex;
++a1;// same as a1.operator++();
cout<<“index=“<<a1.getindex;
++a2;// same as a2.operator++();
cout<<“index=“<<a1.getindex;
}
Operators which are used to operate on
single operand called unary operators.
32. Binary Operator Overloading
Binary operator takes two operands.
Binary operators are + , -, *, etc.,
For example a plus operator takes two operands (a + b).
Syntax: return-type class-name :: operator (arglist)
{
//function body
}
In binary operator overloading, function takes one parameter.
The binary overloaded operator function takes the first object as an
implicit operand and the second operand must be passed explicitly.
The data members of the first object are accessed without using the dot
operator whereas, the second argument members can be accessed using
the dot operator if the argument is an object.
33. Overloading binary operator
Class test
{
int sub1, sub2;
public:
test (int x, int y)
{
sub1=x;sub2=y;
} // notice the declaration
test operator +(test);
void show()
{
cout<<sub1<<endl<<sub2;
}
};
test test :: operator +(test ob)
{
test temp;
temp.sub1=sub1+ob.sub1;
temp.sub2= sub2+ob.sub2;
return temp;
}
void main()
{
test t1(80,70);
test t2(90,75);
test t3=t1+t2;// t3=t1.operator+(t2);
t3.show();
}//main
36. Type conversion
• Converting one data type to another data type is called type conversion.
• Ex:- int a;
float b=3.14;
a=b;
cout<<“n a=“<<a;
a= 3
• What happens when they are user defined data types?
• a1=a2+a3;// a1,a2,a3 are objects of the same class.
There are three un compatible types
1. Conversion from basic data type to class type.
2. Conversion from class type to basic data type.
3. Conversion from one class type to another class type.
37. 1. Conversion from basic data type to class type
• To convert data from a basic type to a user defined type (class type), the
conversion function should be defined in the class in the form of
constructor.
• Constructor with one argument.
• This constructor function takes a single argument of basic data type(int,
float,double).
• In the constructor function write steps for converting basic to object type.
2. Conversion from class type to basic data type.
• In this case, define a operator function in the class is called conversion
function.
• Operator function is defined as an overloaded basic data- type which takes
no arguments.
• It converts object to basic types and returns a basic data item.
• Syntax-
operator basic data type()
{
// steps to convert
}
38. class temperature
{
float celsius;
public:
temperature()
{
celsius=0.0;
}
temperature(float fahrenheit)
{
// fahrenheit to celsius
celsius=(fahrenheit-32)*5/9;
}
operator float()
{
float f;
// celsius to fahrenheit
f=((celsius*9/5)+32);
return f;
}
void gettemp()
{
cout<<"n enter the temparature celsius";
cin>>celsius;
}
void showtemp()
{
cout<<"n temperature in celsius="<<celsius;
}
};
void main()
{
temperature t1,t2;
float fa;
cout<<"enter the temparature in farhenheitn";
cin>>fa;
t1=fa;// invokes constructor with argument
t1.showtemp();
float ce;
t2.gettemp();
ce=t2; // invokes the operator function
cout<<"n temparature in farhenheit"<<ce;
}//main
Temparature conversion
39. • Note – in previous program we called the constructor with one argument
using the statement t1=fa;
• In this case the compiler first searches for the overloaded assignment
operator function, if it is not found, it invokes the one- argument
constructor.
• ce=t2;- same as the ce= float(t2); or ce= (float)t2;
3. Conversion from one class type to another class type.
• There is a situation where we need to convert one class type to another
class type.
• Example-
ab=xy;
where ab is an object of class ABC and xy is an object of class XYZ.
• XYZ is called source class and ABC are called destination class.
40. • For this type conversion also we can use any of the conversions methods
like constructor with one argument and operator conversion function.
• Choice of these two methods depends on the whether the conversion
function should be used in source class or destination class.
• In source class implement the operator conversion function.
• In destination class define the constructor with one argument.
Conversion function in source class: operator function
• General form
class ABC//destination class
{ ………members of class ABC
………
};
class XYZ // source class
{
public:
operator ABC()
{
}
};
Name of destination class.
Conversion operator function
41. Convert Fahrenheit to Celsius
class celsius
{
float cels;
public:
celsius()
{
cels=0.0;
}
celsius(float farh)
{
cels=farh;
}
void show()
{
cout<<"n celsius="<<cels;
}
};
class farhenheit
{
float f;
public:
farhenheit()
{
f=0.0;
}
operator celsius()
{
return (celsius((f-32)*5/9));
}
void gettemp()
{
cout<<"n enter the temparature";
cin>>f;
}
};
void main()
{
celsius c1;
farhenheit f1;
clrscr();
f1.gettemp();
// uses the operator
function in source
class farhenheit
c1=f1;
c1.show();
getch();
}//main
42. Conversion function in destination
class: constructor function
• Class ABC// destination class
{
public:
ABC(XYZ xy)
{
……..
………
}
};
Class XYZ// source class
(
………
……….
};
Object of the source class.
43. templates-
whenever a function is defined it works only on particular data
type.
Ex-
void swap(char a,char b)
{ char t;
t=a;
a=b;
b=t;}
void swap( int a, int b)
{int t;
t=a;
a=b;
b=t;}
Void swap( float a,float b)
{int t;
t=a;
a=b;
b=t;}
void main()
{
char ch1=X,ch2=Y;
swap(ch1,ch2);
int x=10,y=20;
swap(x,y);
float p=10.5, q=20.7;
Swap(p,q);
}
Above program we have redefined the function
for each and every data type.
44. templates
Templates is most recently added feature in c++.
Another way of achieving reusability in oops is templates.
Templates acts as a macros.
It allows to develop the reusable software components like
functions and classes etc.
Templates are used to support the generic programming
(works on different data types).
Templates are used to create a family of classes and functions.
They works on different data types.
Take add(), if u make this function as template function it
works on all data types such as adding int, float, and double.
Templates are defined for both classes and functions.
1. function template
2. class template
45. 1.Function templates.
• We need to designed a single piece of function which works on
all the data types.
• Syntax
template < class T,……>
return type function_name ( arglist)
{
//body of the function
}
The function template is similar to normal function except variables that it uses
whose data types are not known until a call to it is made.
call to template is similar to the normal function and parameters can be of any type.
when the compiler encounters a call to such functions, it identifies the data type of
the parameters and creates a function internally and makes call to it.
46. #include<iostream.h>
template < class T>
void swap(T a,T b)
{
T t;
t=a;
a=b;
b=t;
}
Void main()
{
char ch1,ch2;
cout<<n enter two characters”
cin>>ch1>>ch2;
swap(ch1,ch2);
int x,y;
cout<<“enter two integers”;
cin>>x>>,y;
swap(x,y);
}//main
When compiler encounters
swap(ch1,ch2); it internally
creates a function of type
swap(char a, char b);
Write a c++ program to implement
bubble sort using the templates.
47. Function with two generic type.
#include<iostream.h>
#include<conio.h>
#include<string.h>
template<class X,class Y>
void display(X a,Y b)
{
cout<<"n a="<<a;
cout<<"n b="<<b;
}
void main()
{
clrscr();
display(oo1,”IT”);
display(89.9,”1strank”);
getch(); }
48. 2. Class templates
• Classes can also be operate on different data types.
such classes are called template classes.
Class test
{
int a;
int b;
public:
test(int x,int y)
{
a=x;
b=y;
}
void display()
{
cout<<a<<b;
}
};
void main()
{
test t(10,20);
t.display();
}
49. Void main()
{
test<int , float>t1(10,20.5);
test<char,float>t2(“hai”,23.8);
t1.show();
t2.show();
}
Syntax:-
template<class T1,class T2…..>
class class_name
{//data members of generic types T1, T2, . . .
//functions with arguments of type T1, T2, . .
…….
};
#include<iostream.h.
Template<class T1,class
T2>
class test
{
T1 a;
T2 b;
public:
test(T1 x, T2 y)
{
a=x;
b=y;
}
void show()
{
cout<<a<<b;
}
};
Once you have created a generic class, you create an
object of that class using the following general form:
class-name <char, int> obj;
50. Inheritance
The mechanism of deriving a new class from an existing class is known as
inheritance.
It is the technique of organizing the information in hierarchical form .
Inheritance allows new classes to be built from older classes instead of being
rewritten from scratch.
Existing class is known as base class or parent class or super class and new class
is known as derived class or child class or sub class.
In inheritance base class members are inherited to derived class and also new
members can be added to derived class.
Inheritance supports the reusability mechanism.
A
B
C
D
Base class
A
B
C
D
E
Derived class
51. C ++, not only supports the access specifiers private and public,
but also an important access specifiers protected, which is
significant in class inheritance.
A class can use all the three visibility modes as illustrated below.
class class_name
{
private: //visible to member functions within its class
. . . . //but not in derived class
protected: //visible to member functions within its class
. . . . //and its derived class
public: //visible to member functions within its class,
. . . . //derived classes and through object
};
52. Syntax of derived class declaration
class derived_classname:[visibility mode] base_classname
{
//members of derived class
//and they can access members of the base class
};
The derivation of derived class from the base class is indicated by the colon
(:).
The default visibility mode is private.
Visibility mode specifies whether the features of the base class are privately or
protected or publicly inherited.
53. The following are the four possible styles of derivation:
1. class D : private B //private derivation
{
//members of D
};
2. class D : protected B //protected derivation
{
//members of D
};
3. class D : public B //public derivation
{
//members of D
};
4. class D : B //private derivation by default
{
//members of D
};
54. Privately inherited
1. public members of base class become private to derived class. Therefore the
public members of the base class can only be accessed by the members of the
derived class. They are inaccessible to the even objects of the derived class.
2. Private members of the base class cannot be inherited to the derived class.
3. Protected members of the base class also become private to the derived class. they
can have access to the member functions of the derived class and further
inheritance is possible.
Publicly inherited.
1. Private members of the base class cannot be inherited.
2. Public members of the base class become public to derived class.
3. Protected members of the base class become protected to derived class.
Therefore they are accessible to the member functions of the derived
class. And also further inheritance is possible.
protected mode.
1. Public and protected members of the base class become protected to the
derived class
2. Private members cannot be inherithed.
55. Derived class visibilityBase class
Publicly privately protected
Private-> Not inherited Not inherited Not inherited
Protected-> protected private protected
Public->
public private protected
Visibility of inherited members
57. Single Inheritance
-A class is derived from only one base class. single inheritance.
base class:
class A
{
//members of A
}
Derived class syntax:
class B: public A
{
//members of B
};
A
B
58. Single inheritance- publicly
class B
{
int a;
public:
int b;
void getdata();
int get_a();
void show_a();
};
class D:public B
{
int c;
public:
void mul();
void display();
};
Void B:: getdata()
{
a=5;
b=10;
}
int B:: get_a()
{
return a;
}
void B:: show_a()
{
cout<<“a=“<<a<<“n”;
}
void D::mul()
{
c= b*get_a();
}
void D:: display()
{
cout<<“a=“<<get_a();
cout<<“b=“<<b;
Cout<<“c=“<<c;
}
Int main()
{
D d;
d.getdata();
d.mul();
d.show_a();
d.display();
d.b=20;
d.mul();
d.display();
Return 0;
}//main
59. Privately inherited Single
inheritance
class B
{
int a;
public:
int b;
void getdata();
int get_a();
void show_a();
};
class D: B
{
int c;
public:
void mul();
void display();
};
Void B:: getdata()
{
cout<<“enter a and bn”;
cin>>a>>b;
}
int B:: get_a()
{
return a;
}
void B:: show_a()
{
cout<<“a=“<<a<<“n”;
}
void D::mul()
{
c= b*get_a();
}
void D:: display()
{
show_a();
cout<<“b=“<<b;
Cout<<“c=“<<c;
}
Int main()
{
D d;
d.getdata();
d.mul();
d.show_a();//wrong
d.display();
d.b=20;// wrong
d.mul();
d.display();
Return 0;
}//main
60. Multilevel Inheritance
- A class is derived from the base class, in turn derived class
become base class to other class is called multilevel
inheritance.
A
B
C
father
son
Grand
father
61. class A
{
//members of A
};
Derived class syntax:
Class B: public A
{
//members of B
};
Derived class syntax:
Class C: public B
{
//members of C
};
62. class student
{
protected:
int roll_no;
public:
void get_no(int)’
void put_no();
};//student
void student:: get_no(int a)
{
roll_no=a;
}
void student:; put_no()
{
cout<<“n roll number=“<<
roll_no<<“n”;
class test : public student
{
protected:
float sub1;
float sub2;
public:
void get_marks(float,float);
void put_marks();
};
Void test:: get_marks(float x,float y)
{
sub1=x;
sub2=y;
}
void test :: put_marks()
{
cout<<“n marks in sub1=:<<sub1;
cout<<“n marks in sub2=<<sub2;
}
class result: public test
{
float total;
public:
void display();
};
void result::display()
{
total= sub1+ sub2;
put_no();
put_marks();
cout<<“n total=“<<total;
}
int main()
{
result student1;
student1.
get_no(001);
student1.
get_marks(65,90);
student1.display();
return 0;
}
63. Multiple Inheritance
- A class is derived from more than one base class is called
multiple inheritance.
A B
C
Example
child
motherfather
64. class A
{
//members of A
};
class B
{
//members of B
};
Derived class syntax:
class c: public A, public B
{
//members of c
----
};
65. class X
{
public:
void display()
{
cout<<“n class X”;
}
};
class Y
{
public:
void display()
{
cout<<“n class Y”;
}
};
class Z: public X,public Y
{
public:
void display()
{
X:: display();
}
};
Int main()
{
Z z;
z.display();
or z.X::display();
z Y:: display();
return 0;
}
Note:- ambiguity resolution in multiple inheritance
same function name is used in more than one
base class ambiguity occurs which is to be execute
- Use scope resolution operator.
66. Hierarchical Inheritance
-two or more classes are derived from a single base class is
called hierarchical inheritance.
A
B C
SNIST
IT CSE ECM
67. class A
{
//members of A
};
Derived class syntax:
class B: public A
{
//members of B
};
Derived class syntax:
class C: public A
{
//members of C
};
68. Hybrid Inheritance
-Derivation of a class involving more than one form of
inheritance is known as hybrid inheritance.
-Hybrid inheritance involves more than one form of
inheritance namely multilevel and multiple.
A
B C
D
1. Multilevel inheritance.
2. Multiple inheritance.
70. Class result: public test,public sports
{
float total;
public:
void display();
};
void result:: display()
{
total= part1+part2+score;
put_no();
putmarks();
put_score();
cout<< total score”<<total<<“n”;
}
int main()
{
result student1;
student1.getno(001);
Student1.getmarks(78.6,80.6);
student1.getscore(6.0);
student1.display();
return 0;
}//main
71. Order of constructor execution
- As long as no base class constructor takes any arguments, the derived class need
not have any constructor function. However, if any base class contains a
constructor with one or more arguments, then it is mandatory for the derived class
to have a constructor and pass appropriate arguments to the base class constructor.
- In inheritance we create objects for the derived class. So that derived class should
pass arguments to the base class constructor. When both the classes uses the
constructors, the constructor in base is executed first and then the constructor in the
derived class is executed later.
- In case of multiple inheritance, the base classes are constructed in the order in
which they appeared in the declaration of derived class.
- similarly in multilevel inheritance they are executed in the order of inheritance.
72. Class A
{
int x;
Public:
A(int i)
{
x=i;
}
void show_x()
{
cout<<?n x=“<<x;
}
};
class B
{
int y;
Public:
B(int j)
{y=j;
cout<<“ny=“<<y;
}
Void show_y()
{
cout<<“y=“<<y;
}
};
Class D:public B,public A
{
int m,n;
public:
D(int a,int b,int c,int d):
B(a),A(b)
{
m=c;
n=d;
}
void show_mn()
{
cout<<“m=“<<m<<“n”;
cout<<“n=“<<n<<“n”;
}
};
int main()
{
D d(5,6,7,8);
d.show_x();
d.show_y();
d. show_mn()
Return 0;
}//main
73. Order of invocation of constructors
• Method of inheritance order of execution
1. class D:public B B()
{ D()
};
2. class D:public B1,public B2 B1()
{ B2()
}; D()
3. Class D: public B1,virtual B2 B2()
{ B1()
}; D()
4. Classs D1:public B B()
{ D1()
};
class D2: public D1 D2()
{
};
74. 74
Constructors and Inheritance
C++ Construction Order:
1. Base class data members are constructed in order of
declaration.
2. Base class constructor is called.
3. Derived class data members are constructed in order.
4. Derived class constructor is executed.
Destructor order (reverse of constructor order):
1. Derived class destructor is executed.
2. Derived class data members are destroyed.
3. The base class destructor is called.
4. Base class data members are destroyed.