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:  …

auto keyword

Let us understand the usage of auto keyword with the help of an example. #include <iostream>using namespace std;int main(){ auto i = 10; auto d = 7.5; cout <<  “Integer and double: ” << i << “ “ << d << endl; return 0;} Above code can be compiled using -std=c++11 flag. Here, we have not defined the type for variable i and d.  When we initialize the variable at the time of declaration, compiler can identify or deduce the type for it. Based on this, C++11 came with the…

GET HIERARCHICAL VALUES PRESENT IN SAME COLUMN OF A TABLE

Lets discuss about the parent and child relationship present in the same column of a table. That means both exists in the same column and there is always a identifier which says whether a record belongs to parent value or it belongs to child value. See the below data .As it is clearly seen from the data, parent and child record can be easily identified from column c1. Here , we need to apply self join to get parent and child values in the same row. See the below Query.…

Stack Using Linked List

Let us see in the below program how stack can be implemented using Linked List. #include <iostream>using namespace std;typedef struct node{ int data; struct node* next; }Node;class stack{private: Node* head;public: stack() { head = NULL; } ~stack() { while (NULL != head) { Node* temp = head; head = head ->next; delete temp; } } void push(int data) { Node* temp = new Node; temp->data = data; if (NULL == head) { head = temp; head->next = NULL; return; } temp->next = head; head = temp; } int pop() {…

Stack using fixed size array

Stack is one of the data structure that uses LIFO (Last In First Out) or FILO (First In Last Out) property i.e. element which is stored in last, will be out (read) first.Real life example of stack is stack of plates. Last plate put over the plates is the first plate that is removed or used. #include <iostream>using namespace std;const int MAX_INDEX = 50;  // Maximum index of array.const int MIN_INDEX  = -1; // Minimum index  of array.class stack{private: unsigned int arr[MAX_INDEX]; int top;public: stack() { top = MIN_INDEX; }…

Initializer_list

Let us understand the concept of initializer_list with the help of an example: #include <iostream>#include <vector>#include <initializer_list>using namespace std;#define MAX 10class array{public: array(std::initializer_list<unsigned int> list) { index = 0; for(auto item: list) { arr[index++] = item; } cout  << “C’tor” << endl; } void display() { for (unsigned int i = 0; i < index; ++i) { cout << arr[i] << endl; } }private: unsigned int arr[ MAX]; unsigned short index;};int main(){ array arrObj = {0,1,5,7,8}; arrObj.display(); vector <unsigned int> v = {5,8,9,10,20}; cout << “Entries in vector: ” <<…

like operations in Pentaho

Let us discuss about How to implement Like operations in Pentaho.Here, I have designed the transformation to handle like operation which is same as like clause in database. See the below Transformation design. See the values in the Generate rows components. See the code written in Modified JavaScript Value Component.Here if you see I have used function “getOcuranceString” which will give value in terms of number of occurrences of a substring in the main string. In other words, we can say if it returns value 0 that means value which…

Return Value Optimization(RVO)

Let us try to understand RVO(Return value optimization) with the help of below example: #include <iostream> using namespace std; class base { unsigned int m_mem1; unsigned int m_mem2; public: base(unsigned int x, unsigned int y): m_mem1(x), m_mem2(y) { cout << “base C’tor” << endl; } ~base() { cout << “base d’tor” << endl; } base(const base& b) { m_mem1 = b. m_mem1; m_mem2 = b. m_mem2; cout << “Copy C’tor” << endl; } static base getNewInstance() { base b(10,20); return b; } }; int main() { base b = base::getNewInstance();…

inline function

inline function is a function which is expanded inline i.e. function definition is copied to a place where it is called.When a function called in program, CPU does following: a) Stores the address of instruction following the function call. b) Push function arguments on the stack c) Transfer the control to the function definition. d) Execute the function e) Transfer the control to the address stored at step a. When execution time of function is less than the switching time from calling to called function, then this becomes overhead. To…

Friend function

Friend function is a function, which can access the private and protected data member of a class. Using keyword friend, we can make function a friend function. Below is the prototype for friend function friend <return-type>  function(<className>); Example: #include <iostream> using namespace std; class base { unsigned int m_int; public: base() { m_int = 20; } friend ostream& operator<<(ostream& s, const base& b); }; //Source File ostream& operator<<(ostream& s, const base& b) { s << b.m_int ; return s; } int main() { base b; cout << b << endl;…