The document discusses object oriented programming concepts in C++, including objects and methods, relationships between objects, inheritance, and polymorphism. It provides examples of implementing a Matrix class with inheritance. A MatrixExt class is defined that inherits from Matrix and adds new methods like setIdentity() and an operator* for matrix multiplication. Objects of the MatrixExt class can be used wherever Matrix objects are expected, demonstrating polymorphism through inheritance.
This document provides class notes on object-oriented programming concepts like inheritance, packages, and interfaces. It covers topics like method overloading, objects as parameters, returning objects, static and nested classes, inheritance basics, method overriding, abstract classes, packages, and interfaces. The document is organized into sections on each topic with examples provided. It also includes indexes listing the topics covered and their importance levels. The material is intended to complement personalized learning materials and assessment tests for students.
This document discusses implementing multiple inheritance in C++. It begins with an example where a Terminal class needs to inherit from both a Task and Displayed class. It then provides background on multiple inheritance and how it allows combining independent concepts. The document outlines C++'s existing single inheritance implementation strategy before describing the author's approach to multiple inheritance, which preserves C++'s efficiency while supporting an object having more than one base class.
C/C++ Programming interview questions and answers document discusses key concepts in C++ including encapsulation, inheritance, polymorphism, constructors, destructors, copy constructors, references, virtual functions, abstract classes, and memory alignment. The document provides definitions and examples to explain each concept.
The document discusses object oriented programming concepts in C++ including classes, objects, data members, member functions, data abstraction, encapsulation, inheritance, polymorphism, access specifiers, and constructors. It provides examples of defining a class with private, public, and protected data members and member functions. Constructors such as the default, parameterized, and copy constructor are demonstrated. Inheritance concepts such as the base class, derived class, types of inheritance and visibility modes are explained.
Encapsulation isolates the internal complexity of an object's operation from the rest of the application. Inheritance allows one class to reuse the state and behavior of another class. Polymorphism allows a client to treat different objects in the same way even if they were created from different classes and exhibit different behaviors.
This document discusses defining custom classes in Java. It covers topics like returning objects from methods, using the "this" keyword, overloaded methods and constructors, class methods and variables, and organizing classes into packages. Key points include how objects are passed by value to method parameters rather than by reference, and how to document classes using Javadoc comments.
The document provides an overview of defining custom classes in Java, including how to return objects from methods, use the 'this' keyword, define overloaded methods and constructors, create class and static methods, implement parameter passing, organize classes into packages, and document classes with Javadoc comments. Key concepts like inheritance, polymorphism, and abstraction are not discussed. The chapter aims to describe the basics of defining custom classes in Java.
This document discusses object-oriented programming concepts in C++ such as abstraction, encapsulation, inheritance, and polymorphism. It also covers access specifiers like public, private, and protected. Other topics include friend functions and classes, static and non-static members, constructors, destructors, and inheritance.
This document provides class notes on object-oriented programming concepts like inheritance, packages, and interfaces. It covers topics like method overloading, objects as parameters, returning objects, static and nested classes, inheritance basics, method overriding, abstract classes, packages, and interfaces. The document is organized into sections on each topic with examples provided. It also includes indexes listing the topics covered and their importance levels. The material is intended to complement personalized learning materials and assessment tests for students.
This document discusses implementing multiple inheritance in C++. It begins with an example where a Terminal class needs to inherit from both a Task and Displayed class. It then provides background on multiple inheritance and how it allows combining independent concepts. The document outlines C++'s existing single inheritance implementation strategy before describing the author's approach to multiple inheritance, which preserves C++'s efficiency while supporting an object having more than one base class.
C/C++ Programming interview questions and answers document discusses key concepts in C++ including encapsulation, inheritance, polymorphism, constructors, destructors, copy constructors, references, virtual functions, abstract classes, and memory alignment. The document provides definitions and examples to explain each concept.
The document discusses object oriented programming concepts in C++ including classes, objects, data members, member functions, data abstraction, encapsulation, inheritance, polymorphism, access specifiers, and constructors. It provides examples of defining a class with private, public, and protected data members and member functions. Constructors such as the default, parameterized, and copy constructor are demonstrated. Inheritance concepts such as the base class, derived class, types of inheritance and visibility modes are explained.
Encapsulation isolates the internal complexity of an object's operation from the rest of the application. Inheritance allows one class to reuse the state and behavior of another class. Polymorphism allows a client to treat different objects in the same way even if they were created from different classes and exhibit different behaviors.
This document discusses defining custom classes in Java. It covers topics like returning objects from methods, using the "this" keyword, overloaded methods and constructors, class methods and variables, and organizing classes into packages. Key points include how objects are passed by value to method parameters rather than by reference, and how to document classes using Javadoc comments.
The document provides an overview of defining custom classes in Java, including how to return objects from methods, use the 'this' keyword, define overloaded methods and constructors, create class and static methods, implement parameter passing, organize classes into packages, and document classes with Javadoc comments. Key concepts like inheritance, polymorphism, and abstraction are not discussed. The chapter aims to describe the basics of defining custom classes in Java.
This document discusses object-oriented programming concepts in C++ such as abstraction, encapsulation, inheritance, and polymorphism. It also covers access specifiers like public, private, and protected. Other topics include friend functions and classes, static and non-static members, constructors, destructors, and inheritance.
Object-oriented programming supports key features like encapsulation, inheritance, and polymorphism. C++ classes encapsulate data and methods, with public interfaces and private implementations. Constructors initialize objects, and the compiler supplies default versions. Methods can access private members of other objects of the same class. Inheritance allows classes to extend others while polymorphism uses abstract base classes and derived implementations sharing a common interface.
Object-oriented programming supports key features like encapsulation, inheritance, and polymorphism. C++ classes encapsulate data and methods, with public interfaces and private implementations. Constructors initialize objects, and the compiler supplies default versions. Methods can access private members of other objects of the same class. Inheritance allows classes to extend others while polymorphism uses abstract base classes and derived implementations sharing a common interface.
This document provides an overview of key Java concepts including packages, classes, variables, expressions, flow control, and exceptions. It discusses Sun's naming conventions, comments, the final modifier, packages and namespaces, fields and methods, access control, instance vs static variables and methods, constructors, expressions and control flow statements, and exceptions. Examples are provided of a Person class including fields, constructors, accessors, static methods, and overridden methods like toString() and equals().
The document provides instructions to examiners for evaluating answers to examination questions. It states that examiners should assess understanding level rather than checking for word-to-word matches. Language errors like spelling mistakes should not be given more importance except for subjects related to language. While assessing figures, examiners may give credit for principal components. For numerical problems, credit may be given in a step-wise manner. In some cases, examiners can use their judgment to give credit for relevant answers based on a candidate's understanding. For programming questions, credit may be given to equivalent programs based on similar concepts.
C++ is an object-oriented programming language created by Bjarne Stroustrup in 1985 that maintains aspects of C while adding object-oriented features like classes. C++ can be used to create everything from small programs to large applications and is a powerful general-purpose language. Inheritance allows code reusability by creating new classes from existing classes or base classes, where derived classes inherit capabilities from base classes but can add their own features and refinements. Polymorphism enables objects to react differently to the same function call through virtual functions, allowing different classes that inherit from a base class to provide their own implementation of a function.
The document provides an overview of C++ vs C# by Shubhra Chauhan. It discusses the key object-oriented programming concepts like classes, objects, inheritance, polymorphism, and how they are implemented in C++ and C#. It includes code examples to demonstrate class usage and inheritance in both languages. The document also compares some similarities and differences between C++ and C# like support for pointers, preprocessors, structures, and goto statements.
This PPT File helps IT freshers with the Basic Interview Questions, which will boost there confidence before going to the Interview. For more details and Interview Questions please log in www.rekruitin.com and click on Job Seeker tools. Also register on the and get employed.
By ReKruiTIn.com
This document discusses objects and classes in Java. It begins by defining an object as an instance of a class that has state and behavior. An object's state is represented by its data fields and its behavior by its methods. It then defines a class as a template or blueprint from which objects are created. A class contains fields to represent state, methods to represent behavior, and constructors. The document provides examples of defining classes with fields and methods, creating objects from classes using the new operator, and accessing object fields and methods. It also covers access modifiers, packages, arrays of objects, and constructors in Java.
C++ [ principles of object oriented programming ]Rome468
C++ is an enhanced version of C that adds support for object-oriented programming. It includes everything in C and allows for defining classes and objects. Classes allow grouping of related data and functions, and objects are instances of classes. Key concepts of OOP supported in C++ include encapsulation, inheritance, and polymorphism. Encapsulation binds data and functions together in a class and allows hiding implementation details. Inheritance allows defining new classes based on existing classes to reuse their functionality. Polymorphism enables different classes to have similarly named functions that demonstrate different behavior.
The document is a test paper for the course CS2311 - Object-Oriented Programming at PERI INSTITUTE OF TECCHNOLOGY. It contains 15 questions testing concepts related to OOP such as classes, objects, inheritance, polymorphism, operator overloading, templates, and exception handling. It also includes questions about file handling and formatted I/O functions in C++. The test has a duration of 180 minutes and is worth a maximum of 100 marks, divided into multiple choice questions worth 2 marks each (Part A) and longer answer questions worth 16 marks each (Part B).
This document provides an overview of various data structures and algorithms implemented in C++. It begins with introductions to fundamental C++ concepts like classes, inheritance, templates, and pointers. It then covers common linear data structures like linked lists, stacks, and queues. For each, it provides high-level explanations of their properties and implementations using both linked lists and arrays. It also briefly introduces trees, binary trees, binary search trees, and other more advanced topics like graphs and graph algorithms. The document is intended as a set of prelecture notes to introduce key concepts before more in-depth lectures and implementations.
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 .
The document provides a list of 25 multiple choice questions related to C++ programming concepts such as classes, objects, inheritance, polymorphism, memory management, and more. Each question has 3-4 possible answer choices and is worth a certain number of points. The questions cover topics that would be included on a final exam for a C++ programming course.
This is a presentation I did for the Cedar Rapids .NET User Group (CRineta.org). It was intended to present object oriented concepts and their application in .NET and C#.
The document provides definitions and explanations of key concepts in C++ like encapsulation, inheritance, polymorphism, overriding, multiple inheritance, constructors, destructors, virtual functions, storage qualifiers, functions, pointers, and name mangling. It discusses these concepts over multiple sections in detail with examples.
The document discusses different levels of abstraction in object-oriented programming and design. It begins by defining abstraction and explaining why it is important for managing complexity. It then describes 5 levels of abstraction in OO programs from the highest level of interacting objects to the lowest level of individual methods. The document also covers different forms of abstraction like specialization and division into parts, and provides a brief history of abstraction mechanisms in computer science from assembly languages to modern object-oriented programming.
The document describes a C++ program called ListMyPolygons that allows users to input polygon details, store the polygon vertices in matrices, and perform transformations on the polygons. It discusses the design of the matrix, polygon, and user interface classes. The matrix class stores vertex coordinates and supports operations for transformations. Polygon classes are derived from an abstract base class and store vertex matrices. The user interface allows inputting polygons, reviewing/modifying them via transformations, and deleting polygons. While the program works for most polygons, determining regular polygons from vertices proved unreliable.
This document discusses generics and how they allow for type-safe data structures in Java and C#. Generics allow a class to act as a template that can be instantiated with different types. This avoids issues like needing to cast objects. The document provides examples of generic queues in Java and C# and discusses how constraints can restrict what types are allowed for generics.
The document discusses the benefits of object-oriented programming (OOP). It states that OOP offers several benefits to programmers and users, including greater productivity, higher quality software, and lower maintenance costs. It then lists 25 specific advantages of OOP such as code reusability through inheritance, modularity through pre-defined classes, data hiding for security, and easier mapping of real-world problems to code.
Finite_Element_Analysis_with_MATLAB_GUIColby White
This document describes a graphical user interface (GUI) created for a finite element analysis (FEA) optimization program. The GUI allows users to manipulate objects, apply forces and supports, and view analysis results such as displacement, strain, and stress. It builds on a 99 line FEA code by adding tools to adjust properties, run multiple analyses, and export optimized data for a more comprehensive understanding of simulation results. Test cases demonstrate the GUI's capabilities for various loading conditions.
Object-oriented programming supports key features like encapsulation, inheritance, and polymorphism. C++ classes encapsulate data and methods, with public interfaces and private implementations. Constructors initialize objects, and the compiler supplies default versions. Methods can access private members of other objects of the same class. Inheritance allows classes to extend others while polymorphism uses abstract base classes and derived implementations sharing a common interface.
Object-oriented programming supports key features like encapsulation, inheritance, and polymorphism. C++ classes encapsulate data and methods, with public interfaces and private implementations. Constructors initialize objects, and the compiler supplies default versions. Methods can access private members of other objects of the same class. Inheritance allows classes to extend others while polymorphism uses abstract base classes and derived implementations sharing a common interface.
This document provides an overview of key Java concepts including packages, classes, variables, expressions, flow control, and exceptions. It discusses Sun's naming conventions, comments, the final modifier, packages and namespaces, fields and methods, access control, instance vs static variables and methods, constructors, expressions and control flow statements, and exceptions. Examples are provided of a Person class including fields, constructors, accessors, static methods, and overridden methods like toString() and equals().
The document provides instructions to examiners for evaluating answers to examination questions. It states that examiners should assess understanding level rather than checking for word-to-word matches. Language errors like spelling mistakes should not be given more importance except for subjects related to language. While assessing figures, examiners may give credit for principal components. For numerical problems, credit may be given in a step-wise manner. In some cases, examiners can use their judgment to give credit for relevant answers based on a candidate's understanding. For programming questions, credit may be given to equivalent programs based on similar concepts.
C++ is an object-oriented programming language created by Bjarne Stroustrup in 1985 that maintains aspects of C while adding object-oriented features like classes. C++ can be used to create everything from small programs to large applications and is a powerful general-purpose language. Inheritance allows code reusability by creating new classes from existing classes or base classes, where derived classes inherit capabilities from base classes but can add their own features and refinements. Polymorphism enables objects to react differently to the same function call through virtual functions, allowing different classes that inherit from a base class to provide their own implementation of a function.
The document provides an overview of C++ vs C# by Shubhra Chauhan. It discusses the key object-oriented programming concepts like classes, objects, inheritance, polymorphism, and how they are implemented in C++ and C#. It includes code examples to demonstrate class usage and inheritance in both languages. The document also compares some similarities and differences between C++ and C# like support for pointers, preprocessors, structures, and goto statements.
This PPT File helps IT freshers with the Basic Interview Questions, which will boost there confidence before going to the Interview. For more details and Interview Questions please log in www.rekruitin.com and click on Job Seeker tools. Also register on the and get employed.
By ReKruiTIn.com
This document discusses objects and classes in Java. It begins by defining an object as an instance of a class that has state and behavior. An object's state is represented by its data fields and its behavior by its methods. It then defines a class as a template or blueprint from which objects are created. A class contains fields to represent state, methods to represent behavior, and constructors. The document provides examples of defining classes with fields and methods, creating objects from classes using the new operator, and accessing object fields and methods. It also covers access modifiers, packages, arrays of objects, and constructors in Java.
C++ [ principles of object oriented programming ]Rome468
C++ is an enhanced version of C that adds support for object-oriented programming. It includes everything in C and allows for defining classes and objects. Classes allow grouping of related data and functions, and objects are instances of classes. Key concepts of OOP supported in C++ include encapsulation, inheritance, and polymorphism. Encapsulation binds data and functions together in a class and allows hiding implementation details. Inheritance allows defining new classes based on existing classes to reuse their functionality. Polymorphism enables different classes to have similarly named functions that demonstrate different behavior.
The document is a test paper for the course CS2311 - Object-Oriented Programming at PERI INSTITUTE OF TECCHNOLOGY. It contains 15 questions testing concepts related to OOP such as classes, objects, inheritance, polymorphism, operator overloading, templates, and exception handling. It also includes questions about file handling and formatted I/O functions in C++. The test has a duration of 180 minutes and is worth a maximum of 100 marks, divided into multiple choice questions worth 2 marks each (Part A) and longer answer questions worth 16 marks each (Part B).
This document provides an overview of various data structures and algorithms implemented in C++. It begins with introductions to fundamental C++ concepts like classes, inheritance, templates, and pointers. It then covers common linear data structures like linked lists, stacks, and queues. For each, it provides high-level explanations of their properties and implementations using both linked lists and arrays. It also briefly introduces trees, binary trees, binary search trees, and other more advanced topics like graphs and graph algorithms. The document is intended as a set of prelecture notes to introduce key concepts before more in-depth lectures and implementations.
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 .
The document provides a list of 25 multiple choice questions related to C++ programming concepts such as classes, objects, inheritance, polymorphism, memory management, and more. Each question has 3-4 possible answer choices and is worth a certain number of points. The questions cover topics that would be included on a final exam for a C++ programming course.
This is a presentation I did for the Cedar Rapids .NET User Group (CRineta.org). It was intended to present object oriented concepts and their application in .NET and C#.
The document provides definitions and explanations of key concepts in C++ like encapsulation, inheritance, polymorphism, overriding, multiple inheritance, constructors, destructors, virtual functions, storage qualifiers, functions, pointers, and name mangling. It discusses these concepts over multiple sections in detail with examples.
The document discusses different levels of abstraction in object-oriented programming and design. It begins by defining abstraction and explaining why it is important for managing complexity. It then describes 5 levels of abstraction in OO programs from the highest level of interacting objects to the lowest level of individual methods. The document also covers different forms of abstraction like specialization and division into parts, and provides a brief history of abstraction mechanisms in computer science from assembly languages to modern object-oriented programming.
The document describes a C++ program called ListMyPolygons that allows users to input polygon details, store the polygon vertices in matrices, and perform transformations on the polygons. It discusses the design of the matrix, polygon, and user interface classes. The matrix class stores vertex coordinates and supports operations for transformations. Polygon classes are derived from an abstract base class and store vertex matrices. The user interface allows inputting polygons, reviewing/modifying them via transformations, and deleting polygons. While the program works for most polygons, determining regular polygons from vertices proved unreliable.
This document discusses generics and how they allow for type-safe data structures in Java and C#. Generics allow a class to act as a template that can be instantiated with different types. This avoids issues like needing to cast objects. The document provides examples of generic queues in Java and C# and discusses how constraints can restrict what types are allowed for generics.
The document discusses the benefits of object-oriented programming (OOP). It states that OOP offers several benefits to programmers and users, including greater productivity, higher quality software, and lower maintenance costs. It then lists 25 specific advantages of OOP such as code reusability through inheritance, modularity through pre-defined classes, data hiding for security, and easier mapping of real-world problems to code.
Finite_Element_Analysis_with_MATLAB_GUIColby White
This document describes a graphical user interface (GUI) created for a finite element analysis (FEA) optimization program. The GUI allows users to manipulate objects, apply forces and supports, and view analysis results such as displacement, strain, and stress. It builds on a 99 line FEA code by adding tools to adjust properties, run multiple analyses, and export optimized data for a more comprehensive understanding of simulation results. Test cases demonstrate the GUI's capabilities for various loading conditions.
08_ digital electronics for engineers electronics.pptElisée Ndjabu
This document provides an overview of basic electronics concepts including:
1) Basic circuit analysis including Ohm's Law, voltage dividers, and the relations between voltage, current, resistance, capacitance, and inductance.
2) Examples of fundamental circuits like voltage dividers and the impact of output impedance on power supplies.
3) An introduction to diodes and their usage in half-wave and full-wave rectifiers to convert AC to DC, as well as smoothing the output with capacitors.
4) Voltage regulation using zener diodes or voltage regulator ICs to provide a stable output voltage regardless of load or input variations.
5) An overview of transistor operation and
The document discusses the fundamentals of digital logic gates. It describes the basic logic gates - NOT, AND, and OR - and how more complex gates like NAND, NOR, XOR, and XNOR are derived from combining these basic gates. It also provides truth tables that define the input and output behavior of each gate. The document explains that logic circuits are built by connecting individual logic gates together and that these circuits have applications in areas like computing, engineering, and automation.
07_arithmeticcircuits digital electronics.pptxElisée Ndjabu
Arithmetic circuits are essential components of digital systems and determine system performance. Adders are fundamental arithmetic circuits used to implement other functions like subtraction and comparison. Common adder circuits include half adders, full adders, and ripple carry adders. Multipliers generate partial products that are reduced using carry save adders and summed using a carry propagate adder. Other important arithmetic functions include shifting, which can implement multiplication and division. The Arithmetic Logic Unit in a CPU contains resources to perform operations in parallel using functions like AND, OR, addition, and comparison.
296484860-Moving-Iron-Instruments for computer engineers.pptElisée Ndjabu
Moving iron instruments use soft iron pieces that are attracted or repelled by the magnetic field produced by a current-carrying coil. There are two types: attraction, where a soft iron piece is attracted into the coil's magnetic field, and repulsion, where two similarly magnetized iron pieces repel each other. Both operate on direct and alternating current. Moving iron instruments are inexpensive, robust, and can withstand overloads, but have non-uniform scales and errors from temperature changes and stray magnetic fields.
sp12Part2 CIRCUITS AND SYSTEMS FOR COMPUTER ENGINEERING .pptxElisée Ndjabu
This document discusses the high-frequency response of electronic circuits such as amplifiers. It begins by introducing high-frequency small-signal models for MOSFETs and BJTs. It then defines the unity-gain frequency and describes how to find capacitance values using this frequency. The document provides an example of analyzing the effect of one capacitor on amplifier gain. It also discusses the frequency response of common source and common emitter amplifiers, showing their high-frequency small-signal equivalent circuits. Key aspects of amplifier frequency response like gain, poles, zeros, and Bode plots are covered.
sp12Part4 CIRCUITS AND SYSTEMS FOR COMPUTER SCIENCE.pptxElisée Ndjabu
1) Operational amplifiers (op-amps) are devices with very high gain that can be used to perform mathematical operations such as amplification, integration, differentiation, and comparison of voltages.
2) The ideal op-amp has infinite input impedance, zero output impedance, infinite open-loop gain, and infinite bandwidth. Real op-amps have finite characteristics that affect their performance.
3) Common op-amp configurations include the inverting amplifier, non-inverting amplifier, voltage follower, summing amplifier, difference amplifier, integrator, and differentiator. These configurations allow op-amps to perform various signal processing functions.
After COMPUTING THIS IS FOR COMPUTER SCIENTISTS.pptxElisée Ndjabu
The document discusses the structure and syntax of Arduino programs. It explains that an Arduino program must have two main functions: setup() which runs once at startup to initialize variables, and loop() which runs continuously. It describes how to declare variables and constants, use functions like pinMode(), digitalWrite(), analogRead(), analogWrite(), and delay(). It also covers topics like serial communication, for loops, and printing to the serial monitor.
RESEARCH METHODOLOGY FOR COMPUTER ENGINEERSElisée Ndjabu
This document outlines the structure and topics of a lecture on research methods in empirical and experimental computer science research. The lecture includes 6 hours split over two classes. The first class will include an initial presentation on research methods and a homework assignment for students to analyze an empirical research paper. The second class will involve student presentations of their assigned papers and discussion. Assessment will be based on the critical presentation of the assigned research paper. The lecture aims to provide an understanding of different research methods and paradigms, with a focus on empirical and engineering methods. Key topics that will be discussed include the definitions of research and different research techniques, computer science as a field, and research paradigms in computer science such as experimental versus theoretical research.
The document summarizes a lecture on C programming that covered basics like data types, operators, input/output functions, and examples. It discussed keywords, arithmetic operators, precedence rules, and provided examples of simple C programs. The lecture also touched on compilation errors, user-defined data types, and precedence tables to explain order of operations. Homework problems were assigned related to syntax, semantics, and predicting output of expressions using increment operators.
This document provides information about an advanced algorithms and data structures course. It includes the instructor's contact information, details about lectures and problem sessions, acknowledgements, recommended textbooks, and an outline of course topics. The course will cover algorithmic paradigms, order statistics, priority queues, randomized data structures, geometric queries, approximation algorithms, and linear programming. Students are encouraged to consult additional online materials through the provided web link.
This document provides an overview of an introduction to C programming lecture. It discusses the course goals, which include mastering programming skills in C and gaining experience writing readable and reusable programs. It also outlines the means of achieving the goals through labs, homeworks and exams. The evaluation and exam components are described, including points for homeworks, a test, and exams. An introduction to C programming is then provided, covering writing programs in C, values and variables, expressions, and standard input/output.
The document outlines a 180-minute lesson plan on motherboards. The plan aims to teach students about the function and components of motherboards, different types of motherboards, and considerations when selecting a motherboard. Key topics covered include the CPU, chipset, buses, expansion slots, and hardware configuration. Students will fill out an organizer during a presentation, complete a lab to remove and install a motherboard, and be assessed through a lab rubric and exam. The goal is for students to understand the importance and workings of the motherboard.
This document provides an overview and summary of concepts related to complex power in circuits with sinusoidal sources. It begins with an introduction and overview of topics to be covered, including a review of phasors, RMS values, and power calculations with sinusoids. It then derives the RMS value of a sinusoidal waveform. The document shows that the average power P in a circuit is equal to the product of the RMS voltage and current multiplied by the cosine of the phase difference between the voltage and current waveforms. It provides notes explaining properties of the average power calculation.
Advanced control scheme of doubly fed induction generator for wind turbine us...IJECEIAES
This paper describes a speed control device for generating electrical energy on an electricity network based on the doubly fed induction generator (DFIG) used for wind power conversion systems. At first, a double-fed induction generator model was constructed. A control law is formulated to govern the flow of energy between the stator of a DFIG and the energy network using three types of controllers: proportional integral (PI), sliding mode controller (SMC) and second order sliding mode controller (SOSMC). Their different results in terms of power reference tracking, reaction to unexpected speed fluctuations, sensitivity to perturbations, and resilience against machine parameter alterations are compared. MATLAB/Simulink was used to conduct the simulations for the preceding study. Multiple simulations have shown very satisfying results, and the investigations demonstrate the efficacy and power-enhancing capabilities of the suggested control system.
International Conference on NLP, Artificial Intelligence, Machine Learning an...gerogepatton
International Conference on NLP, Artificial Intelligence, Machine Learning and Applications (NLAIM 2024) offers a premier global platform for exchanging insights and findings in the theory, methodology, and applications of NLP, Artificial Intelligence, Machine Learning, and their applications. The conference seeks substantial contributions across all key domains of NLP, Artificial Intelligence, Machine Learning, and their practical applications, aiming to foster both theoretical advancements and real-world implementations. With a focus on facilitating collaboration between researchers and practitioners from academia and industry, the conference serves as a nexus for sharing the latest developments in the field.
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELgerogepatton
As digital technology becomes more deeply embedded in power systems, protecting the communication
networks of Smart Grids (SG) has emerged as a critical concern. Distributed Network Protocol 3 (DNP3)
represents a multi-tiered application layer protocol extensively utilized in Supervisory Control and Data
Acquisition (SCADA)-based smart grids to facilitate real-time data gathering and control functionalities.
Robust Intrusion Detection Systems (IDS) are necessary for early threat detection and mitigation because
of the interconnection of these networks, which makes them vulnerable to a variety of cyberattacks. To
solve this issue, this paper develops a hybrid Deep Learning (DL) model specifically designed for intrusion
detection in smart grids. The proposed approach is a combination of the Convolutional Neural Network
(CNN) and the Long-Short-Term Memory algorithms (LSTM). We employed a recent intrusion detection
dataset (DNP3), which focuses on unauthorized commands and Denial of Service (DoS) cyberattacks, to
train and test our model. The results of our experiments show that our CNN-LSTM method is much better
at finding smart grid intrusions than other deep learning algorithms used for classification. In addition,
our proposed approach improves accuracy, precision, recall, and F1 score, achieving a high detection
accuracy rate of 99.50%.
Using recycled concrete aggregates (RCA) for pavements is crucial to achieving sustainability. Implementing RCA for new pavement can minimize carbon footprint, conserve natural resources, reduce harmful emissions, and lower life cycle costs. Compared to natural aggregate (NA), RCA pavement has fewer comprehensive studies and sustainability assessments.
Literature Review Basics and Understanding Reference Management.pptxDr Ramhari Poudyal
Three-day training on academic research focuses on analytical tools at United Technical College, supported by the University Grant Commission, Nepal. 24-26 May 2024
Introduction- e - waste – definition - sources of e-waste– hazardous substances in e-waste - effects of e-waste on environment and human health- need for e-waste management– e-waste handling rules - waste minimization techniques for managing e-waste – recycling of e-waste - disposal treatment methods of e- waste – mechanism of extraction of precious metal from leaching solution-global Scenario of E-waste – E-waste in India- case studies.
Understanding Inductive Bias in Machine LearningSUTEJAS
This presentation explores the concept of inductive bias in machine learning. It explains how algorithms come with built-in assumptions and preferences that guide the learning process. You'll learn about the different types of inductive bias and how they can impact the performance and generalizability of machine learning models.
The presentation also covers the positive and negative aspects of inductive bias, along with strategies for mitigating potential drawbacks. We'll explore examples of how bias manifests in algorithms like neural networks and decision trees.
By understanding inductive bias, you can gain valuable insights into how machine learning models work and make informed decisions when building and deploying them.
A review on techniques and modelling methodologies used for checking electrom...nooriasukmaningtyas
The proper function of the integrated circuit (IC) in an inhibiting electromagnetic environment has always been a serious concern throughout the decades of revolution in the world of electronics, from disjunct devices to today’s integrated circuit technology, where billions of transistors are combined on a single chip. The automotive industry and smart vehicles in particular, are confronting design issues such as being prone to electromagnetic interference (EMI). Electronic control devices calculate incorrect outputs because of EMI and sensors give misleading values which can prove fatal in case of automotives. In this paper, the authors have non exhaustively tried to review research work concerned with the investigation of EMI in ICs and prediction of this EMI using various modelling methodologies and measurement setups.
ACEP Magazine edition 4th launched on 05.06.2024Rahul
This document provides information about the third edition of the magazine "Sthapatya" published by the Association of Civil Engineers (Practicing) Aurangabad. It includes messages from current and past presidents of ACEP, memories and photos from past ACEP events, information on life time achievement awards given by ACEP, and a technical article on concrete maintenance, repairs and strengthening. The document highlights activities of ACEP and provides a technical educational article for members.
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTjpsjournal1
The rivalry between prominent international actors for dominance over Central Asia's hydrocarbon
reserves and the ancient silk trade route, along with China's diplomatic endeavours in the area, has been
referred to as the "New Great Game." This research centres on the power struggle, considering
geopolitical, geostrategic, and geoeconomic variables. Topics including trade, political hegemony, oil
politics, and conventional and nontraditional security are all explored and explained by the researcher.
Using Mackinder's Heartland, Spykman Rimland, and Hegemonic Stability theories, examines China's role
in Central Asia. This study adheres to the empirical epistemological method and has taken care of
objectivity. This study analyze primary and secondary research documents critically to elaborate role of
china’s geo economic outreach in central Asian countries and its future prospect. China is thriving in trade,
pipeline politics, and winning states, according to this study, thanks to important instruments like the
Shanghai Cooperation Organisation and the Belt and Road Economic Initiative. According to this study,
China is seeing significant success in commerce, pipeline politics, and gaining influence on other
governments. This success may be attributed to the effective utilisation of key tools such as the Shanghai
Cooperation Organisation and the Belt and Road Economic Initiative.
1. Object Oriented Programming in C++
Jan Faigl
Department of Computer Science
Faculty of Electrical Engineering
Czech Technical University in Prague
Lecture 11
BE5B99CPL – C Programming Language
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 1 / 48
2. Overview of the Lecture
Part 1 – Object Oriented Programming (in C++)
Objects and Methods in C++
Relationship
Inheritance
Polymorphism
Inheritance and Composition
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 2 / 48
3. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Part I
Part 1 – Object Oriented Programming
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 3 / 48
4. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Outline
Objects and Methods in C++
Relationship
Inheritance
Polymorphism
Inheritance and Composition
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 4 / 48
5. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example of Encapsulation
Class Matrix encapsulates 2D matrix of double values
class Matrix {
public:
Matrix(int rows, int cols);
Matrix(const Matrix &m);
~Matrix();
inline int rows(void) const { return ROWS; }
inline int cols(void) const { return COLS; }
double getValueAt(int r, int c) const;
void setValueAt(double v, int r, int c);
void fillRandom(void);
Matrix sum(const Matrix &m2);
Matrix operator+(const Matrix &m2);
Matrix& operator=(const Matrix &m);
private:
inline double& at(int r, int c) const { return vals[COLS * r + c]; }
private:
const int ROWS;
const int COLS;
double *vals;
};
std::ostream& operator<<(std::ostream& out, const Matrix& m);
lec11/matrix.h
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 5 / 48
6. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Matrix Subscripting Operator
For a convenient access to matrix cells, we can implement operator
() with two arguments r and c denoting the cell row and column
class Matrix {
public:
double& operator()(int r, int c);
double operator()(int r, int c) const;
};
// use the reference for modification of the cell value
double& Matrix::operator()(int r, int c)
{
return at(r, c);
}
// copy the value for the const operator
double Matrix::operator()(int r, int c) const
{
return at(r, c);
}
For simplicity and better readability, we do not check range of arguments.
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 6 / 48
7. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example Matrix – Identity Matrix
Implementation of the function set the matrix to the identity using
the matrix subscripting operator
void setIdentity(Matrix& matrix)
{
for (int r = 0; r < matrix.rows(); ++r) {
for (int c = 0; c < matrix.cols(); ++c) {
matrix(r, c) = (r == c) ? 1.0 : 0.0;
}
}
}
Matrix m1(2, 2);
std::cout << "Matrix m1 -- init values: " << std::endl << m1;
setIdentity(m1);
std::cout << "Matrix m1 -- identity: " << std::endl << m1;
Example of output
Matrix m1 -- init values:
0.0 0.0
0.0 0.0
Matrix m1 -- identity:
1.0 0.0
0.0 1.0
lec11/demo-matrix.cc
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 7 / 48
8. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Outline
Objects and Methods in C++
Relationship
Inheritance
Polymorphism
Inheritance and Composition
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 8 / 48
9. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Relationship between Objects
Objects can be in relationship based on the
Inheritance – is the relationship of the type is
Object of descendant class is also the ancestor class
One class is derived from the ancestor class
Objects of the derived class extends the based class
Derived class contains all the field of the ancestor class
However, some of the fields may be hidden
New methods can be implemented in the derived class
New implementation override the previous one
Derived class (objects) are specialization of a more general
ancestor (super) class
An object can be part of the other objects – it is the has relation
Similarly to compound structures that contain other struct data
types as their data fields, objects can also compound of other objects
We can further distinguish
Aggregation – an object is a part of other object
Composition – inner object exists only within the compound object
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 9 / 48
10. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Aggregation/Composition
Aggregation – relationship of the type “has” or “it is composed
Let A be aggregation of B C, then objects B and C are contained
in A
It results that B and C cannot survive without A
In such a case, we call the relationship as composition
Example of implementation
class GraphComp { // composition
private:
std::vector<Edge> edges;
};
class GraphComp { // aggregation
public:
GraphComp(std::vector<Edge>& edges)
: edges(edges) {}
private:
const std::vector<Edge>& edges;
};
struct Edge {
Node v1;
Node v2;
};
struct Node {
Data data;
};
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 10 / 48
11. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Outline
Objects and Methods in C++
Relationship
Inheritance
Polymorphism
Inheritance and Composition
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 11 / 48
12. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Inheritance
Founding definition and implementation of one class on another
existing class(es)
Let class B be inherited from the class A, then
Class B is subclass or the derived class of A
Class A is superclass or the base class of B
The subclass B has two parts in general:
Derived part is inherited from A
New incremental part contains definitions and implementation
added by the class B
The inheritance is relationship of the type is-a
Object of the type B is also an instance of the object of the type A
Properties of B inherited from the A can be redefined
Change of field visibility (protected, public, private)
Overriding of the method implementation
Using inheritance we can create hierarchies of objects
Implement general function in superclasses or creating abstract classes
that are further specialized in the derived classes.
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 12 / 48
13. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example MatrixExt – Extension of the Matrix
We will extend the existing class Matrix to have identity method
and also multiplication operator
We refer the superclass as the Base class using typedef
We need to provide a constructor for the MatrixExt; however, we
used the existing constructor in the base class
class MatrixExt : public Matrix {
typedef Matrix Base; // typedef for refering the superclass
public:
MatrixExt(int r, int c) : Base(r, c) {} // base constructor
void setIdentity(void);
Matrix operator*(const Matrix &m2);
}; lec11/matrix_ext.h
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 13 / 48
14. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example MatrixExt – Identity and Multiplication Operator
We can use only the public (or protected) methods of Matrix class
Matrix does not have any protected members
#include "matrix_ext.h"
void MatrixExt::setIdentity(void)
{
for (int r = 0; r < rows(); ++r) {
for (int c = 0; c < cols(); ++c) {
(*this)(r, c) = (r == c) ? 1.0 : 0.0;
}
}
}
Matrix MatrixExt::operator*(const Matrix &m2)
{
Matrix m3(rows(), m2.cols());
for (int r = 0; r < rows(); ++r) {
for (int c = 0; c < m2.cols(); ++c) {
m3(r, c) = 0.0;
for (int k = 0; k < cols(); ++k) {
m3(r, c) += (*this)(r, k) * m2(k, c);
}
}
}
return m3;
} lec11/matrix_ext.cc
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 14 / 48
15. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example MatrixExt – Example of Usage 1/2
Objects of the class MatrixExt also have the methods of the
Matrix
#include <iostream>
#include "matrix_ext.h"
using std::cout;
int main(void)
{
int ret = 0;
MatrixExt m1(2, 1);
m1(0, 0) = 3; m1(1, 0) = 5;
MatrixExt m2(1, 2);
m2(0, 0) = 1; m2(0, 1) = 2;
cout << "Matrix m1:n" << m1 << std::endl;
cout << "Matrix m2:n" << m2 << std::endl;
cout << "m1 * m2 =n" << m2 * m1 << std::endl;
cout << "m2 * m1 =n" << m1 * m2 << std::endl;
return ret;
}
clang++ matrix.cc matrix_ext.
cc demo-matrix_ext.cc &&
./a.out
Matrix m1:
3.0
5.0
Matrix m2:
1.0 2.0
m1 * m2 =
13.0
m2 * m1 =
3.0 6.0
5.0 10.0
lec11/demo-matrix_ext.cc
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 15 / 48
16. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example MatrixExt – Example of Usage 2/2
We may use objects of MatrixExt anywhere objects of Matrix can
be applied.
This is a result of the inheritance
And a first step towards polymorphism
void setIdentity(Matrix& matrix)
{
for (int r = 0; r < matrix.rows(); ++r) {
for (int c = 0; c < matrix.cols(); ++c) {
matrix(r, c) = (r == c) ? 1.0 : 0.0;
}
}
}
MatrixExt m1(2, 1);
cout << "Using setIdentity for Matrix" << std::endl;
setIdentity(m1);
cout << "Matrix m1:n" << m1 << std::endl;
lec11/demo-matrix_ext.cc
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 16 / 48
17. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Categories of the Inheritance
Strict inheritance – derived class takes all of the superclass and
adds own methods and attributes. All members of the superclass
are available in the derived class. It strictly follows the is-a
hierarchy
Nonstrict inheritance – the subclass derives from the a superclass
only certain attributes or methods that can be further redefined
Multiple inheritance – a class is derived from several superclasses
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 17 / 48
18. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Inheritance – Summary
Inheritance is a mechanism that allows
Extend data field of the class and modify them
Extend or modify methods of the class
Inheritance allows to
Create hierarchies of classes
“Pass” data fields and methods for further extension and
modification
Specialize (specify) classes
The main advantages of inheritance are
It contributes essentially to the code reusability
Together with encapsulation!
Inheritance is foundation for the polymorphism
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 18 / 48
19. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Outline
Objects and Methods in C++
Relationship
Inheritance
Polymorphism
Inheritance and Composition
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 19 / 48
20. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Polymorphism
Polymorphism can be expressed as the ability to refer in a same way
to different objects
We can call the same method names on different objects
We work with an object whose actual content is determined at the
runtime
Polymorphism of objects - Let the class B be a subclass of A, then
the object of the B can be used wherever it is expected to be an
object of the class A
Polymorphism of methods requires dynamic binding, i.e., static vs.
dynamic type of the class
Let the class B be a subclass of A and redefines the method m()
A variable x is of the static type B, but its dynamic type can be A
or B
Which method is actually called for x.m() depends on the dynamic
type
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 20 / 48
21. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example MatrixExt – Method Overriding 1/2
In MatrixExt, we may override a method implemented in the base
class Matrix, e.g., fillRandom() will also use negative values.
class MatrixExt : public Matrix {
...
void fillRandom(void);
}
void MatrixExt::fillRandom(void)
{
for (int r = 0; r < rows(); ++r) {
for (int c = 0; c < cols(); ++c) {
(*this)(r, c) = (rand() % 100) / 10.0;
if (rand() % 100 > 50) {
(*this)(r, c) *= -1.0; // change the sign
}
}
}
} lec11/matrix_ext.h, lec11/matrix_ext.cc
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 21 / 48
22. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example MatrixExt – Method Overriding 2/2
We can call the method fillRandom() of the MatrixExt
MatrixExt *m1 = new MatrixExt(3, 3);
Matrix *m2 = new MatrixExt(3, 3);
m1->fillRandom(); m2->fillRandom();
cout << "m1: MatrixExt as MatrixExt:n" << *m1 << std::endl;
cout << "m2: MatrixExt as Matrix:n" << *m2 << std::endl;
delete m1; delete m2; lec11/demo-matrix_ext.cc
However, in the case of m2 the Matrix::fillRandom() is called
m1: MatrixExt as MatrixExt:
-1.3 9.8 1.2
8.7 -9.8 -7.9
-3.6 -7.3 -0.6
m2: MatrixExt as Matrix:
7.9 2.3 0.5
9.0 7.0 6.6
7.2 1.8 9.7
We need a dynamic way to identity the object type at runtime
for the polymorphism of the methods
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 22 / 48
23. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Virtual Methods – Polymorphism and Inheritance
We need a dynamic binding for polymorphism of the methods
It is usually implemented as a virtual method in object oriented
programming languages
Override methods that are marked as virtual has a dynamic
binding to the particular dynamic type
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 23 / 48
24. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Overriding without Virtual Method 1/2
#include <iostream>
using namespace std;
class A {
public:
void info()
{
cout << "Object of the class A" << endl;
}
};
class B : public A {
public:
void info()
{
cout << "Object of the class B" << endl;
}
};
A* a = new A(); B* b = new B();
A* ta = a; // backup of a pointer
a->info(); // calling method info() of the class A
b->info(); // calling method info() of the class B
a = b; // use the polymorphism of objects
a->info(); // without the dynamic binding, method of the class A is called
delete ta; delete b;
clang++ demo-novirtual.cc
./a.out
Object of the class A
Object of the class B
Object of the class A
lec11/demo-novirtual.cc
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 24 / 48
25. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Overriding with Virtual Method 2/2
#include <iostream>
using namespace std;
class A {
public:
virtual void info() // Virtual !!!
{
cout << "Object of the class A" << endl;
}
};
class B : public A {
public:
void info()
{
cout << "Object of the class B" << endl;
}
};
A* a = new A(); B* b = new B();
A* ta = a; // backup of a pointer
a->info(); // calling method info() of the class A
b->info(); // calling method info() of the class B
a = b; // use the polymorphism of objects
a->info(); // the dynamic binding exists, method of the class B is called
delete ta; delete b;
clang++ demo-virtual.cc
./a.out
Object of the class A
Object of the class B
Object of the class B
lec11/demo-virtual.cc
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 25 / 48
26. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Derived Classes, Polymorphism, and Practical Implications
Derived class inherits the methods and data fields of the
superclass, but it can also add new methods and data fields
It can extend and specialize the class
It can modify the implementation of the methods
An object of the derived class can be used instead of the object of
the superclass, e.g.,
We can implement more efficient matrix multiplication without
modification of the whole program
We may further need a mechanism to create new object based on the
dynamic type, i.e., using the newInstance virtual method
Virtual methods are important for the polymorphism
It is crucial to use a virtual destructor for a proper destruction of
the object
E.g., when a derived class allocate additional memory
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 26 / 48
27. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Virtual Destructor 1/4
#include <iostream>
using namespace std;
class Base {
public:
Base(int capacity) {
cout << "Base::Base -- allocate data" << endl;
int *data = new int[capacity];
}
virtual ~Base() { // virtual destructor is important
cout << "Base::~Base -- release data" << endl;
}
protected:
int *data;
};
lec11/demo-virtual_destructor.cc
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 27 / 48
28. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Virtual Destructor 2/4
class Derived : public Base {
public:
Derived(int capacity) : Base(capacity) {
cout << "Derived::Derived -- allocate data2" << endl;
int *data2 = new int[capacity];
}
~Derived() {
cout << "Derived::~Derived -- release data2" << endl;
int *data2;
}
protected:
int *data2;
};
lec11/demo-virtual_destructor.cc
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 28 / 48
29. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Virtual Destructor 3/4
Using virtual destructor all allocated data are properly released
cout << "Using Derived " << endl;
Derived *object = new Derived(1000000);
delete object;
cout << endl;
cout << "Using Base" << endl;
Base *object = new Derived(1000000);
delete object;
lec11/demo-virtual_destructor.cc
clang++ demo-virtual_destructor.cc && ./a.out
Using Derived
Base::Base -- allocate data
Derived::Derived -- allocate data2
Derived::~Derived -- release data2
Base::~Base -- release data
Using Base
Base::Base -- allocate data
Derived::Derived -- allocate data2
Derived::~Derived -- release data2
Base::~Base -- release data
Both desctructors Derived and Base are called
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 29 / 48
30. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Virtual Destructor 4/4
Without virtual destructor, e.g„
class Base {
...
~Base(); // without virtualdestructor
};
Derived *object = new Derived(1000000);
delete object;
Base *object = new Derived(1000000);
delete object;
Only both constructors are called, but only destructor of the Base
class in the second case Base *object = new Derived(1000000);
Using Derived
Base::Base -- allocate data
Derived::Derived -- allocate data2
Derived::~Derived -- release data2
Base::~Base -- release data
Using Base
Base::Base -- allocate data
Derived::Derived -- allocate data2
Base::~Base -- release data
Only the desctructor of Base is called
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 30 / 48
31. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Outline
Objects and Methods in C++
Relationship
Inheritance
Polymorphism
Inheritance and Composition
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 31 / 48
32. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Inheritance and Composition
A part of the object oriented programming is the object oriented
design (OOD)
It aims to provide “a plan” how to solve the problem using objects
and their relationship
An important part of the design is identification of the particular
objects
their generalization to the classes
and also designing a class hierarchy
Sometimes, it may be difficult to decides
What is the common (general) object and what is the specializa-
tion, which is important step for class hierarchy and applying the
inheritance
It may also be questionable when to use composition
Let show the inheritance on an example of geometrical objects
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 32 / 48
33. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Is Cuboid Extended Rectangle? 1/2
class Rectangle {
public:
Rectangle(double w, double h) : width(w), height(h) {}
inline double getWidth(void) const { return width; }
inline double getHeight(void) const { return height; }
inline double getDiagonal(void) const
{
return sqrt(width*width + height*height);
}
protected:
double width;
double height;
};
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 33 / 48
34. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Is Cuboid Extended Rectangle? 2/2
class Cuboid : public Rectangle {
public:
Cuboid(double w, double h, double d) :
Rectangle(w, h), depth(d) {}
inline double getDepth(void) const { return depth; }
inline double getDiagonal(void) const
{
const double tmp = Rectangle::getDiagonal();
return sqrt(tmp * tmp + depth * depth);
}
protected:
double depth;
};
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 34 / 48
35. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Inheritance Cuboid Extend Rectangle
Class Cuboid extends the class Rectangle by the depth
Cuboid inherits data fields width a height
Cuboid also inherits „getters” getWidth() and getHeight()
Constructor of the Rectangle is called from the Cuboid constructor
The descendant class Cuboid extends (override) the
getDiagonal() methods
It actually uses the method getDiagonal() of the ancestor
Rectangle::getDiagonal()
We create a “specialization” of the Rectangle as an extension
Cuboid class
Is it really a suitable extension?
What is the cuboid area? What is the cuboid circumference?
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 35 / 48
36. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Inheritance Cuboid Extend Rectangle
Class Cuboid extends the class Rectangle by the depth
Cuboid inherits data fields width a height
Cuboid also inherits „getters” getWidth() and getHeight()
Constructor of the Rectangle is called from the Cuboid constructor
The descendant class Cuboid extends (override) the
getDiagonal() methods
It actually uses the method getDiagonal() of the ancestor
Rectangle::getDiagonal()
We create a “specialization” of the Rectangle as an extension
Cuboid class
Is it really a suitable extension?
What is the cuboid area? What is the cuboid circumference?
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 35 / 48
37. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Inheritance Cuboid Extend Rectangle
Class Cuboid extends the class Rectangle by the depth
Cuboid inherits data fields width a height
Cuboid also inherits „getters” getWidth() and getHeight()
Constructor of the Rectangle is called from the Cuboid constructor
The descendant class Cuboid extends (override) the
getDiagonal() methods
It actually uses the method getDiagonal() of the ancestor
Rectangle::getDiagonal()
We create a “specialization” of the Rectangle as an extension
Cuboid class
Is it really a suitable extension?
What is the cuboid area? What is the cuboid circumference?
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 35 / 48
38. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Inheritance – Rectangle is a Special Cuboid 1/2
Rectangle is a cuboid with zero depth
class Cuboid {
public:
Cuboid(double w, double h, double d) :
width(w), height(h), depth(d) {}
inline double getWidth(void) const { return width; }
inline double getHeight(void) const { return height; }
inline double getDepth(void) const { return depth; }
inline double getDiagonal(void) const
{
return sqrt(width*width + height*height + depth*depth);
}
protected:
double width;
double height;
double depth;
};
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 36 / 48
39. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Inheritance – Rectangle is a Special Cuboid 2/2
class Rectangle : public Cuboid {
public:
Rectangle(double w, double h) : Cuboid(w, h, 0.0) {}
};
Rectangle is a “cuboid” with zero depth
Rectangle inherits all data fields: with, height, and depth
It also inherits all methods of the ancestor
Accessible can be only particular ones
The constructor of the Cuboid class is accessible and it used to
set data fields with the zero depth
Objects of the class Rectangle can use all variable and methods
of the Cuboid class
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 37 / 48
40. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Should be Rectangle Descendant of Cuboid or Cuboid be
Descendant of Rectangle?
1. Cuboid is descendant of the rectangle
“Logical” addition of the depth dimensions, but methods valid for
the rectangle do not work of the cuboid
E.g., area of the rectangle
2. Rectangle as a descendant of the cuboid
Logically correct reasoning on specialization
“All what work for the cuboid also work for the cuboid with zero
depth”
Inefficient implementation – every rectangle is represented by 3 di-
mensions
Specialization is correct
Everything what hold for the ancestor have to be valid for the descendant
However, in this particular case, usage of the inheritance is questionable.
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 38 / 48
41. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Should be Rectangle Descendant of Cuboid or Cuboid be
Descendant of Rectangle?
1. Cuboid is descendant of the rectangle
“Logical” addition of the depth dimensions, but methods valid for
the rectangle do not work of the cuboid
E.g., area of the rectangle
2. Rectangle as a descendant of the cuboid
Logically correct reasoning on specialization
“All what work for the cuboid also work for the cuboid with zero
depth”
Inefficient implementation – every rectangle is represented by 3 di-
mensions
Specialization is correct
Everything what hold for the ancestor have to be valid for the descendant
However, in this particular case, usage of the inheritance is questionable.
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 38 / 48
42. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Should be Rectangle Descendant of Cuboid or Cuboid be
Descendant of Rectangle?
1. Cuboid is descendant of the rectangle
“Logical” addition of the depth dimensions, but methods valid for
the rectangle do not work of the cuboid
E.g., area of the rectangle
2. Rectangle as a descendant of the cuboid
Logically correct reasoning on specialization
“All what work for the cuboid also work for the cuboid with zero
depth”
Inefficient implementation – every rectangle is represented by 3 di-
mensions
Specialization is correct
Everything what hold for the ancestor have to be valid for the descendant
However, in this particular case, usage of the inheritance is questionable.
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 38 / 48
43. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Relationship of the Ancestor and Descendant is of the type
“is-a”
Is a straight line segment descendant of the point?
Straight line segment does not use any method of a point
is-a?: segment is a point ? → NO → segment is not descendant
of the point
Is rectangle descendant of the straight line segment?
is-a?: NO
Is rectangle descendant of the square, or vice versa?
Rectangle “extends” square by one dimension, but it is not a square
Square is a rectangle with the width same as the height
Set the width and height in the constructor!
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 39 / 48
44. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Substitution Principle
Relationship between two derived classes
Policy
Derived class is a specialization of the superclass
There is the is-a relationship
Wherever it is possible to sue a class, it must be possible to use
the descendant in such a way that a user cannot see any difference
Polymorphism
Relationship is-a must be permanent
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 40 / 48
45. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Composition of Objects
If a class contains data fields of other object type, the relationship
is called composition
Composition creates a hierarchy of objects, but not by inheritance
Inheritance creates hierarchy of relationship in the sense of descendant / ancestor
Composition is a relationship of the objects – aggregation –
consists / is compound
It is a relationship of the type “has”
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 41 / 48
46. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Composition 1/3
Each person is characterized by attributes of the Person class
name (string)
address (string)
birthDate (date)
graduationDate (date)
Date is characterized by three attributes Datum (class Date)
day (int)
month (int)
year (int)
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 42 / 48
47. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Composition 2/3
#include <string>
class Person {
public:
std::string name;
std::string address;
Date birthDate;
Date graduationDate;
};
class Date {
public:
int day;
int month;
int year;
};
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 43 / 48
48. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Example – Composition 3/3
Person
std::string name std::string address
Date birthDate Date graduationDate
Date birthDate
int month int day
int year
Date graduationDate
int month int day
int year
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 44 / 48
49. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Inheritance vs Composition
Inheritance objects:
Creating a derived class (descendant, subclass, derived class)
Derived class is a specialization of the superclass
May add variables (data fields) Or overlapping variables (names)
Add or modify methods
Unlike composition, inheritance changes the properties of the
objects
New or modified methods
Access to variables and methods of the ancestor (base class,
superclass)
If access is allowed (public/protected)
Composition of objects is made of attributes (data fields) of the
object type
It consists of objects
A distinction between composition an inheritance
„Is” test – a symptom of inheritance (is-a)
„Has” test – a symptom of composition (has)
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 45 / 48
50. Objects and Methods in C++ Relationship Inheritance Polymorphism Inheritance and Composition
Inheritance and Composition – Pitfalls
Excessive usage of composition and also inheritance in cases it is
not needed leads to complicated design
Watch on literal interpretations of the relationship is-a and has,
sometimes it is not even about the inheritance, or composition
E.g., Point2D and Point3D or Circle and Ellipse
Prefer composition and not the inheritance
One of the advantages of inheritance is the polymorphism
Using inheritance violates the encapsulation
Especially with the access rights set to the protected
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 46 / 48
52. Topics Discussed
Topics Discussed
Objects and Methods in C++ – example of 2D matrix
encapsulation
Subscripting operator
Relationship between objects
Aggregation
Composition
Inheritance – properties and usage in C++
Polymorphism – dynamic binding and virtual methods
Inheritance and Composition
Jan Faigl, 2016 BE5B99CPL – Lecture 11: OOP in C++ (Part 2) 48 / 48