The document discusses polymorphism in C++. It shows how declaring functions as virtual in a base class and derived classes allows dynamic binding via pointers to the base class. When calling virtual functions through a base class pointer, the function called is determined by the actual object type, not the pointer type, allowing base class pointers to transparently access overridden functions in derived classes. This allows generic treatment of objects through their common base class.
- Pointers are a powerful feature in C++ that allow dynamic memory allocation but are difficult to master.
- A pointer variable stores the address of a memory location rather than its data value.
- Pointer variables must be initialized before their value (what they point to) can be accessed, otherwise it will cause runtime errors.
This document provides an introduction to C++ programming concepts including variables, data types, constants, and I/O streams. It discusses basic C++ code structure and comments. Integral data types like char, bool, and integers are explained. Floating point types float and double are also introduced. The document demonstrates declaring and initializing variables as well as basic math operations on variables. Constants and the const keyword are described along with the #define preprocessor directive.
The document discusses inheritance in C++ programming. It defines inheritance as an "is-a" relationship between classes where a derived class inherits attributes and behaviors from its base class. Examples are provided of inheritance relationships between vehicles and specific types of vehicles like cars. The advantages of inheritance include code reuse, ability to extend and modify the base class without affecting other classes, and enhancing capabilities by adding new behaviors and customizing the base class.
This document provides an overview of type conversion in C++. It discusses implicit and explicit type conversion, including promotion and demotion. It covers numeric type conversion between integral types like int, float, double, and char. It also discusses enum types in C++ and how to declare and use enumerated variable types. Finally, it briefly introduces relational operators. The key topics covered are type conversion between numeric types, both implicitly through promotion and explicitly through casting, as well as how to define and use enum types for a set of named constants.
The document discusses the use of the this keyword in C++ classes. It explains that this represents the address of the object and can be used explicitly or implicitly. It demonstrates using this to check if a parameter passed to a member function is the object itself, and to access data members. It shows that this->, (*this). and just x are equivalent ways to access data members from within member functions. It also provides an example of using this to check if two references are referring to the same object.
The document discusses C++ arrays, including how to declare and initialize single-dimensional and multi-dimensional arrays, access array elements, and pass arrays to functions. It provides examples of declaring arrays of different data types, initializing arrays using aggregate initialization, and accessing elements within and outside of the declared bounds of the arrays. It also demonstrates some errors that can occur with array declarations and initialization.
- The document discusses structs in C++, including defining structs, initializing struct variables, accessing struct members, passing structs as function parameters, and using pointers to structs.
- Key aspects covered include that structs allow grouping of related data of different types, struct definitions do not allocate memory, and struct variables are initialized and accessed using dot notation. Structs can be passed by value or by reference to functions. Pointers can be used to point to struct variables.
The document discusses functions in C++. It covers function prototypes, definitions, parameters, return types, and passing arguments to functions. Examples are provided of defining, declaring, calling functions, and common errors like missing return types or incorrect parameter types. Predefined functions from headers like sqrt() from cmath and rand() from cstdlib are also demonstrated.
- Pointers are a powerful feature in C++ that allow dynamic memory allocation but are difficult to master.
- A pointer variable stores the address of a memory location rather than its data value.
- Pointer variables must be initialized before their value (what they point to) can be accessed, otherwise it will cause runtime errors.
This document provides an introduction to C++ programming concepts including variables, data types, constants, and I/O streams. It discusses basic C++ code structure and comments. Integral data types like char, bool, and integers are explained. Floating point types float and double are also introduced. The document demonstrates declaring and initializing variables as well as basic math operations on variables. Constants and the const keyword are described along with the #define preprocessor directive.
The document discusses inheritance in C++ programming. It defines inheritance as an "is-a" relationship between classes where a derived class inherits attributes and behaviors from its base class. Examples are provided of inheritance relationships between vehicles and specific types of vehicles like cars. The advantages of inheritance include code reuse, ability to extend and modify the base class without affecting other classes, and enhancing capabilities by adding new behaviors and customizing the base class.
This document provides an overview of type conversion in C++. It discusses implicit and explicit type conversion, including promotion and demotion. It covers numeric type conversion between integral types like int, float, double, and char. It also discusses enum types in C++ and how to declare and use enumerated variable types. Finally, it briefly introduces relational operators. The key topics covered are type conversion between numeric types, both implicitly through promotion and explicitly through casting, as well as how to define and use enum types for a set of named constants.
The document discusses the use of the this keyword in C++ classes. It explains that this represents the address of the object and can be used explicitly or implicitly. It demonstrates using this to check if a parameter passed to a member function is the object itself, and to access data members. It shows that this->, (*this). and just x are equivalent ways to access data members from within member functions. It also provides an example of using this to check if two references are referring to the same object.
The document discusses C++ arrays, including how to declare and initialize single-dimensional and multi-dimensional arrays, access array elements, and pass arrays to functions. It provides examples of declaring arrays of different data types, initializing arrays using aggregate initialization, and accessing elements within and outside of the declared bounds of the arrays. It also demonstrates some errors that can occur with array declarations and initialization.
- The document discusses structs in C++, including defining structs, initializing struct variables, accessing struct members, passing structs as function parameters, and using pointers to structs.
- Key aspects covered include that structs allow grouping of related data of different types, struct definitions do not allocate memory, and struct variables are initialized and accessed using dot notation. Structs can be passed by value or by reference to functions. Pointers can be used to point to struct variables.
The document discusses functions in C++. It covers function prototypes, definitions, parameters, return types, and passing arguments to functions. Examples are provided of defining, declaring, calling functions, and common errors like missing return types or incorrect parameter types. Predefined functions from headers like sqrt() from cmath and rand() from cstdlib are also demonstrated.
This document provides an overview of classes in C++. It begins with definitions and concepts related to classes, such as encapsulation and user-defined types. It then provides examples of declaring and defining a simple Time class with attributes like hours, minutes, seconds and methods to set, get, print and change the time. The document also discusses class members, access specifiers, constructors, pointers and references to class objects, and getter and setter methods. It concludes with brief mentions of utility functions, separating interface from implementation, and organizing classes across header and source files.
The document discusses various control structures in C++ programming including if/else statements, while loops, do/while loops, and for loops. It provides code examples of each control structure and the output of executing the code. It also demonstrates the use of break and continue statements within loops.
The document discusses arrays, strings, and functions in C programming. It begins by explaining how to initialize and access 2D arrays, including examples to take input from the user and store it in a 2D array. It then discusses initializing and accessing multidimensional arrays. Next, it covers array contiguous memory and the advantages and limitations of arrays. Finally, it discusses common programming errors related to array construction for real-time applications.
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...ssuserd6b1fd
C programming language notes for beginners and Collage students. Written for beginners. Colored graphics. Function by Function explanation with complete examples. Well commented examples. Illustrations are made available for data dealing at memory level.
03 of 03 parts
Get Part 1 from https://www.slideshare.net/ArunUmrao/notes-for-c-programming-for-bca-mca-b-sc-msc-be-amp-btech-1st-year-1
Get Part 2 from https://www.slideshare.net/ArunUmrao/notes-for-c-programming-for-bca-mca-b-sc-msc-be-amp-btech-1st-year-2
C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, while a static type system prevents unintended operations. C provides constructs that map efficiently to typical machine instructions and has found lasting use in applications previously coded in assembly language. Such applications include operating systems and various application software for computers, from supercomputers to PLCs and embedded system.
The document discusses arrays in C++. It explains one-dimensional and two-dimensional arrays, how to declare, initialize, and access elements of arrays. Key points include arrays storing a collection of like-typed data, being indexed starting from 0, initializing during declaration, and accessing two-dimensional array elements requiring row and column indices. Examples are provided to demonstrate array concepts.
The document contains 32 C programming questions and their multiple choice answers. The questions cover topics like operators, control flow, functions, arrays, structures, pointers and macros. Some key questions involve logical operators, recursion, structures, linked lists and string manipulation.
2 BytesC++ course_2014_c9_ pointers and dynamic arrays kinan keshkeh
The document discusses pointers and arrays in C++. It begins with definitions of pointers, including that a pointer stores a memory address and pointer variable declarations. It then covers various pointer topics like dereferencing pointers, passing pointers to functions, and returning pointers from functions. The document also discusses dynamic memory allocation using pointers, pointer arithmetic, multi-dimensional dynamic arrays, pointers and classes, and the this pointer. Code examples are provided to illustrate many of the concepts. Homework problems at the end involve writing functions to insert into and print a linked list of vehicle records, search the list, compare dates, and print records before a given date.
This document discusses pointers in C++. It defines pointers as variables that store memory addresses and uses the address of (&) and indirection/dereference (*) operators. It provides several examples demonstrating how to declare pointer variables, assign the addresses of non-pointer variables to pointers, and use pointers to access and modify variable values indirectly through memory addresses. Key points covered include declaring pointer data types, assigning addresses to pointers using &, accessing values at addresses using *, and chaining pointers by assigning the address of one pointer to another pointer.
Presented at DevWeek (25th March 2015)
These days, testing is considered a sexy topic for programmers. Who’d have thought it? But what makes for good unit tests (GUTs)? There’s more to effective unit testing than just knowing the assertion syntax of a testing framework.
Testing represents a form of communication and, as such, it offers multiple levels and forms of feedback, not just basic defect detection. Effective unit testing requires an understanding of what forms of feedback and communication are offered by tests, and what styles encourage or discourage such qualities.
What style of test partitioning is most common, and yet scales poorly and is ineffective at properly expressing the behaviour of a class or component? What styles, tricks and tips can be used to make tests more specification-like and can scale as the codebase grows?
This session will address these questions and outline exactly what makes a good unit test.
02 of 03 parts
Get Part 1 from https://www.slideshare.net/ArunUmrao/notes-for-c-programming-for-bca-mca-b-sc-msc-be-amp-btech-1st-year-1
Get Part 3 from https://www.slideshare.net/ArunUmrao/notes-for-c-programming-for-bca-mca-b-sc-msc-be-amp-btech-1st-year-3
C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, while a static type system prevents unintended operations. C provides constructs that map efficiently to typical machine instructions and has found lasting use in applications previously coded in assembly language. Such applications include operating systems and various application software for computers, from supercomputers to PLCs and embedded system.
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...ssuserd6b1fd
C++ programming language notes for beginners and Collage students. Written for beginners. Colored graphics. Function by Function explanation with complete examples. Well commented examples. Illustrations are made available for data dealing at memory level.
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...ssuserd6b1fd
C programming language notes for beginners and Collage students. Written for beginners. Colored graphics. Function by Function explanation with complete examples. Well commented examples. Illustrations are made available for data dealing at memory level.
Functional programming, though far from new, has gained much traction recently. Functional programming characteristics have started to appear in the PHP world, too. Microframeworks including Silex and Slim, middleware architectures (Stack) and even standards (PSR-7) rely on concepts such as lambdas, referential transparency and immutability, all of which come from functional programming.
I’ll give you a crash course in Erlang, a pragmatic functional language to make you feel familiar with the functional paradigm. By comparing code samples between Erlang and PHP, you’ll find out how and why you should employ functional programming in your PHP applications. You’ll see that functional programming is nothing to be scared of. On the contrary, understanding its concepts broadens your programming horizon and provides you with valuable solutions to your problems.
The document provides an overview of variables, data types, variable scope, strings, arrays, control structures, functions, operators, and challenges for Arduino programming. It defines integer and character variables, describes global and local variable scope, demonstrates how to define and access string and array elements, lists common control structures like if/else and for loops, shows how to define and call functions, and gives examples of arithmetic, comparison, boolean, and bitwise operators. The challenges section provides examples of taking user input, creating arrays, checking even/odd numbers, calculating circle circumference, and generating ASCII art.
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...ssuserd6b1fd
C programming language notes for beginners and Collage students. Written for beginners. Colored graphics. Function by Function explanation with complete examples. Well commented examples. Illustrations are made available for data dealing at memory level.
Presented at ACCU Oxford (14th September 2015)
Functional C++? As opposed to what — dysfunctional? Well, kind of, yeah. Sure, in C++ the principal unit of composition is called a function, but that doesn't mean it's a functional language. And the idea of restricting mutability of state gets a nod with const, but it's a nod not a hug. And the STL shows influences of functional programming, although it falls short of being compositional. And, yes, sure, C++11 has lambdas, but then again, these days, who doesn't? Lambda calculus was invented in the 1930s.
This talk looks at how to express functional programming ideas in (post)modern C++ in a way that can be considered idiomatic to C++, rather than trying to use the power of overloading and meta-programming to pretend C++ is Haskell or Lisp. In short, immutability beyond const and into shared and persistent data structures, concurrency beyond threading and locks, and thinking about functions as transformations and units of composition rather than actions.
The document discusses the Falcon programming language, noting its open source, simple, fast and powerful nature. It highlights features of Falcon like full support for multithreading, support for coroutines, and faster speed compared to Python. Examples are provided of Falcon's syntax for variables, data types, operators, functions, and control flow structures that are similar to other languages like C/C++ and Lua.
Macros and templates in C++ differ in that macros do not perform type checking on parameters and can cause unexpected behavior when parameters are modified, while templates allow the compiler to verify type compatibility and do not have issues with parameter modification. Macros are expanded by the preprocessor before compilation, so errors refer to the expanded code rather than the macro definition. Templates undergo type checking and retain the template parameter types.
Polymorphism allows objects of different types to be treated as a common type. It is implemented by adding a virtual pointer (VPTR) to objects that points to a virtual function table (VTABLE) containing pointers to each object's virtual methods. This allows calling the same method on different types of objects in a polymorphic way while executing the correct implementation based on the object's actual type at runtime.
This document provides an overview of classes in C++. It begins with definitions and concepts related to classes, such as encapsulation and user-defined types. It then provides examples of declaring and defining a simple Time class with attributes like hours, minutes, seconds and methods to set, get, print and change the time. The document also discusses class members, access specifiers, constructors, pointers and references to class objects, and getter and setter methods. It concludes with brief mentions of utility functions, separating interface from implementation, and organizing classes across header and source files.
The document discusses various control structures in C++ programming including if/else statements, while loops, do/while loops, and for loops. It provides code examples of each control structure and the output of executing the code. It also demonstrates the use of break and continue statements within loops.
The document discusses arrays, strings, and functions in C programming. It begins by explaining how to initialize and access 2D arrays, including examples to take input from the user and store it in a 2D array. It then discusses initializing and accessing multidimensional arrays. Next, it covers array contiguous memory and the advantages and limitations of arrays. Finally, it discusses common programming errors related to array construction for real-time applications.
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...ssuserd6b1fd
C programming language notes for beginners and Collage students. Written for beginners. Colored graphics. Function by Function explanation with complete examples. Well commented examples. Illustrations are made available for data dealing at memory level.
03 of 03 parts
Get Part 1 from https://www.slideshare.net/ArunUmrao/notes-for-c-programming-for-bca-mca-b-sc-msc-be-amp-btech-1st-year-1
Get Part 2 from https://www.slideshare.net/ArunUmrao/notes-for-c-programming-for-bca-mca-b-sc-msc-be-amp-btech-1st-year-2
C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, while a static type system prevents unintended operations. C provides constructs that map efficiently to typical machine instructions and has found lasting use in applications previously coded in assembly language. Such applications include operating systems and various application software for computers, from supercomputers to PLCs and embedded system.
The document discusses arrays in C++. It explains one-dimensional and two-dimensional arrays, how to declare, initialize, and access elements of arrays. Key points include arrays storing a collection of like-typed data, being indexed starting from 0, initializing during declaration, and accessing two-dimensional array elements requiring row and column indices. Examples are provided to demonstrate array concepts.
The document contains 32 C programming questions and their multiple choice answers. The questions cover topics like operators, control flow, functions, arrays, structures, pointers and macros. Some key questions involve logical operators, recursion, structures, linked lists and string manipulation.
2 BytesC++ course_2014_c9_ pointers and dynamic arrays kinan keshkeh
The document discusses pointers and arrays in C++. It begins with definitions of pointers, including that a pointer stores a memory address and pointer variable declarations. It then covers various pointer topics like dereferencing pointers, passing pointers to functions, and returning pointers from functions. The document also discusses dynamic memory allocation using pointers, pointer arithmetic, multi-dimensional dynamic arrays, pointers and classes, and the this pointer. Code examples are provided to illustrate many of the concepts. Homework problems at the end involve writing functions to insert into and print a linked list of vehicle records, search the list, compare dates, and print records before a given date.
This document discusses pointers in C++. It defines pointers as variables that store memory addresses and uses the address of (&) and indirection/dereference (*) operators. It provides several examples demonstrating how to declare pointer variables, assign the addresses of non-pointer variables to pointers, and use pointers to access and modify variable values indirectly through memory addresses. Key points covered include declaring pointer data types, assigning addresses to pointers using &, accessing values at addresses using *, and chaining pointers by assigning the address of one pointer to another pointer.
Presented at DevWeek (25th March 2015)
These days, testing is considered a sexy topic for programmers. Who’d have thought it? But what makes for good unit tests (GUTs)? There’s more to effective unit testing than just knowing the assertion syntax of a testing framework.
Testing represents a form of communication and, as such, it offers multiple levels and forms of feedback, not just basic defect detection. Effective unit testing requires an understanding of what forms of feedback and communication are offered by tests, and what styles encourage or discourage such qualities.
What style of test partitioning is most common, and yet scales poorly and is ineffective at properly expressing the behaviour of a class or component? What styles, tricks and tips can be used to make tests more specification-like and can scale as the codebase grows?
This session will address these questions and outline exactly what makes a good unit test.
02 of 03 parts
Get Part 1 from https://www.slideshare.net/ArunUmrao/notes-for-c-programming-for-bca-mca-b-sc-msc-be-amp-btech-1st-year-1
Get Part 3 from https://www.slideshare.net/ArunUmrao/notes-for-c-programming-for-bca-mca-b-sc-msc-be-amp-btech-1st-year-3
C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, while a static type system prevents unintended operations. C provides constructs that map efficiently to typical machine instructions and has found lasting use in applications previously coded in assembly language. Such applications include operating systems and various application software for computers, from supercomputers to PLCs and embedded system.
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...ssuserd6b1fd
C++ programming language notes for beginners and Collage students. Written for beginners. Colored graphics. Function by Function explanation with complete examples. Well commented examples. Illustrations are made available for data dealing at memory level.
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...ssuserd6b1fd
C programming language notes for beginners and Collage students. Written for beginners. Colored graphics. Function by Function explanation with complete examples. Well commented examples. Illustrations are made available for data dealing at memory level.
Functional programming, though far from new, has gained much traction recently. Functional programming characteristics have started to appear in the PHP world, too. Microframeworks including Silex and Slim, middleware architectures (Stack) and even standards (PSR-7) rely on concepts such as lambdas, referential transparency and immutability, all of which come from functional programming.
I’ll give you a crash course in Erlang, a pragmatic functional language to make you feel familiar with the functional paradigm. By comparing code samples between Erlang and PHP, you’ll find out how and why you should employ functional programming in your PHP applications. You’ll see that functional programming is nothing to be scared of. On the contrary, understanding its concepts broadens your programming horizon and provides you with valuable solutions to your problems.
The document provides an overview of variables, data types, variable scope, strings, arrays, control structures, functions, operators, and challenges for Arduino programming. It defines integer and character variables, describes global and local variable scope, demonstrates how to define and access string and array elements, lists common control structures like if/else and for loops, shows how to define and call functions, and gives examples of arithmetic, comparison, boolean, and bitwise operators. The challenges section provides examples of taking user input, creating arrays, checking even/odd numbers, calculating circle circumference, and generating ASCII art.
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...ssuserd6b1fd
C programming language notes for beginners and Collage students. Written for beginners. Colored graphics. Function by Function explanation with complete examples. Well commented examples. Illustrations are made available for data dealing at memory level.
Presented at ACCU Oxford (14th September 2015)
Functional C++? As opposed to what — dysfunctional? Well, kind of, yeah. Sure, in C++ the principal unit of composition is called a function, but that doesn't mean it's a functional language. And the idea of restricting mutability of state gets a nod with const, but it's a nod not a hug. And the STL shows influences of functional programming, although it falls short of being compositional. And, yes, sure, C++11 has lambdas, but then again, these days, who doesn't? Lambda calculus was invented in the 1930s.
This talk looks at how to express functional programming ideas in (post)modern C++ in a way that can be considered idiomatic to C++, rather than trying to use the power of overloading and meta-programming to pretend C++ is Haskell or Lisp. In short, immutability beyond const and into shared and persistent data structures, concurrency beyond threading and locks, and thinking about functions as transformations and units of composition rather than actions.
The document discusses the Falcon programming language, noting its open source, simple, fast and powerful nature. It highlights features of Falcon like full support for multithreading, support for coroutines, and faster speed compared to Python. Examples are provided of Falcon's syntax for variables, data types, operators, functions, and control flow structures that are similar to other languages like C/C++ and Lua.
Macros and templates in C++ differ in that macros do not perform type checking on parameters and can cause unexpected behavior when parameters are modified, while templates allow the compiler to verify type compatibility and do not have issues with parameter modification. Macros are expanded by the preprocessor before compilation, so errors refer to the expanded code rather than the macro definition. Templates undergo type checking and retain the template parameter types.
Polymorphism allows objects of different types to be treated as a common type. It is implemented by adding a virtual pointer (VPTR) to objects that points to a virtual function table (VTABLE) containing pointers to each object's virtual methods. This allows calling the same method on different types of objects in a polymorphic way while executing the correct implementation based on the object's actual type at runtime.
The document discusses different types of polymorphism in C++, including runtime polymorphism using virtual methods and compile-time polymorphism using templates. It notes that templates can provide polymorphism without the performance overhead of virtual methods, but may increase compile times. Both techniques have advantages and can be combined effectively in some cases to leverage their respective benefits.
This document discusses polymorphism in programming. It defines polymorphism as allowing one interface to have multiple implementations so that a method can do different things based on the object. There are two main types of polymorphism in Java: runtime polymorphism (using method overriding) and compile-time polymorphism (using method overloading). Polymorphism is useful because it allows programming in a general way rather than specific, lets programs process objects that share a superclass, and makes systems extensible with new classes that require minimal code changes.
This document discusses polymorphism as part of a preformulation study seminar. It defines polymorphism as the ability of a substance to exist in two or more crystalline forms that have different molecular arrangements. The key points covered include:
- The need to study polymorphism to select the most stable and soluble form for formulations. Metastable forms often have better bioavailability.
- Various methods to identify and characterize polymorphs such as X-ray diffraction, thermal analysis techniques like DSC and TGA, and microscopy.
- Factors that can influence polymorphic transitions like temperature, humidity, solvents, grinding, and compression during tableting.
- The importance of understanding polymorphism for properties like
Polymorphism refers to an object's ability to take on multiple forms. In object-oriented programming, polymorphism occurs when an entity such as a variable, function, or object can have more than one form. There are two main types of polymorphism: compile-time polymorphism (such as function and operator overloading) and runtime polymorphism (using virtual functions). Polymorphism allows programmers to work with general classes and let the runtime system handle the specific types, providing flexibility.
Polymorphism refers to the ability of an object to take on multiple forms. In Java, polymorphism occurs when a reference variable can refer to objects of different subclasses. This allows methods to behave differently depending on the actual object being referred to. There are three main forms of polymorphism in Java: method overriding, abstract method implementation, and interface implementation. Polymorphism provides benefits like simplicity and extensibility by allowing code to interact generically with base types and subclasses without needing specific type details.
How to Make Awesome SlideShares: Tips & TricksSlideShare
Turbocharge your online presence with SlideShare. We provide the best tips and tricks for succeeding on SlideShare. Get ideas for what to upload, tips for designing your deck and more.
SlideShare is a global platform for sharing presentations, infographics, videos and documents. It has over 18 million pieces of professional content uploaded by experts like Eric Schmidt and Guy Kawasaki. The document provides tips for setting up an account on SlideShare, uploading content, optimizing it for searchability, and sharing it on social media to build an audience and reputation as a subject matter expert.
C++: Constructor, Copy Constructor and Assignment operatorJussi Pohjolainen
The document discusses various C++ constructors including default constructors, initialization lists, copy constructors, assignment operators, and destructors. It provides examples of how to properly implement these special member functions to avoid problems like shallow copying and double deletes.
Create the equivalent of a four function calculator. The program should request the user to enter a number, an operator, and another number. carry out the specified arithmetical operation: adding, subtracting, multiplying, or dividing the two numbers. (Using switch statement ).ThesisScientist.com
This document provides an overview and introduction to building a basic fraction calculator app in Objective-C. It begins with an overview of the project architecture using the MVC pattern with a Fraction model class to represent fractions, a Calculator class to perform operations, and a ViewController class to manage the user interface. It then details the implementation of each class, including the Fraction class with methods for creating, modifying, and performing operations on fractions, the Calculator class for setting operands and performing operations, and the ViewController class for handling user interface events and updating the display.
The document contains examples demonstrating various object-oriented programming concepts in C++ including constructors, destructors, inheritance, polymorphism, operator overloading, templates, and more. Each example includes the code for a concept, the output of running the code, and a brief description.
The document discusses inheritance and polymorphism in object-oriented programming. It defines inheritance as deriving a new subclass from a base class, creating a class hierarchy that shares code and interface. Polymorphism allows calling the same function on objects of different types and having the function call the appropriate implementation for that type. The document uses examples like student subclasses and shape classes to demonstrate inheritance and polymorphism implementation in C++ using virtual functions for dynamic binding.
The document discusses functions in C programming. It provides examples of defining functions with parameters and return types, calling functions by passing arguments, using header files to declare functions, and recursion. It shows functions being defined and called to perform tasks like calculating factorials, displaying prices based on hotel rates and nights, and converting numbers to binary. Functions allow breaking programs into smaller, reusable components.
CONSTRUCTORS, DESTRUCTORS AND OPERATOR OVERLOADING.pptxDeepasCSE
Certainly, here's a brief explanation of constructors, destructors, and operator overloading without using code:
Constructors: Constructors are special methods used to initialize objects of a class. They set the initial state of an object when it is created.
Destructors: Destructors are special methods used to clean up resources and perform necessary cleanup when an object is no longer needed or goes out of scope. They ensure proper resource management.
Operator Overloading: Operator overloading is a feature that allows you to define custom behaviors for operators such as +, -, *, /, etc., when they are applied to objects of your class. It enables you to work with objects in a way that is meaningful for your specific class.
Constructors can be of different types:
Default Constructors: Initialize objects with default values.
Parameterized Constructors: Accept arguments to initialize objects with specific values.
Copy Constructors: Create a new object as a copy of an existing object.
Constructor Overloading: A class can have multiple constructors with different parameter lists, providing flexibility in object initialization.
Destructors are executed automatically when an object is destroyed. They are essential for releasing resources like memory, file handles, or network connections, ensuring proper cleanup and preventing resource leaks.
Operator overloading enables you to define how operators work with objects of your class. For instance, you can specify what the + operator does when applied to two objects of your class, allowing for custom operations that make sense in the context of your class's functionality.
In summary, constructors initialize objects, destructors handle cleanup, and operator overloading allows custom operations with operators when working with objects. These features are crucial for building custom classes in object-oriented programming.
1. The document provides an introduction to object-oriented programming concepts and C++ programming.
2. It discusses the need for OOP over procedure-oriented programming and highlights the differences between the two approaches.
3. The document then covers basic C++ concepts like data types, functions, classes, inheritance and polymorphism through examples.
Virtual functions allow functions in derived classes to override functions in base classes. When a base class pointer points to a derived class object, calling a virtual function through the pointer will call the derived class's version. This allows the same interface to behave differently based on the actual object. Virtual functions are useful for mathematical operations, where a base class defines an interface and derived classes perform specific calculations like addition, subtraction etc. depending on the object type pointed to by the base class pointer.
This document provides information about functions in C programming. It defines a function as a block of code that performs a specific task and can be reused. The general form of a function definition includes the return type, function name, parameters, and function body. Functions allow breaking a large, complex program into smaller, modular sub-programs. Parameters are used to pass values between the calling function and the called function. Variables have local scope and are only accessible within the function they are defined, so parameters must be explicitly passed between functions. Functions can return values to the calling function using the return statement.
In object-oriented programming, a class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods).
The document discusses object-oriented programming concepts like inheritance, base classes, and derived classes. It provides code examples to illustrate inheritance relationships between classes like Point, Circle, and Cylinder. The code defines base classes like Point and derived classes like Circle that inherit properties and methods from their base classes. Tests are provided to create objects from derived classes and demonstrate inherited functionality.
The document discusses object-oriented programming concepts like inheritance, base classes, and derived classes. It provides code examples to illustrate inheritance relationships between classes like Point, Circle, and Cylinder. The code defines base classes like Point and derived classes like Circle that inherit properties and methods from their base classes. The examples show how to define constructors, properties, and methods in base and derived classes and call methods on derived class objects to demonstrate polymorphism.
The composite pattern allows objects to be composed into tree structures to represent part-whole hierarchies. It allows clients to treat individual objects and compositions uniformly. The example shows how shapes like lines and rectangles can be composed into pictures. Individual shapes are leaf classes while pictures are composite classes that can group shapes together and be treated the same way as individual shapes by clients.
The document discusses object-oriented programming concepts like polymorphism. It includes:
- An introduction to polymorphism and how it allows programs to handle related classes generically and be easily extensible.
- Examples of polymorphism including a shape hierarchy with classes like Quadrilateral, Rectangle, etc. and a space object hierarchy with classes that all implement a DrawYourself method.
- Details about abstract classes and how they provide base classes that concrete classes inherit from while requiring the concrete classes to implement abstract methods and properties.
- A case study demonstrating inheritance and polymorphism using abstract base class Shape and concrete classes Point2, Circle2, and Cylinder2 that inherit from Shape.
The document discusses object-oriented programming concepts like polymorphism. It includes:
- An introduction to polymorphism and how it allows programs to handle related classes generically and be easily extensible.
- Examples of polymorphism including a shape hierarchy with classes like Square and Circle overriding a perimeter method, and a space object hierarchy with classes overriding a DrawYourself method.
- Details about abstract classes and how they provide base classes that concrete classes inherit from, including an example abstract Shape class and derived Point2, Circle2 classes.
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Mohammad Shaker
In my MSc. thesis, I have re-tackled the problem of procedurally generating content for physics-based games I have previously investigated in my BSc. graduation thesis. This time around I propose two novel methods: the first is projection based for faster generation of physics-based games content. The other, The Progressive Generation, is a generic, wide-range, across genre, customisable with playability check method all bundled in a fast progressive approach. This new method is applied on two completely different games: NEXT And Cut the Rope.
Short, Matters, Love - Passioneers Event 2015Mohammad Shaker
Short, Matters, Love is a presentation I prepared for freshmen students at the Faculty of Information Technology in Damascus, Syria organised by Passioneers - 2015
This document discusses Unity3D and game development. It provides an overview of Unity3D and other game engines like Unreal Engine, comparing their features and costs. Examples are given of popular games made with each engine. The document also lists several games the author has made using Unity3D and provides some additional resources and references.
The document discusses various topics related to mobile application design including cloud interaction, Android touch and gesture interaction, UI element sizing, screen sizes, changing orientation, retaining objects during configuration changes, multi-device targeting, and wearables. It provides examples and guidelines for designing applications that can adapt to different devices and configurations.
The document discusses principles of interaction design, color theory, and game design. It covers topics like primary and secondary colors, color harmonies, using color to attract attention and set mood, the importance of white space and negative space in design, and how games like Journey, Fez, Luftrausers, Monument Valley, Ori and the Blind Forest, and Limbo effectively use techniques like the rule of thirds, establishing a sense of goal, and game feel.
This document discusses various topics related to typography including letter shapes like the letter "T", how words for concepts like water have evolved across languages, symbols for ideas like fish, and different writing styles such as styles that would be impossible to write. It examines typography from multiple perspectives like shapes, language evolution, symbols, and stylization.
Interaction Design L04 - Materialise and CouplingMohammad Shaker
This document discusses various aspects of coupling and interaction design in mobile applications. It addresses good and bad examples of coupling on Android and iOS, such as how apps are switched between. It also discusses using accurate text to represent backend processes, and using faster progress bars to reduce cognitive load on users. Visualizations are suggested to improve progress bars.
The document discusses various options for storing data in an Android application including SharedPreferences for simple key-value pairs, internal storage for private files, external storage for public files, SQLite databases for structured data, network connections for storing data on a web server, and ContentProviders for sharing data between applications. It provides details on using SharedPreferences, internal SQLite databases stored in the application's files, and ContentProviders for sharing Contacts data with other apps.
The document discusses various interaction design concepts in Android including toasts, notifications, threads, broadcast receivers, and alarms. It provides code examples for creating toasts, setting notification priorities, and scheduling alarms to fire at boot or at specific times using the AlarmManager. Broadcast receivers can be used to set alarms during device boot by listening for the BOOT_COMPLETED intent filter and implementing the onReceive callback.
This document provides an overview of various mobile development technologies and frameworks including Cloud, iOS, Android, iPad Pro, Xcode, Model-View-Controller (MVC), C, Objective-C, Foundation data types, functions calls, Swift, iOS Dev Center, coordinate systems, Windows Phone, .NET support, MVVM, binding, WebClient, and navigation. It also mentions tools like Expression Blend and frameworks like jQuery Mobile, PhoneGap, Sencha Touch, and Xamarin.
This document discusses various topics related to mobile app design including user experience (UX), user interface (UI), interaction design, user constraints like limited data/battery and screen size, and using context like location to improve the user experience. It provides examples of a pizza ordering app and making ATM machines smarter. It also covers design patterns and principles like focusing on user needs and testing designs through feedback.
This document discusses principles of visual organization and responsive grid systems for web design. It mentions laws of proximity, similarity, common fate, continuity, closure, and symmetry which help organize visual elements. It also discusses column-based and ratio-based grid systems as well as responsive grid systems that adapt to different screen widths, citing examples from Pinterest, Bootstrap, and the website www.mohammadshaker.com which demonstrates responsive design.
This document provides an overview comparison of key aspects of mobile app development for iOS and Android platforms. It discusses differences in app store policies, pricing, monetization options like ads and in-app purchases, development tools including engines like Unity and Unreal, and the publishing process. Key points mentioned include Android apps averaging over 2.5x the price of similar iOS apps, Apple's restrictive app review policies, the 70/30 revenue split in Google Play Store, and tools for user testing and publishing on both platforms. It also shares stats on the revenue and success of specific apps like Monument Valley.
The document discusses various ways to implement cloud functionality in Android applications using services like Parse and Android Backup. It provides code examples for backing up app data to the cloud using Android Backup, setting up a backend using Parse, pushing notifications with Parse, and performing analytics tracking with Parse.
This document discusses several topics related to developing Android apps including:
1. Adding markers to maps by setting an onMapClickListener and adding a MarkerOptions to the clicked location.
2. Signing into apps with Google accounts using the Google Identity API.
3. Following Material Design guidelines for visual style and user interfaces.
4. Maintaining multiple APK versions and using OpenGL ES for games.
This document discusses various techniques for styling Android applications including adding styles, overriding styles, using themes, custom backgrounds, nine-patch images, and animations. It provides links to tutorials and documentation on animating views with zoom animations and other motion effects.
This document provides information about various Android development topics including:
- ListAdapters and mapping models to UI using an MVVM-like pattern
- Creating custom lists
- Starting a new activity using an Intent and passing data between activities
- Understanding the Android activity lifecycle and methods like onPause() and onResume()
- Handling configuration changes that recreate the activity
- Working with permissions
The document discusses common patterns for working with lists, launching new screens, and handling activity state changes. It also provides code examples for starting a new activity, passing data between activities, and handling the activity lifecycle callbacks.
This document provides an overview of various topics related to mobile application development including cloud computing, interaction design, Android, iOS, web technologies like HTML5 and JavaScript, programming languages like Java and Objective-C, frameworks, gaming, user experience design, and more. It discusses tools for Android development and covers basics of creating an Android app like setting up the IDE, creating the UI, adding interactivity, debugging, and referencing documentation.
Embedded machine learning-based road conditions and driving behavior monitoringIJECEIAES
Car accident rates have increased in recent years, resulting in losses in human lives, properties, and other financial costs. An embedded machine learning-based system is developed to address this critical issue. The system can monitor road conditions, detect driving patterns, and identify aggressive driving behaviors. The system is based on neural networks trained on a comprehensive dataset of driving events, driving styles, and road conditions. The system effectively detects potential risks and helps mitigate the frequency and impact of accidents. The primary goal is to ensure the safety of drivers and vehicles. Collecting data involved gathering information on three key road events: normal street and normal drive, speed bumps, circular yellow speed bumps, and three aggressive driving actions: sudden start, sudden stop, and sudden entry. The gathered data is processed and analyzed using a machine learning system designed for limited power and memory devices. The developed system resulted in 91.9% accuracy, 93.6% precision, and 92% recall. The achieved inference time on an Arduino Nano 33 BLE Sense with a 32-bit CPU running at 64 MHz is 34 ms and requires 2.6 kB peak RAM and 139.9 kB program flash memory, making it suitable for resource-constrained embedded systems.
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.
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...IJECEIAES
Climate change's impact on the planet forced the United Nations and governments to promote green energies and electric transportation. The deployments of photovoltaic (PV) and electric vehicle (EV) systems gained stronger momentum due to their numerous advantages over fossil fuel types. The advantages go beyond sustainability to reach financial support and stability. The work in this paper introduces the hybrid system between PV and EV to support industrial and commercial plants. This paper covers the theoretical framework of the proposed hybrid system including the required equation to complete the cost analysis when PV and EV are present. In addition, the proposed design diagram which sets the priorities and requirements of the system is presented. The proposed approach allows setup to advance their power stability, especially during power outages. The presented information supports researchers and plant owners to complete the necessary analysis while promoting the deployment of clean energy. The result of a case study that represents a dairy milk farmer supports the theoretical works and highlights its advanced benefits to existing plants. The short return on investment of the proposed approach supports the paper's novelty approach for the sustainable electrical system. In addition, the proposed system allows for an isolated power setup without the need for a transmission line which enhances the safety of the electrical network
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...University of Maribor
Slides from talk presenting:
Aleš Zamuda: Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapter and Networking.
Presentation at IcETRAN 2024 session:
"Inter-Society Networking Panel GRSS/MTT-S/CIS
Panel Session: Promoting Connection and Cooperation"
IEEE Slovenia GRSS
IEEE Serbia and Montenegro MTT-S
IEEE Slovenia CIS
11TH INTERNATIONAL CONFERENCE ON ELECTRICAL, ELECTRONIC AND COMPUTING ENGINEERING
3-6 June 2024, Niš, Serbia
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.
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsVictor Morales
K8sGPT is a tool that analyzes and diagnoses Kubernetes clusters. This presentation was used to share the requirements and dependencies to deploy K8sGPT in a local environment.
6th International Conference on Machine Learning & Applications (CMLA 2024)ClaraZara1
6th International Conference on Machine Learning & Applications (CMLA 2024) will provide an excellent international forum for sharing knowledge and results in theory, methodology and applications of on Machine Learning & Applications.
3. Polymorphism
•Polymorphism
–“Multi-form”
–Enables us to program “in general”
–Write program that process object of classes that are part of the same class hierarchy as if they are all objects of the hierarchy's base class
–Makes programs extensible
•Add new classes (new classes to the hierarchy) with no modification
4. Polymorphism
#ifndefPOINT_H
#definePOINT_H
classPoint {
public:
Point( int= 0, int= 0 ); // default constructor
voidsetX( int); // set x in coordinate pair
intgetX() const; // return x from coordinate pair
voidsetY( int); // set y in coordinate pair
intgetY() const; // return y from coordinate pair
voidprint() const; // output Point object
private:
intx; // x part of coordinate pair
inty; // y part of coordinate pair
}; // end class Point
#endif
#include"point.h"// Point class definition
Point::Point( intxValue, intyValue ): x( xValue ), y( yValue ){}
voidPoint::setX( intxValue ){ x = xValue; }
intPoint::getX() const{ returnx;}
voidPoint::setY( intyValue ){ y = yValue;}
intPoint::getY() const{ returny;}
voidPoint::print() const
{ cout << '['<< getX() << ", "<< getY() << ']‘;}
6. Polymorphism
void main()
{
Point point( 30, 50 ); Point *pointPtr = 0; // base-class pointer
Circle circle( 120, 89, 2.7 ); Circle *circlePtr = 0; // derived-class pointer
// set floating-point numeric formatting
cout << fixed << setprecision( 2 );
// output objects point and circle
cout << "Print point and circle objects:” << "nPoint: ";
point.print(); // invokes Point's print
cout << "nCircle: ";
circle.print(); // invokes Circle's print
pointPtr = &point;
cout << "nnCalling print with base-class pointer to “ << "nbase-class object invokes base-class print “<< "function:n";
pointPtr->print(); // invokes Point's print
circlePtr = &circle;
cout << "nnCalling print with derived-class pointer to “ << "nderived-class object invokes derived-class “ << "print function:n";
circlePtr->print(); // invokes Circle's print
// aim base-class pointer at derived-class object and print
pointPtr = &circle;
cout << "nnCalling print with base-class pointer to “ << "derived-class objectninvokes base-class print “ <<
"function on that derived-class objectn";
pointPtr->print(); // invokes Point's print
cout << endl;
}
Print point and circle objects:
Point: [30, 50]
Circle: center = [120, 89]; radius = 2.7
Calling print with base-class pointer to
base-class object invokes base-class print function:
[30, 50]
Calling print with derived-class pointer to
derived-class object invokes derived-class print function:
center = [120, 89]; radius = 2.7
Calling print with base-class pointer to derived-class object
invokes base-class print function on that derived-class object
[120, 89]
Press any key to continue
7. Polymorphism
void main()
{
Point point( 30, 50 ); Point *pointPtr = 0; // base-class pointer
Circle circle( 120, 89, 2.7 ); Circle *circlePtr = 0; // derived-class pointer
// set floating-point numeric formatting
cout << fixed << setprecision( 2 );
// output objects point and circle
cout << "Print point and circle objects:” << "nPoint: ";
point.print(); // invokes Point's print
cout << "nCircle: ";
circle.print(); // invokes Circle's print
pointPtr = &point;
cout << "nnCalling print with base-class pointer to “ << "nbase-class object invokes base-class print “<< "function:n";
pointPtr->print(); // invokes Point's print
circlePtr = &circle;
cout << "nnCalling print with derived-class pointer to “ << "nderived-class object invokes derived-class “ << "print function:n";
circlePtr->print(); // invokes Circle's print
// aim base-class pointer at derived-class object and print
pointPtr = &circle;
cout << "nnCalling print with base-class pointer to “ << "derived-class objectninvokes base-class print “ <<
"function on that derived-class objectn";
pointPtr->print(); // invokes Point's print
circlePtr = &point;
}
Compiler error, circlePtr = &point;a point is not a circle!
8. Polymorphism
// Fig. 10.6: fig10_06.cpp
// Aiming a derived-class pointer at a base-class object.
#include"point.h"// Point class definition
#include"circle.h"// Circle class definition
intmain()
{
Point point( 30, 50 );
Circle *circlePtr = 0;
// aim derived-class pointer at base-class object
circlePtr = &point; // Error: a Point is not a Circle
return0;
} // end main
Compiler error, circlePtr = &point;a point is not a circle!
9. Polymorphism
#include<iostream>
usingnamespace::std;
#include"xpoint.h"
#include"xcircle.h"
intmain()
{
Point *pointPtr = 0;
Circle circle( 120, 89, 2.7 );
// aim base-class pointer at derived-class object
pointPtr = &circle;
// invoke base-class member functions on derived-class
// object through base-class pointer
intx = pointPtr->getX();
inty = pointPtr->getY();
pointPtr->setX( 10 );
pointPtr->setY( 10 );
pointPtr->print();
} // end main
[10, 10]
Press any key to continue
10. Polymorphism
intmain()
{
Point *pointPtr = 0;
Circle circle( 120, 89, 2.7 );
// aim base-class pointer at derived-class object
pointPtr = &circle;
// invoke base-class member functions on derived-class
// object through base-class pointer
intx = pointPtr->getX();
inty = pointPtr->getY();
pointPtr->setX( 10 );
pointPtr->setY( 10 );
pointPtr->print();
// attempt to invoke derived-class-only member functions
// on derived-class object through base-class pointer
doubleradius = pointPtr->getRadius();
pointPtr->setRadius( 33.33 );
doublediameter = pointPtr->getDiameter();
doublecircumference = pointPtr->getCircumference();
doublearea = pointPtr->getArea();
return0;
} // end main
Compiler error
11. Polymorphism -Summary
•Base-Pointer can aim at derived class
–But can only call base-class functions
–Calling derived class functions is a compiler error
•Coz functions are not defined at base class
12. RULE
The type of pointer/reference determines function to call
14. virtual functions
•The type of object, not pointer, determines functions to call
•Why this is so good? suppose the following:
–draw function in base class
•Shape
–draw functions in all derived class
•Circle, triangle, rectangle
•Now, to draw any shape:
–Have base class shape pointer, call member function draw
–Treat all these shapes generically as object of the base class shape
–Program determines proper draw function at run time dynamically based on the type of the object to which the base class shape pointer points to at any given time.
–Declare draw virtual in the base class
–Override draw in each base class (must have the same signature )
–Declare draw virtual in all derived class
–But that’s not even necessary.
15. RULE when using virtual
The type of the object, not the pointer, determines function to call
16. The Point Class Was Looking Like this:
#ifndefPOINT_H
#definePOINT_H
classPoint {
public:
Point( int= 0, int= 0 ); // default constructor
voidsetX( int); // set x in coordinate pair
intgetX() const; // return x from coordinate pair
voidsetY( int); // set y in coordinate pair
intgetY() const; // return y from coordinate pair
voidprint() const; // output Point object
private:
intx; // x part of coordinate pair
inty; // y part of coordinate pair
}; // end class Point
#endif
#include"point.h"// Point class definition
Point::Point( intxValue, intyValue ): x( xValue ), y( yValue ){}
voidPoint::setX( intxValue ){ x = xValue; }
intPoint::getX() const{ returnx;}
voidPoint::setY( intyValue ){ y = yValue;}
intPoint::getY() const{ returny;}
voidPoint::print() const
{ cout << '['<< getX() << ", "<< getY() << ']‘;}
17. Now, we use virtualfunctions
#ifndefPOINT_H
#definePOINT_H
classPoint {
public:
Point( int= 0, int= 0 ); // default constructor
voidsetX( int); // set x in coordinate pair
intgetX() const; // return x from coordinate pair
voidsetY( int); // set y in coordinate pair
intgetY() const; // return y from coordinate pair
virtual voidprint() const; // output Point object
private:
intx; // x part of coordinate pair
inty; // y part of coordinate pair
}; // end class Point
#endif
#include"point.h"// Point class definition
Point::Point( intxValue, intyValue ): x( xValue ), y( yValue ){}
voidPoint::setX( intxValue ){ x = xValue; }
intPoint::getX() const{ returnx;}
voidPoint::setY( intyValue ){ y = yValue;}
intPoint::getY() const{ returny;}
voidPoint::print() const
{ cout << '['<< getX() << ", "<< getY() << ']‘;}
Just here
18. The Same in Circle Class, Which Was Looking Like this:
#ifndefCIRCLE_H
#defineCIRCLE_H
#include"point.h”
classCircle: publicPoint {
public:
Circle( int= 0, int= 0, double= 0.0 );
voidsetRadius( double); // set radius
doublegetRadius() const; // return radius
doublegetDiameter() const; // return diameter
doublegetCircumference() const; // return circumference
doublegetArea() const; // return area
voidprint() const; // output Circle object
private:
doubleradius; // Circle's radius
}; // end class Circle
#endif
#include"circle.h"// Circle class definition
Circle::Circle( intxValue, intyValue, doubleradiusValue )
: Point( xValue, yValue ) // call base-class constructor
{ setRadius( radiusValue );}
voidCircle::setRadius( doubleradiusValue )
{ radius = ( radiusValue < 0.0? 0.0: radiusValue );}
doubleCircle::getRadius() const{ returnradius;}
doubleCircle::getDiameter() const{ return2 * getRadius();}
doubleCircle::getCircumference() const{ return3.14159 * getDiameter();}
doubleCircle::getArea() const
{ return3.14159 * getRadius() * getRadius();}
voidCircle::print() const
{ cout << "center = ";
Point::print();
cout << "; radius = "<< getRadius();
}
20. virtualfunctions
intmain()
{
Point point( 30, 50 ); Point *pointPtr = 0;
Circle circle( 120, 89, 2.7 ); Circle *circlePtr = 0;
// output objects point and circle using static binding
cout << "Invoking print function on point and circle “
<< "nobjects with static binding “ << "nnPoint: ";
point.print(); // static binding
cout << "nCircle: “;
circle.print(); // static binding
cout << "nnInvoking print function on point and circle “
<< "nobjects with dynamic binding";
pointPtr = &point;
cout << "nnCalling virtual function print with base-class” << "npointer to base-class object” << "ninvokes base-class print function:n";
pointPtr->print();
circlePtr = &circle;
cout << "nnCalling virtual function print with “ << "nderived-class pointer to derived-class object “ << "ninvokes derived- class print function:n";
circlePtr->print();
pointPtr = &circle;
cout << "nnCalling virtual function print with base-class"
<< "npointer to derived-class object "
<< "ninvokes derived-class print function:n";
pointPtr->print(); // polymorphism: invokes circle's print}
Invoking print function on point and circle
objects with static binding
Point: [30, 50]
Circle: Center = [120, 89]; Radius = 2.70
Invoking print function on point and circle
objects with dynamic binding
Calling virtual function print with base-class
pointer to base-class object
invokes base-class print function:
[30, 50]
Calling virtual function print with
derived-class pointer to derived-class object
invokes derived-class print function:
Center = [120, 89]; Radius = 2.70
Calling virtual function print with base-class
pointer to derived-class object
invokes derived-class print function:
Center = [120, 89]; Radius = 2.70
Press any key to continue
[30, 50]
center = [120, 89]; radius = 2.7
[30, 50]
center = [120, 89]; radius = 2.7
center = [120, 89]; radius = 2.7
Press any key to continue
21. RULE when using virtual
The type of the object, not the pointer, determines function to call
REMEMBER, REMEMBER
23. virtualin baseclass, notvirtualat childclass
#ifndefPOINT_H
#definePOINT_H
classPoint {
public:
Point( int= 0, int= 0 ); // default constructor
voidsetX( int); // set x in coordinate pair
intgetX() const; // return x from coordinate pair
voidsetY( int); // set y in coordinate pair
intgetY() const; // return y from coordinate pair
virtualvoidprint() const; // output Point object
private:
intx; // x part of coordinate pair
inty; // y part of coordinate pair
}; // end class Point
#endif
#ifndefCIRCLE_H
#defineCIRCLE_H
#include"point.h”
classCircle: publicPoint {
public:
Circle( int= 0, int= 0, double= 0.0 );
voidsetRadius( double); // set radius
doublegetRadius() const; // return radius
doublegetDiameter() const; // return diameter
doublegetCircumference() const; // return circumference
doublegetArea() const; // return area
voidprint() const; // output Circle object
private:
doubleradius; // Circle's radius
}; // end class Circle
#endif
Just here
Nothing here
24. virtualfunctions
intmain()
{
Point point( 30, 50 );
Point *pointPtr = 0;
Circle circle( 120, 89, 2.7 );
Circle *circlePtr = 0;
point.print(); cout << endl; // static binding
circle.print(); cout << endl; // static binding
pointPtr = &point;
pointPtr->print(); cout << endl;
circlePtr = &circle;
circlePtr->print(); cout << endl;
pointPtr = &circle;
pointPtr->print(); cout << endl;
cout << endl;
return0;
} // end main
[30, 50]
center = [120, 89]; radius = 2.7
[30, 50]
center = [120, 89]; radius = 2.7
center = [120, 89]; radius = 2.7
Press any key to continue
The same behavior as before, that means virtual funtions are directly virtual in child classes once declared virtual in base class
27. Virtual Destructors
•If an object with non-virtual destructor is destroyed explicitly, by applying the delete operator to a base class pointer to the object
–The behavior is un-expected
•How to fix this?
–Declare base-class destructor virtual
–Making all derived class virtual as well (that’s not necessary as we have seen)
–Now, when deleting, the appropriate destructor will be called based on the type on object the base class pointer points to.
•Note
–Constructors can’t be virtual.
28. Virtual Destructors
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son(){cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Son S;
}
I'm constructor of dad
I'm constructor of son
I'm destructor of son
I'm destructor of dad
Press any key to continue
29. Virtual Destructors
#include<iostream>
usingnamespace::std;
classDad
{
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
Son(){cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Son S;
}
Compile error. Declaring constructor and desrtuctors private in base class
31. dynamic_castkeyword
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son(){cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D;
Son S;
cout << "______________________n";
Son *SonPtr =&S;
Dad *DadPtr =&D;
Dad *Person = dynamic_cast<Dad *> (DadPtr);
if(Person)
// means: if Person points to an object of type Dad
{cout << "It works!n";}
else
{cout <<"Not working!n";}
}
I'm constructor of dad
I'm constructor of dad
I'm constructor of son
______________________
It works!
I'm destructor of son
I'm destructor of dad
I'm destructor of dad
Press any key to continue
32. dynamic_castkeyword
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son(){cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D;
Son S;
cout << "______________________n";
Son *SonPtr =&S;
Dad *DadPtr =&D;
Dad *Person = dynamic_cast<Son *> (DadPtr);
if(Person)
{cout << "It works!n";}
else
{cout << "Not working!n";}
}
Compiler error
34. typeidKeyword
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2 = newDad;
cout << typeid(D1).name() << endl;
cout << typeid(D2).name() << endl;
}
I'm constructor of dad
I'm constructor of dad
class Dad
class Dad *
I'm destructor of dad
Press any key to continue
35. typeidKeyword
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2 = newDad;
cout << typeid(D1).name() << endl;
cout << typeid(D2).name() << endl;
deleteD1;
}
Compiler error Delete D1
36. typeidKeyword
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2 = newDad;
cout << typeid(D1).name() << endl;
cout << typeid(D2).name() << endl;
deleteD2;
}
I'm constructor of dad
I'm constructor of dad
class Dad
class Dad *
I'm destructor of dad
I'm destructor of dad
Press any key to continue
37. typeidKeyword
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2 = newDad();
cout << typeid(D1).name() << endl;
cout << typeid(D2).name() << endl;
deleteD2;
}
I'm constructor of dad
I'm constructor of dad
class Dad
class Dad *
I'm destructor of dad
I'm destructor of dad
Press any key to continue
38. typeidKeyword
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2;
cout << typeid(D1).name() << endl;
cout << typeid(D2).name() << endl;
deleteD2;
}
I'm constructor of dad
class Dad
class Dad *
Press any key to continue
Then runtime error Delete with no “new”
39. typeidKeyword
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2;
cout << typeid(D1).name() << endl;
cout << typeid(D2).name() << endl;
}
I'm constructor of dad
class Dad
class Dad *
I'm destructor of dad
Press any key to continue
40. typeidKeyword
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Son S1;
Son *S2 = newDad();
cout << typeid(S1).name() << endl;
cout << typeid(S2).name() << endl;
}
Compiler error
41. typeidKeyword
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2;
cout << typeid(D1).name() << endl;
cout << typeid(*D2).name() << endl;
}
I'm constructor of dad
class Dad
class Dad
I'm destructor of dad
Press any key to continue
42. typeidKeyword
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2;
cout << typeid(Dad).name() << endl;
}
I'm constructor of dad
class Dad
I'm destructor of dad
Press any key to continue
43. typeidKeyword
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2;
typeid(Dad)=typeid(D2)?
cout <<"Yeahn": cout << "Non";
}
Compiler error
45. Quiz #1
#ifndefPOINT_H
#definePOINT_H
classPoint {
public:
Point( int= 0, int= 0 ); // default constructor
voidsetX( int); // set x in coordinate pair
intgetX() const; // return x from coordinate pair
voidsetY( int); // set y in coordinate pair
intgetY() const; // return y from coordinate pair
virtual voidprint() const; // output Point object
private:
intx; // x part of coordinate pair
inty; // y part of coordinate pair
}; // end class Point
#endif
#ifndefCIRCLE_H
#defineCIRCLE_H
#include"point.h”
classCircle: publicPoint {
public:
Circle( int= 0, int= 0, double= 0.0 );
voidsetRadius( double); // set radius
doublegetRadius() const; // return radius
doublegetDiameter() const; // return diameter
doublegetCircumference() const; // return circumference
doublegetArea() const; // return area
virtual voidprint() const; // output Circle object
private:
doubleradius; // Circle's radius
}; // end class Circle
#endif
46. Quiz #1
intmain()
{
Point point( 30, 50 );
Point *pointPtr = 0;
Circle circle( 120, 89, 2.7 );
Circle *circlePtr = 0;
{
staticPoint P(20,40);
}
point.print(); cout << endl;
circle.print(); cout << endl;
pointPtr = &circle;
pointPtr->print(); cout << endl;
circlePtr = &circle;
circlePtr->print(); cout << endl;
pointPtr->print(); cout << endl;
cout << endl;
return0;
} // end main
WaaaWeee Constructor of Point!
WaaaWeee Constructor of Point!
WaaaWeee Constructor of Cricle!
WaaaWeee Constructor of Point!
[30, 50]
center = [120, 89]; radius = 2.7
center = [120, 89]; radius = 2.7
center = [120, 89]; radius = 2.7
center = [120, 89]; radius = 2.7
WaaaWeee Destructor of Cricle!
WaaaWeee Destructor of Point!
WaaaWeee Destructor of Point!
WaaaWeee Destructor of Point!
Press any key to continue
47. Quiz #2
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2;
typeid(Dad)==typeid(D1)? cout<<"Yeahn":cout<<"Non";
}
I'm constructor of dad
Yeah
I'm destructor of dad
Press any key to continue
48. Quiz #3
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2;
typeid(Dad)==typeid(D2)? cout <<"Yeahn": cout << "Non";
}
I'm constructor of dad
No
I'm destructor of dad
Press any key to continue
49. Quiz #4
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2;
Son *S1 = newSon();
D2 = &(S1);
cout << typeid(D2).name() << endl;
}
Compiler error D2 = &(S1);
50. Quiz #5
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2;
Son *S1 = newSon;
D2 = &(*S1);
cout << typeid(D2).name() << endl;
}
I'm constructor of dad
I'm constructor of dad
I'm constructor of son
class Dad *
I'm destructor of dad
Press any key to continue
51. Quiz #6
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2;
Son *S1;
D2 = &(*S1);
cout << typeid(D2).name() << endl;
}
Runtime error
52. Quiz #7
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2 = newDad ();
Son *S1 = newSon;
D2 = &(*S1);
cout << typeid(D2).name() << endl;
deleteDad;
}
Compiler error deleteDad;
53. Quiz #8
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Dad *D2 = newDad ();
Son *S1 = newSon;
D2 = &(*S1);
cout << typeid(D2).name() << endl;
deleteS1;
}
I'm constructor of dad
I'm constructor of dad
I'm constructor of dad
I'm constructor of son
class Dad *
I'm destructor of son
I'm destructor of dad
I'm destructor of dad
Press any key to continue
54. Quiz #9
#include<iostream>
usingnamespace::std;
classDad
{
public:
Dad(){cout << "I'm constructor of dad "<< endl; };
~Dad(){cout << "I'm destructor of dad "<< endl; };
};
classSon: publicDad
{
public:
Son() {cout << "I'm constructor of son "<< endl; }
~Son() {cout << "I'm destructor of son "<< endl; }
};
#include<iostream>
#include"Testing.h"
usingnamespace::std;
voidmain()
{
Dad D1;
Son *S1 = newSon;
Dad *D2 = &(*(&(*S1)));
cout << typeid(D2).name() << endl;
}
I'm constructor of dad
I'm constructor of dad
I'm constructor of son
class Dad *
I'm destructor of dad
Press any key to continue