Application of Residue Theorem to evaluate real integrations.pptx
C++
1. Constructors and destructors
Introduction:
Constructors:
A class constructor is a special member function of a class that is executed
whenever we create new objects of that class.
There is no return type for the constructors and infinite number of
constructors can be used in the particular class. Constructors will have the
same name as class. It is very useful for setting initial values to objects.
It can be called infinite times in a class through objects. Constructors play
a vital role in object oriented programming.
Theory:
There are five different types of constructors.
1. Parametrized constructors
2. Default constructors
3. Copy constructors
4. Conversion constructors
5. Move constructors
1. Parametrized constructors:
Constructors that can take at least one argument are termed as
parameterized constructors.
When an object is declared in a parameterized constructor, the initial
values have to be passed as arguments to the constructor function.
The normal way of object declaration may not work. The constructors
can be called explicitly or implicitly. The method of calling the
constructor implicitly is also called the shorthand method.
2. Default constructors:
If the programmer does not supply a constructor for an instantiable
class, most languages will provide a default constructor.
The behaviour of the default constructor is language dependent. It
may initialize data members to zero or other same values, or it may
do nothing at all.
2. 3. Copy constructors
Copy constructors define the actions performed by the compiler when
copying class objects. A copy constructor has one formal parameter
that is the type of the class
4. Conversion constructors
Conversion constructors provide a means for the compiler to
implicitly create an object belonging to one class based on an object
of a different type. These constructors are usually invoked implicitly
to convert arguments or operands to an appropriate type, but they
may also be called explicitly.
5. Move constructors
In C++, move constructors take a value reference to an object of the
class, and are used to implement ownership transfer of the parameter
object's resources.
Syntax of constructors:
1. Default constructors:
#include <iostream>
using namespace std;
class default{
public:
default(){
int a, b;
a=0
b=0; //default constructor
}
};
int main(){
3. default o1,o2;
}
2. Parametrized constructors:
#include <iostream>
using namespace std;
class parameter{
public:
parameter(int a,int b){
cout<<”parametrized consrtructor is called”;
}
};
int main(){
parameter o1(1,2) , o2(3,4);
return 0;
}
3. Copy constructors:
#include<iostream>
Using namespace std;
Class copy{
Public:
Copy(copy &o1){
Cout<<”copy constructor called”;
}
};
Int main(){
Copy o1;
4. o2=o1;
}
Real time applications of constructors:
Real-time locating systems (RTLSs) are considered an
effective way to identify and track the location of an object in
both indoor and outdoor environments. Various RTLSs have
been developed and made commercially available in recent
years. Research into RTLSs in the construction sector is
ubiquitous, and results have been published in many
construction-related academic journals over the past decade.
A succinct and systematic review of current applications
would help academics, researchers, and industry practitioners
in identifying existing research deficiencies and therefore
future research directions.
Constructors are used in data transmission systems in real life.
Destructors:
Introduction:
"Destructor" functions are the inverse of constructor functions.
They are called when objects are destroyed (deallocated) .
Designate a function as a class's destructor by preceding the class
name with a tilde (~).
Destructors are called only once in the whole program.
Theory:
Destructors are functions with the same name as the class but preceded by
a tilde .The first form of the syntax is used for destructors declared or
defined inside a class declaration; the second form is used for destructors
defined outside a class declaration.
Several rules govern the declaration of destructors. Destructors:
Do not accept arguments.
Cannot specify any return type (including void ).
Cannot return a value using the return statement.
Cannot be declared as const, volatile, or static. However, they can be
invoked for the destruction of objects declared as const, volatile,
or static.
5. Can be declared as virtual. Using virtual destructors, you can destroy
objects without knowing their type — the correct destructor for the
object is invoked using the virtual function mechanism. Note that
destructors can also be declared as pure virtual functions for abstract
classes.
Syntax of destructors:
#include<iostream>
Using namespace std;
Class destructor(){
~destructor(){
Cout<<” destructor is called”;
}
};
Int main(){
Destructor o1;
Return 0;
}
Real time application of destructors:
Destructors are very important pieces of the RAII (Resource Allocation Is
Initialization) idiom. Linking the acquisition of resources (files, memory,
sockets, other class objects) to the lifetime of an object is a very powerful tool.
When an object goes out of scope, either through normal execution or due to
an exception, having the object destructor called allows the class to clean up
its resources properly, without having to burden the code using an object with
lots of extra finalization steps.