Arnab Chakraborty has Published 4293 Articles

getline (string) in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Dec-2019 09:58:05

893 Views

It is used to extracts characters from the stream as unformatted input and stores them into s as a c-string, until either the extracted character is the delimiting character, or n characters have been written to s (including the terminating null character). The declaration is like:basic_istream& getline (char_type* s, streamsize ... Read More

Constructor Overloading in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Dec-2019 09:55:35

4K+ Views

As we know function overloading is one of the core feature of the object oriented languages. We can use the same name of the functions; whose parameter sets are different. Here we will see how to overload the constructors of C++ classes. The constructor overloading has few important concepts.Overloaded constructors ... Read More

Cons of using the whole namespace in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Dec-2019 09:53:42

281 Views

In C++, we use different namespaces. We can also create our own namespaces. For example, generally, we use standard namespace called std. We write the syntax like:using namespace std;In the standard library, it contains common functionality you use in building your applications like containers, algorithms, etc. If names used by ... Read More

Find the compatibility difference between two arrays in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Dec-2019 09:50:39

546 Views

Consider there are two friends and now they want to test their bonding. So they will check, how much compatible they are. Given the numbers n, numbered from 1..n. And they are asked to rank the numbers. They have to find the compatibility difference between them. The compatibility difference is ... Read More

Find the closest pair from two sorted arrays in c++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Dec-2019 09:47:51

501 Views

Suppose we have two sorted arrays and a number x, we have to find the pair whose sum is closest to x. And the pair has an element from each array. We have two arrays A1 [0..m-1] and A2 [0..n-1], and another value x. We have to find the pair ... Read More

Find the second last node of a linked list in single traversal in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 13:02:06

670 Views

Now we will see how to get the second last element in the linked list. Suppose there are few elements like [10, 52, 41, 32, 69, 58, 41], second last element is 58.To solve this problem, we will use two pointers one will point to current node, and another will ... Read More

Find the Second Largest Element in a Linked List in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 13:00:00

472 Views

Here we will see the second largest element in the linked list. Suppose there are n different nodes with numerical values. So if the list is like [12, 35, 1, 10, 34, 1], then second largest element will be 34.This process is similar to the finding of second largest element ... Read More

Find the next identical calendar year in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 12:54:41

240 Views

Suppose we have an year Y. Find next identical calendar year to Y. So the calendar of 2017 is identical with 2023.A year X is identical to given previous year Y if it matches these two conditions.x starts with the same day as year, If y is leap year, then ... Read More

Find the fractional (or n/k – th) node in linked list in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 12:51:30

267 Views

Suppose we have a singly linked list and the number k. We have to write a function to find the (n/k)th element, where n is the number of elements in the list. For decimals, we will choose the ceiling values. So if the list is like 1, 2, 3, 4, ... Read More

Find the first natural number whose factorial is divisible by x in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 12:45:33

212 Views

We have to find the first natural number whose factorial is divisible by x. The x is given by the user. So if the x = 16, then output will be 6. as 6! mod 16 = 0. We will use general approach to solve this problem. iteratively count 1!, ... Read More

Advertisements