Assignment Operator

Let us understand assignment operator with the help of an example of employeeData class. #include <iostream>#include <string>using namespace std;class employeeData { unsigned int m_salary; char* m_name;public: ~ employeeData() { if (m_name) { delete []m_name; } } employeeData() { cout << “employeeData default C’tor” << endl; m_salary = 0; m_name = NULL; } employeeData(unsigned int salary, char* name) { cout << “employeeData parameterized C’tor” << endl; m_salary = salary; unsigned int len = strlen(name); m_name = new char[len +1]; strncpy(m_name, name, len); m_name[len+1] = ‘\0’; } //Overloaded Assignment Operator employeeData& operator=(const…

Copy Constructor

Prototype of copy constructor <classname>(const <classname>& ); Let say class name is foo. Then the copy constructor prototype will look like: foo(const foo& ); Scenarios:Below are the scenarios where copy constructor is called. 1) When an object is passed by value as function argument. 2) When function returns object by value. 3) When new object is created from an already existing/created object. Need:Compiler provides default copy constructor for each class. However, there are scenarios where we need to define the copy constructor explicitly. Consider a class below: #include <iostream>using namespace…

Virtual Function

Function is a virtual function when the virtual keyword is added in the beginning of function declaration.virtual void display();virtual keyword is required in declaration. In function definition, virtual keyword is not required. When you want to override(redefine) the function in derived class, then virtual function is required. This means virtual function works only when inheritance is involved. Let us understand with the help of an example. class shape {public: virtual void draw() {} virtual void func() {}};class rectangle: public shape {public: void draw() { cout << “Draw rectangle” << endl;…

Dynamic Cast

This is one of the type casting provided by C++. Let us understand with the help of an example. #include <iostream>using namespace std;#define MAX_LENGTH 50class person { unsigned int m_age; char m_name[MAX_LENGTH];public: person(unsigned int age, char* name) { m_age = age;    int len = strlen(name); strncpy(m_name, name, len); m_name[len+1] = ‘\0’; } virtual ~person(){}};class student : public person { unsigned int m_rollNumber;public: student(unsigned int age, char* name, unsigned int rollNumber):person(age, name),m_rollNumber(rollNumber) { } ~student(){}};class teacher: public person {unsigned int m_salary;public: teacher(unsigned int age, char* name, unsigned int salary):person(age, name),m_salary(salary) {…

DHCP

DHPC stands for Dynamic Host configuration Protocol.For any device to be part of network, it must have an IP in order to communicate with other devices in the network.Here device or Host mean the same. IP AllocationIP can be assign to a device in two ways:1. Statically2. Dynamically Statically assigning an IP means manually configuring the device. However, this can be very hectic if we have to do for multiple devices. To overcome this tedious work, DHCP come in to picture. DHCP is a protocol that helps in configuring/assigning the…

Conversions

In this, we will learn about the conversions. First two conversions viz. Binary to Decimal and Decimal to Binary are explained in detail and remaining two conversions viz. Decimal to Hexadecimal and Hexadecimal to Decimal are almost same as first two but with small difference. In all the conversions, we will take one number and convert in to another. Binary to DecimalBinary number is represented with 0 and 1. Binary Number: 0110 0011 Rightmost bit of binary number is LSB i.e. Least Significant bit and leftmost bit is MSB (Most…

IPv4 Address

IPv4 Address consist of 4 numbers separated by dot(.). Each number ranges from zero to 255. Each number is an octet (each octet is of 8 bit) and that is why maximum range of each number is 255. Since each Number is an octet and there are 4 numbers in IPv4 address so IPv4 Address is a 32 bit Address Example of IPv4 Address: 10.8.12.9 Every device like computer, printer or router is assigned with IPv4 Address in order to uniquely identify in the network.IPv4 address divided in to two…

Call Pentaho Job using Batch Script

In this post, I will discuss about the “How to call the Pentaho Job in the local Machine which is windows” . To put it differently, call the Pentaho Job using batch script. Below is the sample code of the batch script. call <local_Path>\data-integration\kitchen.bat /file:<Local-Path>\Pipe-delimited-file-variables.kjb In above command, I have mentioned Path of the kitchen.bat file and then Path of the Pentaho job along with Job Name.Below is the ETL code of above Job. This job does a very simple part to load the pipe delimited file to a Table.…

Queue using stack

Let us understand how to prepare queue using two stacks When we say we have to prepare queue using stack that means all the operations of stack should be used to get the queue functionality. Queue has FIFO property i.e. First-In First-Out i.e. element which is inserted first , same element should be removed or pop first. Consider that we have two stacks s1 and s2. Initially both the stacks are empty. Here we have used Stack Using Linked List. When we push any data in to stack, we have…

nullptr

Let us understand the need of nullptr with help of an example. #include <iostream>using namespace std;class base {public: void display(int num) { cout << “Integer display: “ << num << endl; } void display(char* ptr) { cout << “ptr display: “ << ptr << endl; }}; int main() { base b; b.display(NULL); return 0; } The above code will not compiled. Below error will come: “In function int main():     15:15: error: call of overloaded display(NULL) is ambiguous            b.display(NULL); 15:15: note: candidates are:  …