Skip to main content

Swapping Private data of classes

 CASE 1: 

Given two numbers a & b, swap these two numbers using the friend function of C++. 

Examples: 

Input : a = 5, b = 9
Output : a = 9, b = 5

Input : a = 4, b = 6
Output : a= 6, b = 4
  • Approach: 
  • Create a class Swap, declare one variable in it, i.e., num, and create a constructor for inputs. Declare a friend function in it. Define the friend function outside the class scope by taking arguments as call by reference to pass the copy of Swap Object. Perform the swap operation.


Comments

Popular posts from this blog

How to Install Parrot Operating System in Virtual Box using OVA

Step by Step Process of Parrot OS Installation What is Parrot OS Parrot is a free and open-source Linux system based on Debian that is popular among security researchers, security experts, developers, and privacy-conscious users. It comes with cyber security and digital forensics arsenal that is totally portable. It also includes everything you'll need to make your own apps and protect your online privacy. Parrot is offered in Home and Security Editions, as well as a virtual machine and a Docker image, featuring the KDE and Mate desktop environments. Features of Parrot OS The following are some of the features of Parrot OS that set it apart from other Debian distributions: Tor, Tor chat, I2P, Anonsurf, and Zulu Crypt, which are popular among developers, security researchers, and privacy-conscious individuals, are included as pre-installed development, forensics, and anonymity applications. It has a separate "Forensics Mode" that does not mount any of the system's hard...

Static Member Functions

  What is static member functions? A static member function can access static data members and static member functions inside or outside of the class. Static member functions have a scope inside the class and cannot access the current object pointer. You can also use a static member function to determine how many objects of the class have been created. Static Member Function in a class is the function that is declared as static because of which function attains certain properties as defined below: A static member function is independent of any object of the class.  A static member function can be called even if no objects of the class exist. A static member function can also be accessed using the class name through the scope resolution operator. A static member function can access static data members and static member functions inside or outside of the class. Static member functions have a scope inside the class and cannot access the current object pointer. You can also u...

Hadoop Mode of Operations

  Aim:         (i) Perform setting up and Installing Hadoop in its three operating modes: Standalone, Pseudo distributed, Fully distributed         (ii)Use web-based tools to monitor your Hadoop setup Ans ) It is an open-source framework written in java that is used to store, analyze and process huge amounts of data in a distributed environment across clusters of computers in an efficient manner. It provides the capability to process distributed data using a simplified programming model. It is used by Google, Facebook, yahoo, youtube, Twitter, etc. It is developed by Doug Cutting at Yahoo in 2006 which is inspired by Google File System and Google Map Reduce algorithm. It is a file system provided by Linux to store the data. Operational modes of configuring Hadoop cluster Hadoop can be run in one of the three supported modes   1) Local(Standalone) mode -By default, Hadoop is configured to ...