Blog

C++ Friend function & Friend Class

If a function is defined as a friend function in C++, then the protected and private data of a class can be accessed using the function. By using the keyword, the friend compiler knows the given function is a friend function. For accessing the data, the declaration of a friend function should be done inside the body of a class, starting with the keyword friend. Declaration of friend function in C++ Class class_name { friend data_type function_name(argument/s); // syntax of friend function. }; In the above declaration, the friend function is preceded by the keyword friend. The function can be defined anywhere in the program like a normal C++ function. The function definition does not use either the keyword friend or scope resolution operator. Characteristics of a Friend function: C++ friend function Example Let’s see the simple example of the C++ friend function used to print the length of a box.             #include <iostream>             using namespace std;             class Box             {                         private:                         int length;             public:             Box() : length(0) {}             friend int printLength(Box); // friend function             };             int printLength(Box b)             {                         b.length + = 10;                         return b.length;             }             int main()             {                         Box b;                         cout  << “Length of box: “ << printLength(b) << endl;                         return 0;             } Output: Length of the box: 10 C++ Friend class A friend class can access both private and protected members of the class in which it has been declared as a friend. Let’s see a simple example of a friend class.             #include <iostream>             using namespace std;             class A             {                         int x =5;                         friend class B; // friend class             };             class B             {                         public:                         void display(A &a)                         {                                     cout << “value of x is : “ << a.x << endl;                             }             };             int main()             {                         A a;                         B b;                         b.display(a);                         return 0;             } Output: Value of x is: 5 In the above example, class B is declared as a friend inside the class A. Therefore, B is a friend of class A. Class B can access the private members of class A.

C++ Friend function & Friend Class Read More »

C++ Copy Constructor

A Copy constructor is an overloaded constructor used to declare and initialize an object from another object. Copy Constructor is of two types: Default Copy constructor: The compiler defines the default copy constructor. If the user defines no copy constructor, the compiler supplies its constructor. User-Defined constructor: The programmer defines the user-defined constructor. Syntax Of User-defined Copy Constructor: Class_name(const class_name &old_object); When Copy Constructor is called Copy Constructor is called in the following scenarios: Two types of copies are produced by the constructor: Shallow Copy #include <iostream>      using namespace std;       class Demo      {          int a;          int b;          int *p;          public:          Demo()          {              p=new int;          }          void setdata(int x,int y,int z)          {              a=x;              b=y;              *p=z;          }          void showdata()          {              std::cout << “value of a is : ” <<a<< std::endl;              std::cout << “value of b is : ” <<b<< std::endl;              std::cout << “value of *p is : ” <<*p<< std::endl;          }      };      int main()      {        Demo d1;        d1.setdata(4,5,7);        Demo d2 = d1;        d2.showdata();          return 0;      }  Demo d2 = d1; calls the default constructor defined by the compiler. The default constructor creates the exact copy or shallow copy of the existing object. Thus, the pointer p of both the objects point to the same memory location. Therefore, when the memory of a field is freed, the memory of another field is also automatically freed as both the fields point to the same memory location. This problem is solved by the user-defined constructor that creates the Deep copy. Deep copy Deep copy dynamically allocates the memory for the copy and then copies the actual value both the source and copy have distinct memory locations. In this way, both the source and the copy are distinct and will not share the same memory location. Deep copy requires us to write the user-defined constructor. #include <iostream>      using namespace std;      class Demo      {          public:          int a;          int b;          int *p;          Demo()          {              p=new int;          }          Demo(Demo &d)          {              a = d.a;              b = d.b;              p = new int;              *p = *(d.p);          }          void setdata(int x,int y,int z)          {              a=x;              b=y;              *p=z;          }          void showdata()          {              std::cout << “value of a is : ” <<a<< std::endl;              std::cout << “value of b is : ” <<b<< std::endl;              std::cout << “value of *p is : ” <<*p<< std::endl;          }      };      int main()      {        Demo d1;        d1.setdata(4,5,7);        Demo d2 = d1;        d2.showdata();        return 0;      }  Demo d2 = d1; calls the copy constructor defined by the user. It creates the exact copy of the value types data and the object pointed by the pointer p. Deep copy does not create the copy of a reference type variable.

C++ Copy Constructor Read More »

Bootstrapping in UNIX / LINUX

Bootstrapping in computer science is the technique for producing a self-compiling compiler. That is compiler/assembler written in the source programming language that it intends to compile. An initial core version of the compiler is generated in a different language mostly assembly language. Successive developed versions of the compiler are developed using this minimal subset of the language. When a computer is turned on is booted up with the code that is stored in ROM. The same code tries to figure out how much to load and start your kernel. The kernel verifies all the system’s hardware and initializes the system’s init process, which is always PID 1. A lot of things will happen before a login prompt can appear for the user to log in. File systems must be checked and mounted, and the system daemons started. These procedures are managed by a series of shell scripts that are run in sequence in init. The above entire process is called as Booting process. There are two ways where a UNIX / LINUX OS can boot, ‘Automatic mode’ & ‘Manual mode’ Without any external assistance if the system performs the whole boot procedure, then it is called ‘Automatic Mode’. In ‘manual mode’, at first, the system follows the automatic procedure up to a point before most initialization scripts have been run, And then turns control over to an operator. Up to this point, the computer will be running in ‘Single User mode’. Most of the system process will not be running, while other users cannot log in as well. It is involved in six different steps:

Bootstrapping in UNIX / LINUX Read More »

Big Data Processing with Hadoop, Spark, or Both?

Hadoop and Spark are the frameworks used for data processing. Both Hadoop and Spark are maintained by Apache Software Foundation. Both of these frameworks work on different principles. Hadoop is a common or popular name in the world of Big Data while Spark is still building a name for itself in a ”style”. Hadoop: Hadoop is an Open Source software framework for storing data and running applications on a cluster. It is very useful in Big Data Analytics with great Volume, Velocity, Variety, and Value known as the 4V’s of Big Data. Data in various forms such as structured, semi-structured and unstructured data. Hadoop has mainly four core components that work on different essential tasks for Big Data analysis. Distributed File System: Hadoop has its own distributed file system(HDFS) for storing the data. Map Reduce: Data store in the HDFS is processed or investigated using map-reduce. YARN: combines central resource manager that manages the node manager agents that monitors the processing of individual clustering nodes. Hadoop Common: It helps the user read and analyse the collected data in various systems Hadoop is a great tool when it comes to big data analysis for applicability, flexibility, availability. Spark : Spark is a framework that provides a number of interconnected platforms systems and standards for big data analysis. The important difference to be noted between Hadoop and Spark is that spark processes data through logical memory and RAM. While Hadoop works with disks. Spark is pretty much like Hadoop as a layer that can load data into memory with parallel analysis. The major cor components of Spark : Spark Streaming: The real-time data streaming where data is in bulk. It helps you analyze the ocean of data. Spark Core: Distributes tasks and works with scheduling. Spark Machine Learning Library (MLlib): An extensive library of an analytic algorithm for spark clusters, adaptable to all other clusters Spark can work with. Conclusion on Hadoop, Spark or Both? When Hadoop is compared with spark, the spark is much speedier than Hadoop. Hadoop focuses on transferring data through hard disks, spark runs its operations through memory. Working through logical RAM increases the speed. Hence, the spark can handle data analysis quite faster than Hadoop. But, spark lacks a file system and it hence needs Hadoop. To get spark work without Hadoop one would need to go with the third party file organization system. However, this is complicating and since both Hadoop and spark are maintained by Apache Software Foundation it is implied that using spark on top of Hadoop is the best long time solution.

Big Data Processing with Hadoop, Spark, or Both? Read More »

Enquire Now

Enquire Now

Enquire Now

Please Sign Up to Download

Please Sign Up to Download

Enquire Now

Please Sign Up to Download





    [group student clear_on_hide]

    [/group]

    [group graduated clear_on_hide]

    [/group]

    [group wp clear_on_hide]

    [/group]

    [group student-course clear_on_hide]

    [/group]

    [group graduated-course clear_on_hide]

    [/group]

    [group work-course clear_on_hide]

    [/group]


    Enquiry Form