Inheritance allows a derived class to inherit attributes and behaviors from a base class. A derived class inherits all public and protected members of the base class. Inheritance establishes an "is-a" relationship between classes. Polymorphism allows derived classes to override virtual functions from the base class and have them called dynamically at runtime based on the actual object type. Abstract base classes define pure virtual functions that derived classes must implement. Multiple inheritance allows a class to inherit from more than one base class.
The document discusses inheritance, polymorphism, and virtual functions in C++. It defines inheritance as a way to create a new class from an existing class, with the new class being a specialized version of the existing class. Polymorphism allows objects to take on multiple forms, and is enabled through the use of virtual functions. Virtual functions allow dynamic binding at runtime so that the proper overridden function is called for a derived class object. The document provides examples of inheritance hierarchies, class access specifiers, base class pointers, abstract base classes, and multiple inheritance.
The document discusses inheritance, polymorphism, and virtual functions in C++. It defines inheritance as a way to create a new class from an existing class, with the new class being a specialized version of the existing class. Polymorphism allows objects to take on multiple forms, and is enabled through the use of virtual functions. Virtual functions allow dynamic binding at runtime so that the proper overridden function is called for a derived class object. The document provides examples of inheritance hierarchies, class access specifiers, constructors and destructors, redefining vs overriding functions, abstract base classes, and multiple inheritance.
This document discusses inheritance in object oriented programming. It covers key concepts of inheritance including derived classes inheriting behavior and attributes from base classes to promote code reuse. Specific topics covered include is-a relationships between classes, access control of inherited members, continuous inheritance where derived classes can act as base classes, and examples of inheritance hierarchies.
This document discusses object-oriented programming (OOP) concepts like classes, objects, inheritance, encapsulation, abstraction, and polymorphism in C++. It provides examples of how each concept is implemented in C++. It explains that classes are user-defined data types that contain data fields and methods. Objects are instances of classes. Inheritance allows classes to inherit attributes from other classes. Encapsulation binds data to the methods that operate on it. Abstraction hides unnecessary details and displays only essential information. Polymorphism allows one message to have multiple implementations.
Inheritance allows new classes to be created from existing classes. This allows code reuse and establishes an is-a relationship between classes. There are different types of inheritance including single, multilevel, multiple and abstract inheritance. When inheriting from a base class, the derived class gains access to properties and methods of the base class. Constructors are called from base to derived during object instantiation. Methods can be overridden in derived classes to change behavior. Multiple inheritance introduces ambiguity that must be resolved using scope resolution.
The document provides an introduction to object-oriented programming (OOP) concepts in C++ including objects, classes, abstraction, encapsulation, inheritance, polymorphism, constructors, destructors, and exception handling. It defines each concept and provides examples of how it is implemented in C++ code. For instance, it explains that a class is a user-defined data type that holds its own data members and member functions, and provides an example class declaration. It also discusses polymorphism and provides examples demonstrating method overloading and overriding.
Inheritance allows reuse of properties and behaviors of an existing class when creating new classes. The existing class is called the base/parent class, while the new class is the derived/child class. The child class inherits all properties and behaviors of the parent class and can define additional properties and behaviors of its own. There are different types of inheritance like single, multilevel, multiple and hierarchical inheritance which define how properties and behaviors are inherited between parent and child classes.
Inheritance allows one class to acquire the properties and behaviors of another class, known as the base or parent class, allowing code reuse and extension of existing classes without modification. There are different types of inheritance like simple, multilevel, and multiple inheritance that build upon the base class in various ways. Inheritance provides benefits like code reuse, extension of existing classes, and ability to override methods of the base class in the derived class.
Inheritance allows new classes called derived classes to be created from existing classes called base classes. Derived classes inherit all features of the base class and can add new features. There are different types of inheritance including single, multilevel, multiple, hierarchical, and hybrid. A derived class can access public and protected members of the base class but not private members. Constructors and destructors of the base class are executed before and after those of the derived class respectively.
The document discusses inheritance in C++. It explains that inheritance allows a derived class to inherit features from a base class, including data members and member functions. This avoids duplicating code and makes programs more organized and reusable. The document provides an example where different types of game characters inherit from a base Person class to share common abilities like walking and talking, while adding their own unique skills.
Access Specifiers
Derived Classes
Type of Inheritance
Derived class Constructors (Constructors in single Inheritance)
Multiple Inheritance
Constructors in multiple Inheritance
Constructors in single/multiple Inheritance with arguments.
Inheritance is the second most important feature of OOP.
In inheritance, the code of existing classes is used for making new classes.
This saves time for writing and debugging the entire code for a new class.
To inherit means to receive.
In inheritance a new class is written such that it can access or use the members of an existing class.
The new class that can access the members of an existing class is called the derived class or child class. The existing class is called the base class or parent class.
Abbasajmal
03149958500
This document provides an overview of object-oriented programming (OOP) concepts. It defines OOP as a programming technique that uses objects and classes. Key concepts discussed include classes and objects, inheritance, data abstraction, encapsulation, and polymorphism. Benefits of OOP include reusability, extensibility, understandability and security. Inheritance allows reuse of existing classes, and can be single, multiple, public, protected or private. Data abstraction hides background details and provides essential information. Encapsulation binds data and functions that manipulate the data. Polymorphism enables different object types to respond to the same function name.
Inheritance allows one class to inherit properties from another parent class. This creates a hierarchy where child classes inherit behavior from the parent class and can add or override behavior. There are three types of access specifiers that determine whether inherited members are public, private, or protected. Virtual functions allow runtime polymorphism by overriding functions in derived classes. Pure virtual functions define an interface that derived classes must implement.
Inheritance allows one class to inherit properties and behaviors from another parent class. This creates a hierarchical relationship between classes and allows code reuse. There are three types of access specifiers that determine whether inherited members from the parent class are public, private, or protected in the child class. Virtual functions allow runtime polymorphism by overriding functions in derived classes. Pure virtual functions define an interface for derived classes by requiring them to implement the function.
A class that contains a pure virtual function is called an abstract base class and cannot be instantiated. It serves as an interface that defines common behavior for derived classes to implement. The document provides examples of an area abstract base class with a pure virtual getarea() function, and rectangle and triangle derived classes that override getarea() and provide class-specific implementations.
Inheritance allows classes to inherit attributes and behaviors from other classes. In C++, a derived class inherits from a base class. The derived class inherits all public and protected members of the base class and can add its own data members and member functions. Constructors and destructors are not inherited by the derived class, so they must be defined separately. When a derived class object is instantiated, the base class constructor is called first to initialize the base portion, followed by the derived portion.
Inheritance allows classes to inherit attributes and behaviors from other classes. In C++, a derived class inherits from a base class. The derived class inherits all public and protected members of the base class and can add additional members or override inherited members. Constructors and destructors are not inherited, so derived classes must define their own. When a derived class object is instantiated, the base class constructor is called first to initialize the base portion, followed by the derived portion.
Inheritance allows one class to inherit properties from another base class, creating a hierarchy from general to specific classes. Derived classes inherit all public and protected members of the base class and can add new, class-specific features. This allows for code reuse and reduces time/effort. Access specifiers like public, private, and protected determine which members are inherited. Constructors and destructors execute in order of derivation, with base constructors first and destructors last. Virtual functions support runtime polymorphism by allowing overriding in derived classes. Pure virtual functions define an interface without implementation.
This document provides an overview of object-oriented programming concepts, including objects, classes, data abstraction and encapsulation, inheritance, and polymorphism. It defines key terms like class, object, inheritance and polymorphism. For example, it states that a class is a blueprint for creating objects, and that inheritance allows code reuse by extending a parent class. The document also gives examples and different types of each concept to help explain them at a high level.
This document provides an overview of inheritance in object-oriented programming. It defines inheritance as a concept that allows one class to inherit properties from another parent or base class. This provides code reusability and reduces development costs. Examples of inheritance from a Four Wheeler base class to subclasses like Car are provided. The document also discusses access specifiers, inheritance modes, types of inheritance like single, multiple and multilevel inheritance, and the order of constructor and destructor calls in inheritance.
The document discusses inheritance in object-oriented programming. It defines inheritance as a class deriving from an existing class, allowing the derived class to access members of the base class. It describes three types of inheritance: public, private, and protected. It provides examples of single and multiple inheritance, and discusses how constructors are handled in derived classes.
First Review PPT gfinal gyft ftu liu yrfut goSowndarya6
ย
CyberShieldX provides end-to-end security solutions, including vulnerability assessment, penetration testing, and real-time threat detection for business websites. It ensures that organizations can identify and mitigate security risks before exploitation.
Unlike traditional security tools, CyberShieldX integrates AI models to automate vulnerability detection, minimize false positives, and enhance threat intelligence. This reduces manual effort and improves security accuracy.
Many small and medium businesses lack dedicated cybersecurity teams. CyberShieldX provides an easy-to-use platform with AI-powered insights to assist non-experts in securing their websites.
Traditional enterprise security solutions are often expensive. CyberShieldX, as a SaaS platform, offers cost-effective security solutions with flexible pricing for businesses of all sizes.
Businesses must comply with security regulations, and failure to do so can result in fines or data breaches. CyberShieldX helps organizations meet compliance requirements efficiently.
Inheritance allows new classes to be created from existing classes. This allows code reuse and establishes an is-a relationship between classes. There are different types of inheritance including single, multilevel, multiple and abstract inheritance. When inheriting from a base class, the derived class gains access to properties and methods of the base class. Constructors are called from base to derived during object instantiation. Methods can be overridden in derived classes to change behavior. Multiple inheritance introduces ambiguity that must be resolved using scope resolution.
The document provides an introduction to object-oriented programming (OOP) concepts in C++ including objects, classes, abstraction, encapsulation, inheritance, polymorphism, constructors, destructors, and exception handling. It defines each concept and provides examples of how it is implemented in C++ code. For instance, it explains that a class is a user-defined data type that holds its own data members and member functions, and provides an example class declaration. It also discusses polymorphism and provides examples demonstrating method overloading and overriding.
Inheritance allows reuse of properties and behaviors of an existing class when creating new classes. The existing class is called the base/parent class, while the new class is the derived/child class. The child class inherits all properties and behaviors of the parent class and can define additional properties and behaviors of its own. There are different types of inheritance like single, multilevel, multiple and hierarchical inheritance which define how properties and behaviors are inherited between parent and child classes.
Inheritance allows one class to acquire the properties and behaviors of another class, known as the base or parent class, allowing code reuse and extension of existing classes without modification. There are different types of inheritance like simple, multilevel, and multiple inheritance that build upon the base class in various ways. Inheritance provides benefits like code reuse, extension of existing classes, and ability to override methods of the base class in the derived class.
Inheritance allows new classes called derived classes to be created from existing classes called base classes. Derived classes inherit all features of the base class and can add new features. There are different types of inheritance including single, multilevel, multiple, hierarchical, and hybrid. A derived class can access public and protected members of the base class but not private members. Constructors and destructors of the base class are executed before and after those of the derived class respectively.
The document discusses inheritance in C++. It explains that inheritance allows a derived class to inherit features from a base class, including data members and member functions. This avoids duplicating code and makes programs more organized and reusable. The document provides an example where different types of game characters inherit from a base Person class to share common abilities like walking and talking, while adding their own unique skills.
Access Specifiers
Derived Classes
Type of Inheritance
Derived class Constructors (Constructors in single Inheritance)
Multiple Inheritance
Constructors in multiple Inheritance
Constructors in single/multiple Inheritance with arguments.
Inheritance is the second most important feature of OOP.
In inheritance, the code of existing classes is used for making new classes.
This saves time for writing and debugging the entire code for a new class.
To inherit means to receive.
In inheritance a new class is written such that it can access or use the members of an existing class.
The new class that can access the members of an existing class is called the derived class or child class. The existing class is called the base class or parent class.
Abbasajmal
03149958500
This document provides an overview of object-oriented programming (OOP) concepts. It defines OOP as a programming technique that uses objects and classes. Key concepts discussed include classes and objects, inheritance, data abstraction, encapsulation, and polymorphism. Benefits of OOP include reusability, extensibility, understandability and security. Inheritance allows reuse of existing classes, and can be single, multiple, public, protected or private. Data abstraction hides background details and provides essential information. Encapsulation binds data and functions that manipulate the data. Polymorphism enables different object types to respond to the same function name.
Inheritance allows one class to inherit properties from another parent class. This creates a hierarchy where child classes inherit behavior from the parent class and can add or override behavior. There are three types of access specifiers that determine whether inherited members are public, private, or protected. Virtual functions allow runtime polymorphism by overriding functions in derived classes. Pure virtual functions define an interface that derived classes must implement.
Inheritance allows one class to inherit properties and behaviors from another parent class. This creates a hierarchical relationship between classes and allows code reuse. There are three types of access specifiers that determine whether inherited members from the parent class are public, private, or protected in the child class. Virtual functions allow runtime polymorphism by overriding functions in derived classes. Pure virtual functions define an interface for derived classes by requiring them to implement the function.
A class that contains a pure virtual function is called an abstract base class and cannot be instantiated. It serves as an interface that defines common behavior for derived classes to implement. The document provides examples of an area abstract base class with a pure virtual getarea() function, and rectangle and triangle derived classes that override getarea() and provide class-specific implementations.
Inheritance allows classes to inherit attributes and behaviors from other classes. In C++, a derived class inherits from a base class. The derived class inherits all public and protected members of the base class and can add its own data members and member functions. Constructors and destructors are not inherited by the derived class, so they must be defined separately. When a derived class object is instantiated, the base class constructor is called first to initialize the base portion, followed by the derived portion.
Inheritance allows classes to inherit attributes and behaviors from other classes. In C++, a derived class inherits from a base class. The derived class inherits all public and protected members of the base class and can add additional members or override inherited members. Constructors and destructors are not inherited, so derived classes must define their own. When a derived class object is instantiated, the base class constructor is called first to initialize the base portion, followed by the derived portion.
Inheritance allows one class to inherit properties from another base class, creating a hierarchy from general to specific classes. Derived classes inherit all public and protected members of the base class and can add new, class-specific features. This allows for code reuse and reduces time/effort. Access specifiers like public, private, and protected determine which members are inherited. Constructors and destructors execute in order of derivation, with base constructors first and destructors last. Virtual functions support runtime polymorphism by allowing overriding in derived classes. Pure virtual functions define an interface without implementation.
This document provides an overview of object-oriented programming concepts, including objects, classes, data abstraction and encapsulation, inheritance, and polymorphism. It defines key terms like class, object, inheritance and polymorphism. For example, it states that a class is a blueprint for creating objects, and that inheritance allows code reuse by extending a parent class. The document also gives examples and different types of each concept to help explain them at a high level.
This document provides an overview of inheritance in object-oriented programming. It defines inheritance as a concept that allows one class to inherit properties from another parent or base class. This provides code reusability and reduces development costs. Examples of inheritance from a Four Wheeler base class to subclasses like Car are provided. The document also discusses access specifiers, inheritance modes, types of inheritance like single, multiple and multilevel inheritance, and the order of constructor and destructor calls in inheritance.
The document discusses inheritance in object-oriented programming. It defines inheritance as a class deriving from an existing class, allowing the derived class to access members of the base class. It describes three types of inheritance: public, private, and protected. It provides examples of single and multiple inheritance, and discusses how constructors are handled in derived classes.
First Review PPT gfinal gyft ftu liu yrfut goSowndarya6
ย
CyberShieldX provides end-to-end security solutions, including vulnerability assessment, penetration testing, and real-time threat detection for business websites. It ensures that organizations can identify and mitigate security risks before exploitation.
Unlike traditional security tools, CyberShieldX integrates AI models to automate vulnerability detection, minimize false positives, and enhance threat intelligence. This reduces manual effort and improves security accuracy.
Many small and medium businesses lack dedicated cybersecurity teams. CyberShieldX provides an easy-to-use platform with AI-powered insights to assist non-experts in securing their websites.
Traditional enterprise security solutions are often expensive. CyberShieldX, as a SaaS platform, offers cost-effective security solutions with flexible pricing for businesses of all sizes.
Businesses must comply with security regulations, and failure to do so can result in fines or data breaches. CyberShieldX helps organizations meet compliance requirements efficiently.
A substation at an airport is a vital infrastructure component that ensures reliable and efficient power distribution for all airport operations. It acts as a crucial link, converting high-voltage electricity from the main grid to the lower voltages needed for various airport facilities. This essay will explore the functions, components, and importance of a substation at an airport.
Functions of an Airport Substation:
Voltage Conversion:
Substations step down high-voltage electricity to lower levels suitable for airport operations, like terminal buildings, runways, and other facilities.
Power Distribution:
They distribute electricity to various loads, including lighting, air conditioning, navigation systems, and ground support equipment.
Grid Stability:
Substations help maintain the stability of the power grid by controlling voltage levels and managing power flows.
Redundancy and Reliability:
Airports often have redundant substations or interconnected systems to ensure uninterrupted power supply, even in case of a fault.
Switching and Control:
Substations provide switching capabilities to connect or disconnect circuits, enabling maintenance and power management.
Protection:
Substations incorporate protective devices, like circuit breakers and relays, to safeguard the power system from faults and ensure safe operation.
Key Components of an Airport Substation:
Transformers: These convert high-voltage electricity to lower voltage levels.
Circuit Breakers: These devices switch circuits on or off, protecting the system from faults.
Busbars: These are large, conductive bars that distribute electricity from transformers to other equipment.
Switchgear: This includes equipment that controls the flow of electricity, such as isolators and switches.
Control and Protection Systems: These systems monitor the substation's performance, detect faults, and automatically initiate corrective actions.
Capacitors: These improve the power factor and reduce losses in the system.
Importance of Airport Substations:
Reliable Power Supply:
Substations are essential for providing reliable power to critical airport functions, ensuring safety and efficiency.
Safe and Efficient Operations:
They contribute to the safe and efficient operation of runways, terminals, and other airport facilities.
Airport Infrastructure:
Substations are an integral part of the airport's infrastructure, enabling various operations and services.
Economic Impact:
Substations support the economic activities of the airport, including passenger and cargo handling.
Modernization and Sustainability:
Modern substations incorporate advanced technologies and systems to improve efficiency, reduce energy consumption, and enhance sustainability.
In conclusion, an airport substation is a crucial component of airport infrastructure, ensuring reliable and efficient power distribution, grid stability, and safe operations.
This study will provide the audience with an understanding of the capabilities of soft tools such as Artificial Neural Networks (ANN), Support Vector Regression (SVR), Model Trees (MT), and Multi-Gene Genetic Programming (MGGP) as a statistical downscaling tool. Many projects are underway around the world to downscale the data from Global Climate Models (GCM). The majority of the statistical tools have a lengthy downscaling pipeline to follow. To improve its accuracy, the GCM data is re-gridded according to the grid points of the observed data, standardized, and, sometimes, bias-removal is required. The current work suggests that future precipitation can be predicted by using precipitation data from the nearest four grid points as input to soft tools and observed precipitation as output. This research aims to estimate precipitation trends in the near future (2021-2050), using 5 GCMs, for Pune, in the state of Maharashtra, India. The findings indicate that each one of the soft tools can model the precipitation with excellent accuracy as compared to the traditional method of Distribution Based Scaling (DBS). The results show that ANN models appear to give the best results, followed by MT, then MGGP, and finally SVR. This work is one of a kind in that it provides insights into the changing monsoon season in Pune. The anticipated average precipitation levels depict a rise of 300โ500% in January, along with increases of 200-300% in February and March, and a 100-150% increase for April and December. In contrast, rainfall appears to be decreasing by 20-30% between June and September.
11th International Conference on Data Mining (DaMi 2025)kjim477n
ย
Welcome To DAMI 2025
Submit Your Research Articles...!!!
11th International Conference on Data Mining (DaMi 2025)
July 26 ~ 27, 2025, London, United Kingdom
Submission Deadline : June 07, 2025
Paper Submission : https://csit2025.org/submission/index.php
Contact Us : Here's where you can reach us : [email protected] or [email protected]
For more details visit : Webpage : https://csit2025.org/dami/index
David Boutry - Mentors Junior DevelopersDavid Boutry
ย
David Boutry is a Senior Software Engineer in New York with expertise in high-performance data processing and cloud technologies like AWS and Kubernetes. With over eight years in the field, he has led projects that improved system scalability and reduced processing times by 40%. He actively mentors aspiring developers and holds certifications in AWS, Scrum, and Azure.
1. Concept Of Object Oriented
Programming
oop is an approach or a Programming pattern where the programs are
structured around objects rather than functions and logic. It makes the
data partitioned into two memory areas, i.e., data and functions, and
helps make the code flexible and modular.
Object-oriented programming mainly focuses on objects that are
required to be manipulated. In OOPs, it can represent data as objects
that have attributes and functions.
2. Basic Object-Oriented
Programming
๏ฑ Object-An O Object can be defined as an entity that has a state and
behavior, or in other words, anything that exists physically in the
world is called an object. It can represent a dog, a person, a table,
etc. An object means the combination of data and programs, which
further represent an entity.
๏ฑ Classes-Class can be defined as a blueprint of the object. It is basically
a collection of objects which act as building blocks.
๏ฑ
Abstraction- Abstraction helps in the data hiding process. It helps in
displaying the essential features without showing the details or the
functionality to the user. It avoids unnecessary information or
irrelevant details and shows only that specific part which the user
wants to see.
3. Basic Object-Oriented Programming
๏ฑ Encapsulation- The wrapping up of data and functions together in a single unit is
known as encapsulation. It can be achieved by making the data members' scope
private and the member functionโs scope public to access these data members.
Encapsulation makes the data non-accessible to the outside world.
๏ฑ Inheritance- Inheritance is the process in which two classes have an is-a relationship
among each other and objects of one class acquire properties and features of the
other class. The class which inherits the features is known as the child class, and the
class whose features it inherited is called the parent class. For example, Class Vehicle is
the parent class, and Class Bus, Car, and Bike are child classes.
๏ฑ Polymorphism- It means many forms. It is the ability to take more than one form. It is
a feature that provides a function or an operator with more than one definition. It can
be implemented using function overloading, operator overload, function overriding,
virtual function.
5. Advantages of OOPs
There are various advantages of object-oriented programming.
๏ฑ OOPs provide reusability to the code and extend the use of existing
classes.
๏ฑ In OOPs, it is easy to maintain code as there are classes and objects,
which helps in making it easy to maintain rather than restructuring.
๏ฑ It also helps in data hiding, keeping the data and information safe
from leaking or getting exposed.
๏ฑ Object-oriented programming is easy to implement.
7. What Is Inheritance?
โข Provides a way to create a new class from an
existing class
โข The new class is a specialized version of the
existing class
9. The "is a" Relationship
โข Inheritance establishes an "is a"
relationship between classes.
โ A poodle is a dog
โ A car is a vehicle
โ A flower is a plant
โ A football player is an athlete
10. Inheritance โ Terminology and Notation in C+
+
โข Base class (or parent) โ inherited from
โข Derived class (or child) โ inherits from the base class
โข Notation:
class Student // base class
{
. . .
};
class UnderGrad : public student
{ // derived class
. . .
};
11. Back to the โis aโ Relationship
โข An object of a derived class 'is a(n)' object of
the base class
โข Example:
โ an UnderGrad is a Student
โ a Mammal is an Animal
โข A derived object has all of the characteristics
of the base class
12. What Does a Child Have?
An object of the derived class has:
โข all members defined in child class
โข all members declared in parent class
An object of the derived class can use:
โข all public members defined in child class
โข all public members defined in parent
class
13. Protected Members and Class
Access
โข protected member access
specification: like private, but
accessible by objects of derived class
โข Class access specification: determines
how private, protected, and
public members of base class are
inherited by the derived class
14. Class Access Specifiers
1) public โ object of derived class can be
treated as object of base class (not vice-versa)
2) protected โ more restrictive than
public, but allows derived classes to know
details of parents
3) private โ prevents objects of derived class
from being treated as objects of base class.
15. Inheritance vs. Access
private: x
protected: y
public: z
private: x
protected: y
public: z
private: x
protected: y
public: z
Base class members
x is inaccessible
private: y
private: z
x is inaccessible
protected: y
protected: z
x is inaccessible
protected: y
public: z
How inherited base class
members
appear in derived class
private
base class
protecte
d
base class
public
base class
16. Inheritance vs. Access
private members:
char letter;
float score;
void calcGrade();
public members:
void setScore(float);
float getScore();
char getLetter();
class Grade
private members:
int numQuestions;
float pointsEach;
int numMissed;
public members:
Test(int, int);
class Test : public Grade
When Test class inherits
from Grade class using
public class access, it
looks like this:
private members:
int numQuestions:
float pointsEach;
int numMissed;
public members:
Test(int, int);
void setScore(float);
float getScore();
char getLetter();
17. Inheritance vs. Access
private members:
char letter;
float score;
void calcGrade();
public members:
void setScore(float);
float getScore();
char getLetter();
class Grade
private members:
int numQuestions;
float pointsEach;
int numMissed;
public members:
Test(int, int);
When Test class inherits
from Grade class using
protected class access, it
looks like this:
private members:
int numQuestions:
float pointsEach;
int numMissed;
public members:
Test(int, int);
protected members:
void setScore(float);
float getScore();
float getLetter();
class Test : protected Grade
18. Inheritance vs. Access
private members:
int numQuestions:
float pointsEach;
int numMissed;
void setScore(float);
float getScore();
float getLetter();
public members:
Test(int, int);
private members:
char letter;
float score;
void calcGrade();
public members:
void setScore(float);
float getScore();
char getLetter();
class Grade
private members:
int numQuestions;
float pointsEach;
int numMissed;
public members:
Test(int, int);
When Test class inherits
from Grade class using
private class access, it
looks like this:
class Test : private Grade
19. Constructors and Destructors in Base and
Derived Classes
โข Derived classes can have their own
constructors and destructors
โข When an object of a derived class is created,
the base classโs constructor is executed first,
followed by the derived classโs constructor
โข When an object of a derived class is
destroyed, its destructor is called first, then
that of the base class
23. Passing Arguments to
Base Class Constructor
โข Allows selection between multiple base class
constructors
โข Specify arguments to base constructor on
derived constructor heading:
Square::Square(int side) :
Rectangle(side,
side)
โข Can also be done with inline constructors
โข Must be done if base class has no default
constructor
24. Passing Arguments to
Base Class Constructor
Square::Square(int side):Rectangle(side,side)
derived class constructor base class constructor
derived constructor
parameter
base constructor
parameters
25. Redefining Base Class Functions
โข Redefining function: function in a derived class
that has the same name and parameter list as
a function in the base class
โข Typically used to replace a function in base
class with different actions in derived class
26. Redefining Base Class Functions
โข Not the same as overloading โ with
overloading, parameter lists must be different
โข Objects of base class use base class version of
function; objects of derived class use derived
class version of function
30. Problem with Redefining
โข Consider this situation:
โ Class BaseClass defines functions x() and y().
x() calls y().
โ Class DerivedClass inherits from BaseClass and
redefines function y().
โ An object D of class DerivedClass is created and
function x() is called.
โ When x() is called, which y() is used, the one
defined in BaseClass or the the redefined one in
DerivedClass?
31. Problem with Redefining
BaseClass
DerivedClass
void X();
void Y();
void Y();
DerivedClass D;
D.X();
Object D invokes function X()
In BaseClass. Function X()
invokes function Y() in BaseClass, not
function Y() in DerivedClass,
because function calls are bound at
compile time. This is static binding.
34. Polymorphism and Virtual Member Functions
โข Virtual member function: function in base class that
expects to be redefined in derived class
โข Function defined with key word virtual:
virtual void Y() {...}
โข Supports dynamic binding: functions bound at run
time to function that they call
โข Without virtual member functions, C++ uses static
(compile time) binding
35. Polymorphism and Virtual Member Functions
Because the parameter in the displayGrade function is a GradedActivity
reference variable, it can reference any object that is derived from
GradedActivity. That means we can pass a GradedActivity object, a
FinalExam object, a PassFailExam object, or any other object that is
derived from GradedActivity.
A problem occurs in Program 15-10 however...
37. As you can see from the example output, the getLetterGrade member
function returned โCโ instead of โPโ. This is because the GradedActivity
classโs getLetterGrade function was executed instead of the
PassFailActivity classโs version of the function.
38. Static Binding
โข Program 15-10 displays 'C' instead of 'P'
because the call to the getLetterGrade
function is statically bound (at compile time)
with the GradedActivity class's version of the
function.
We can remedy this by making the function
virtual.
39. Virtual Functions
โข A virtual function is dynamically bound to calls
at runtime.
At runtime, C++ determines the type of object
making the call, and binds the function to the
appropriate version of the function.
40. Virtual Functions
โข To make a function virtual, place the virtual
key word before the return type in the base
class's declaration:
virtual char getLetterGrade() const;
โข The compiler will not bind the function to
calls. Instead, the program will bind them at
runtime.
41. Updated Version of GradedActivity
The function
is now
virtual.
The function also becomes
virtual in all derived classes
automatically!
42. Polymorphism
If we recompile our program with the updated versions of
the classes, we will get the right output, shown here:
(See Program 15-11 in the book.)
This type of behavior is known as polymorphism. The term
polymorphism means the ability to take many forms.
Program 15-12 demonstrates polymorphism by passing
objects of the GradedActivity and PassFailExam classes to
the displayGrade function.
45. Polymorphism Requires References or
Pointers
โข Polymorphic behavior is only possible when an
object is referenced by a reference variable or
a pointer, as demonstrated in the
displayGrade function.
46. Base Class Pointers
โข Can define a pointer to a base class object
โข Can assign it the address of a derived class
object
47. Base Class Pointers
โข Base class pointers and references only know about
members of the base class
โ So, you canโt use a base class pointer to call a derived class
function
โข Redefined functions in derived class will be ignored
unless base class declares the function virtual
48. Redefining vs. Overriding
โข In C++, redefined functions are statically
bound and overridden functions are
dynamically bound.
So, a virtual function is overridden, and a
non-virtual function is redefined.
49. Virtual Destructors
โข It's a good idea to make destructors
virtual if the class could ever become a
base class.
โข Otherwise, the compiler will perform
static binding on the destructor if the
class ever is derived from.
โข See Program 15-14 for an example
50. Abstract Base Classes and Pure Virtual
Functions
โข Pure virtual function: a virtual member
function that must be overridden in a derived
class that has objects
โข Abstract base class contains at least one pure
virtual function:
virtual void Y() = 0;
โข The = 0 indicates a pure virtual function
โข Must have no function definition in the base
class
51. Abstract Base Classes and Pure Virtual
Functions
โข Abstract base class: class that can have no
objects. Serves as a basis for derived classes
that may/will have objects
โข A class becomes an abstract base class when
one or more of its member functions is a pure
virtual function
52. Multiple Inheritance
โข A derived class can have more than one base
class
โข Each base class can have its own access
specification in derived class's definition:
class cube : public square,
public rectSolid;
class
square
class
rectSolid
class
cube
53. Multiple Inheritance
โข Problem: what if base classes have member
variables/functions with the same name?
โข Solutions:
โ Derived class redefines the multiply-defined function
โ Derived class invokes member function in a particular
base class using scope resolution operator ::
โข Compiler errors occur if derived class uses base
class function without one of these solutions
54. TEMPLATES AND FILE OPERATIONS
Templates, Function templates, class Templates,
Overloading of Template Functions Member
function Templates,
File stream operations-
ostream,ifstream,fstream,File Access Modes
File position pointer โ fseek get,fseek put,ftell get,
ftell put, Sequential Input and Output operations
Random Access, Error handling during file
operation.
55. Templates in C++
โข It is a simple and powerful tool in C++
โข simple idea is to pass data type as a parameter so that
we donโt need to write the same code for different data
types.
โข Templates are often used in larger codebase for the
purpose of code reusability and flexibility of the
programs.
โข The concept of templates can be used in two different
ways:
โข Function Templates
โข Class Templates
How it works?
โข Templates are expanded at compiler
time. This is like macros.
โข Difference between Macro and
Template is compiler does type
checking before template expansion.
56. Function Templates
โข A function template works in a similar to a normal function,
with one key difference.
โข A single function template can work with different data
types at once but, a single normal function can only work
with one set of data types.
โข Normally, if you need to perform identical operations on two
or more types of data, you use function overloading to create
two functions with the required function declaration.
โข However, a better approach would be to use function
templates because you can perform the same task writing
less and maintainable code.
57. How to declare a function template?
A function template starts with the keyword template followed by
template parameter/s inside < > which is followed by function
declaration.
template <typename T>
T someFunction(T arg)
{
... .. ...
}
โข In the above code, T is a template argument that accepts different
data types (int, float), and class is a keyword.
โข You can also use keyword typename instead of class in the above
example.
โข When, an argument of a data type is passed to someFunction( ),
compiler generates a new version of someFunction() for the given
data type.
59. Class Templates
โข Like function templates, you can also create class templates
for generic class operations.
โข Sometimes, you need a class implementation that is same
for all classes, only the data types used are different.
โข Normally, you would need to create a different class for
each data type OR create different member variables and
functions within a single class.
โข This will unnecessarily bloat your code base and will be
hard to maintain, as a change is one class/function should
be performed on all classes/functions.
โข However, class templates make it easy to reuse the same
code for all data types.
60. How to declare a class
template?
template <class T>
class className
{ ... .. ...
public:
T var;
T someOperation(T arg);
... .. ...
};
โข In the above declaration, T is the template argument which is a
placeholder for the data type used.
โข Inside the class body, a member variable var and a member
function someOperation() are both of type T.
61. How to create a class template
object?
To create a class template object, you need to define the
data
type inside a < > when creation.
className<dataType> classObject;
For example:
className<int> classObject;
className<float> classObject;
className<string>
classObject;
62. Overloading of Template
Functions
โข You may overload a function template either by a non-
template function or by another function template.
โข If you call the name of an overloaded function template, the
compiler will try to deduce its template arguments and
check its explicitly declared template arguments. If
successful, it will instantiate a function template
specialization, then add this specialization to the set of
candidate functions used in overload resolution.
โข The compiler proceeds with overload resolution, choosing
the most appropriate function from the set of candidate
functions. Non-template functions take precedence over
template
63. Files - Introduction
โข Computer programs are associated to work with files as
it helps in storing data & information permanently.
โข File - itself a bunch of bytes stored on some storage
devices.
โข In C++ this is achieved through a component header file
called fstream.h
โข The I/O library manages two aspects- as interface
and for transfer of
data.
โข The library predefine a set of operations for all file
related handling through certain classes.
64. File Handling using File Streams in C++
File represents storage medium for storing data or information. Streams
refer to sequence of bytes. In Files we store data i.e. text or binary data
permanently and use these data to read or write in the form of input output
operations by transferring bytes of data. So we use the term File
Streams/File handling. We use the header file <fstream>
1.
2.
3.
ofstream: It represents output Stream and this is used for writing in
files.
ifstream: It represents input Stream and this is used for
reading
from files.
fstream: It represents both output Stream and input Stream. So it
can read from files and write to files.
Operations in File Handling:
Creating a file
Reading data
Writing new data
Closing a file
: open()
: read()
: write()
: close()
65. โข Streams act as an interface between files and programs.
โข They represent as a sequence of bytes and deals with the flow of
data.
โข Every stream is associated with a class having member functions
and operations for a particular kind of data flow.
โข File -> Program ( Input stream) - reads
โข Program ->File (Output stream) โ write
โข All designed into fstream.h and hence needs to be included in all
file handling programs.
โข To use the fstream library, include both the standard <iostream>
AND the <fstream> header file:
69. C++ File Pointers
Every file maintains two pointers called
โข get_pointer (in input mode file)
โข put_pointer (in output mode file)
which tells the current position in the file where reading or
writing will takes place respectively
A file pointer in this context is not like a C++ pointer but it
works like a book-mark in a book.
These pointers help attain random access in file. That means
moving directly to any location in the file instead of moving
through it sequentially.
70. Sequential Access Vs Random File Access
Sequential Access Random Access
In a sequential-access file, it is possible
to read and write information
sequentially, starting from the
beginning of the file.
A random-access data file enables you
to read or writeinformation anywhere
in the file.
To go from point A to point Z in a
sequential-access system, you must
pass through all intervening points.
In a random-access system, you can
jump directly to point Z.
Random access is sometimes called
direct access.
If information is accessed in the same
order, a sequential-access file is faster.
To access information randomly,
random access is better
71. Random Access Files
There may be situations where random access in the best choice.
For example, if you have to modify a value in record no 21, then using
random access techniques, you can place the file pointer at the beginning
of record 21 and then straight-way process the record.
If sequential access is used, then you'll have to unnecessarily go through
first twenty records in order to reach at record 21.
The seekg(), seekp(), tellg() and tellp() Functions
In C++, random access is achieved by manipulating seekg(),
seekp(), tellg() and tellp() functions.
The seekg() and tellg() functions allow you to set and examine the
get_pointer, and the seekp() and tellp() functions perform these
operations on the put_pointer.
The seekg() and tellg() functions are for input streams
(ifstream) and seekp() and tellp() functions are for output
streams (ofstream).
73. Error handling during file operation.
Error handling refers to the response and recovery procedures from
error conditions present in a software application. In other words, it
is the process comprised of anticipation, detection and resolution of
application errors, programming errors or communication errors.
It is possible that an error may occur during I/O operations on a file.
Typical error situations include:
1. Trying to read beyond the end-of-file mark.
2. Device overflow means no space in the disk for storing data.
3. Trying to use a file that has not been opened.
4. Trying to perform operation on a file, when the file is opened for
another type of operation.
5. Opening a file with an invalid filename.
6. Try to read a file with no data in it.
If we fail to check such read and write errors, a program may behave
abnormally when an error occurs. An unchecked error may result in
a premature termination of the program or incorrect output.
74. Function Meaning
int bad()
Returns a non-zero value if an invalid operation is attempted or
any unrecoverable error has occurred. However, if it is zero (false
value), it may be possible to recover from any other error reported
and continue operations.
int eof()
Returns non-zero (true value) if end-of-file is encountered while
reading; otherwise returns zero (false value).
int fail()
Returns non-zero (true) when an input or output operation has
failed.
int good()
Returns non-zero (true) if no error has occurred. This means, all
the above functions are false. For example, if fin.good() is true,
everything is okay with the stream named as fin and we can
proceed to perform I/O operations. When it returns zero, no
further operations can be carried out.
clear() Resets the error state so that further operations can be attempted.
Following table lists these error handling functions and their meaning :
75. EXCEPTION HANDLING AND STL
Exception handing mechanism, Throwing
mechanism catching mechanism, Rethrowing
an exception, C++ Standard Exception
Library, runtime error, logic failures, user
defined exceptions, Exception handling in
inheritance, specifying exceptions.
C++ standard STL.- Containers, Algorithms,
Iterators โ Standard function library
76. Exception in Programs
โข An exception is an event that occurs during the execution of a
program that disrupts the normal flow of instructions.
โข Many different kinds of errors can cause exceptions: problems
ranging from serious hardware errors, such as a hard disk
crash, to simple programming errors, such as trying to access
an out-of-bounds array element.
Exception in C++
โข A C++ exception is a response to an exceptional circumstance
that arises while a program is running, such as an attempt to
divide by zero.
โข Exceptions provide a way to transfer control from one part of a
program to another.
โข C++ exception handling is built upon three keywords: try,
catch, and throw.
77. Exception in C++ - Continued
1. throw โ A program throws an exception when a problem shows
up. This is done using a throw keyword.
2. catch โ A program catches an exception with an exception
handler at the place in a program where you want to handle the
problem. The catch keyword indicates the catching of an
exception.
3. try โ A try block identifies a block of code for which particular
exceptions will be activated. It's followed by one or more catch
blocks.
#include <stdexcept> // To use built in Exception Library
try
{ // protected code }
catch( ExceptionName e1 ) { // catch block }
catch( ExceptionName e2 ) { // catch block }
catch( ExceptionName eN ) { // catch block }
78. C++ Standard Exceptions
C++ provides a list of standard exceptions defined in <exception>
which we can use in our programs. These are arranged in a parent-
child class hierarchy shown below
79. Exception Programs
Runtime Errors & Logic Failures - Example
โข Divide by Zero Exception
โข Array Index Out of Bounds Exception
โข Overflow Error
Assignment - 1
Write a calculator program in C++ with necessary
exception handling mechanisms
80. Throwing mechanism & Catching mechanism
The exception handler is declared with the catch keyword
immediately after the closing brace of the try block. The syntax for
catch is similar to a regular function with one parameter. The type
of this parameter is very important, since the type of the argument
passed by the throw expression is checked against it, and only in the
case they match, the exception is caught by that handler.
Multiple handlers (i.e., catch expressions) can be chained; each one
with a different parameter type. Only the handler whose argument
type matches the type of the exception specified in the throw
statement is executed.
If an ellipsis (...) is used as the parameter of catch, that handler will
catch any exception no matter what the type of the exception
thrown. This can be used as a default handler that catches all
exceptions not caught by other handlers
81. C++ User-Defined Exceptions
The new exception can be defined by overriding and inheriting
exception class functionality.
#include <iostream>
#include <exception>
using namespace std;
//Creating a user defined exception class
class MyException : public exception{
public:
const char * what() const throw()
{
return "Attempted to divide by zero!n";
}
};
82. Rethrowing an exception
โข Rethrowing an expression from within an exception handler can
be done by calling throw, by itself, with no exception.
โข This causes current exception to be passed on to an outer
try/catch sequence.
โข An exception can only be rethrown from within a catch block.
โข When an exception is rethrown, it is propagated outward to the
next catch block.
void MyHandler()
{
try
{
throw "Hello";
}
catch (const char*)
{
cout <<"Caught exception inside MyHandlern";
throw; //rethrow char* out of function
}
83. Exception Handling in Inheritance
Exception Handling โ catching base and derived classes as exceptions:
If both base and derived classes are caught as exceptions then catch
block of derived class must appear before the base class.
If we put base class first then the derived class catch block will never
be reached. For example, following C++ code prints โCaught Base
Exceptionโ
In Java, catching a base class exception before derived is not allowed
by the compiler itself.
In C++, compiler might give warning about it, but compiles the
code.
84. #include<iostream>
using namespace std;
class Base {};
class Derived: public Base {};
int main()
{
Derived d;
// some other stuff
try {
// Some monitored code
throw d;
}
catch(Base b) {
cout<<"Caught Base Exception";
}
catch(Derived d) { //This catch block is NEVER executed
cout<<"Caught Derived Exception";
}
getchar();
return 0;
}
In this C++ code, if we change
the order of catch statements
then both catch statements
become reachable.
85. Exception specifications (throw, noexcept) (C++)
โข Exception specifications are a C++ language feature that
indicate the programmer's intent about the exception types that
can be propagated by a function.
โข You can specify that a function may or may not exit by an
exception by using an exception specification.
โข The compiler can use this information to optimize calls to the
function, and to terminate the program if an unexpected
exception escapes the function.
โข If exception handling is used in an application, there must be a
function in the call stack that handles thrown exceptions before
they exit the outer scope of a function marked noexcept,
noexcept(true), or throw()
โข Syntax
void MyFunction(int i) throw();
void MyFunction(int i) noexcept;
86. Assignment / Lab Excercise
Write a program that converts dates from numerical
month/day format to alphabetic month/day (for example,
1/31 or 01/31 corresponds to January 31).
You will define two exception classes, one called
MonthErrorand another called DayError.
If the user enters anything other than a legal month
number (integers from 1 to 12), then your program will
throw and catch a MonthError.
Similarly, if the user enters anything other than a valid
day number (integers from 1 to either 29, 30, or 31,
depending on the month), then your program will throw
and catch a DayError. To keep things simple, always allow
29 days for February.
88. Introduction to the Standard Template Library
The Standard Template Library, or STL, is a C++ library of
container classes, algorithms, and iterators; it provides many of the
basic algorithms and data structures of computer science.
The STL is a generic library, meaning that its components are
heavily parameterized: almost every component in the STL is a
template. You should make sure that you understand how
templates work in C++ before you use the STL.
The STL includes the classes vector, list, deque, set, multiset, map,
multimap, hash_set, hash_multiset, hash_map, and
hash_multimap. Each of these classes is a template, and can be
instantiated to contain any type of object
89. STL has four components
1. Algorithms
2. Containers
3. Functions
4. Iterators
90. Algorithms The header algorithm defines a collection of functions
especially designed to be used on ranges of elements.They act
on containers and provide means for various operations for the
contents of the containers.
Algorithm
Sorting
Searching
Important STL Algorithms
Useful Array algorithms
Partition Operations
Containers Containers or container classes store objects and data. There
are in total seven standard โfirst-classโ container classes and
three container adaptor classes and only seven header files that
provide access to these containers or container adaptors.
Refer to types of containers in slide 16
Functions The STL includes classes that overload the function call
operator. Instances of such classes are called function objects or
functors. Functors allow the working of the associated function
to be customized with the help of parameters to be passed.
91. Vector in C++ STL
โข Vectors are same as dynamic arrays with the ability to resize
itself automatically when an element is inserted or deleted,
with their storage being handled automatically by the
container.
โข Vector elements are placed in contiguous storage so that they
can be accessed and traversed using iterators. In vectors, data is
inserted at the end.
โข Inserting at the end takes differential time, as sometimes there
may be a need of extending the array.
โข Removing the last element takes only constant time because no
resizing happens.
โข Inserting and erasing at the beginning or in the middle is linear
in time.
92. Vector in C++ STL
Certain functions associated with the vector are:
Iterators
โข begin() โ Returns an iterator pointing to the first element in the vector
โข end() โ Returns an iterator pointing to the theoretical element that
follows the last element in the vector
โข rbegin() โ Returns a reverse iterator pointing to the last element in the
vector (reverse beginning). It moves from last to first element
โข rend() โ Returns a reverse iterator pointing to the theoretical element
preceding the first element in the vector (considered as reverse end)
โข cbegin() โ Returns a constant iterator pointing to the first element in
the vector.
โข cend() โ Returns a constant iterator pointing to the theoretical element
that follows the last element in the vector.
โข crbegin() โ Returns a constant reverse iterator pointing to the last
element in the vector (reverse beginning). It moves from last to first
element
โข crend() โ Returns a constant reverse iterator pointing to the theoretical
element preceding the first element in the vector (considered as reverse
end)
93. List in C++ STL
Lists are sequence containers that allow constant time insert and erase
operations anywhere within the sequence, and iteration in both directions.
List containers are implemented as doubly-linked lists; Doubly linked lists
can store each of the elements they contain in different and unrelated
storage locations. The ordering is kept internally by the association to each
element of a link to the element preceding it and a link to the element
following it.
They are very similar to forward_list: The main difference being that
forward_list objects are single-linked lists, and thus they can only be iterated
forwards, in exchange for being somewhat smaller and more efficient.
Compared to other base standard sequence containers (array, vector and
deque), lists perform generally better in inserting, extracting and moving
elements in any position within the container for which an iterator has
already been obtained, and therefore also in algorithms that make intensive
use of these, like sorting algorithms.
94. List in C++ - Sequence Containers
Some more useful functions are discussed in this article
1. emplace(position, value) :- This function is used to insert an element
at the position specified.
2. emplace_back(value) :- This function adds value at end of list.
3. emplace_front :- This function adds value at beginning of list
4. merge(list2) :- This function is used to merge list2 with list1. If both
the lists are in sorted order, then the resulting list is also sorted.
5. remove_if(condition) :- This function removes the element from list on
the basis of condition given in its argument
6. unique() :- This function is used to delete the repeated occurrences of
the number. List has to be sorted for this function to get executed.
7. splice(position, list2) :- This function is used to transfer elements from
one list into another.
8. swap(list2) :- This function is used to swap one list element with other.
95. Set in C++ STL
โข Sets are containers that store unique elements following a specific order.
In a set, the value of an element also identifies it (the value is itself the
key, of type T), and each value must be unique. The value of the
elements in a set cannot be modified once in the container (the elements
are always const), but they can be inserted or removed from the
container.
โข Internally, the elements in a set are always sorted following a specific
strict weak ordering criterion indicated by its internal comparison object
(of type Compare).
โข Set containers are generally slower than unordered_set containers to
access individual elements by their key, but they allow the direct
iteration on subsets based on their order.
โข Sets are typically implemented as binary search trees.
96. Set in C++ STL
Some basic functions associated with Set:
โข begin() โ Returns an iterator to the first element in the set.
โข end() โ Returns an iterator to the theoretical element that follows last element in
the set.
โข size() โ Returns the number of elements in the set.
โข max_size() โ Returns the maximum number of elements that the set can hold.
โข empty() โ Returns whether the set is empty.
โข count(const g) โ Returns 1 or 0 based on the element โgโ is present in the set or
not.
โข lower_bound(const g) โ Returns an iterator to the first element that is equivalent
to โgโ or definitely will not go before the element โgโ in the set.
โข upper_bound(const g) โ Returns an iterator to the first element that is
equivalent to โgโ or definitely will go after the element โgโ in the set.
โข equal_range()โ The function returns an iterator of pairs. (key_comp). The pair
refers to the range that includes all the elements in the container which have a
key equivalent to k.
โข emplace()โ This function is used to insert a new element into the set container,
only if the element to be inserted is unique and does not already exists in the set.