Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
C++ Articles
Page 79 of 597
What happens when more restrictive access is given to a derived class method in C++
In this section we will discuss about interesting facts restrictive access of derived class methods in C++. We will see some examples and analyze the output to know more about restrictions of using derived class methods in C++.Example (C++)Let us see the following implementation to get better understanding −#include using namespace std; class BaseClass { public: virtual void display(){ cout
Read MoreMaximize the number of sum pairs which are divisible by K in C++
Given the task is to calculate the maximum number of pairs arr[i] + arr[j] that are divisible by K where arr[] is an array containing N integers.Given the condition that a particular index number cannot be used in more than one pair.Inputarr[]={1, 2 ,5 ,8 ,3 }, K=2Output 2Explanation − The desired pairs are: (0, 2), (1, 3) as 1+5=6 and 2+8=10 . Both 6 and 10 are divisible by 2.Alternative answers could be the pairs: (0, 4), (1, 3) or (2, 4), (1, 3) but the answer remains the same, that is, 2.Input arr[]={1 ,3 ,5 ,2 ,3 ,4 }, K=3Output 3Approach ...
Read MoreMaximize the maximum among minimum of K consecutive sub-arrays in C++
Given the task is to divide an array arr[] into K consecutive sub-arrays and find the maximum possible value of maximum among the minimum of the K consecutive sub-srrays.Input arr[]={2, 8, 4, 3, 9, 1, 5}, K=3Output 9Explanation − The 3 consecutive sub arrays that can made are: {2, 8, 4, 3}, {9}, and {1, 5}The minimum values out of all these arrays are: (2, 9, 1)The maximum value out of these three is 9.Input arr[] = { 8, 4, 1, 9, 11}, K=1Output 11Approach used in the below program as followsIf we look at the task, it can be divided into 3 cases ...
Read MoreComputing index using pointers returned by STL functions in C++
In this section we will see how to generate index using pointers that are returned by STL in C++. As we know many inbuilt functions in C++ return the pointers to the position in memory which provides the address of desired number, but it has no relation with the actual index in the container of the returned value. As an example, to determine maximum element in a code, we use std::max_element() function, this does not return the index of the desired element, but return the address in memory. But sometimes, we need to get the index from that address. Here ...
Read MoreMaximum difference of indices (i, j) such that A[i][j] = 0 in the given matrix in C++
We are given with a matrix of size n x n and a condition that a[i][j] = 0 and the task is to calculate the maximum difference of indices having a[i][j] = 0. So, we can clearly state that there must be at least one zero in a matrix.Input int matrix[][] = { {0, 1, 1}, {0, 0, 0}, {4, 5, 1}}Output −Maximum difference of indices (i, j) such that A[i][j] = 0 in the given matrix is −Explanation − we have element 0 at matrix[0][0], matrix[1][0], matrix[1][1] and matrix[1][2]. So the maximum difference of indices will be ...
Read MoreGaussian Filter Generation in C++
As we know the Gaussian Filtering is very much useful applied in the field of image processing. It is used to reduce the noise of an image. In this section we will see how to generate a 2D Gaussian Kernel. Gaussian Distribution for generating 2D kernel is as follows.$$G(x,y)= \frac{1}{2\Pi\:\sigma^{2}}e^{\frac{x^{2}+y^{2}}{2\sigma^{2}}}$$ExampleLet us see the following implementation to get better understanding −#include #include #include #define PI 3.1415 using namespace std; void calc_filter(double kernel[][5]) { double sigma = 1.0; double p, q = 2.0 * sigma * sigma; double sum = 0.0; for (int x = -2; x
Read MoreGenerating Test Cases (generate() and generate_n() in C++
In this section we will see how we can use C++ STL function to generate test cases. Sometimes generating test cases for array programs can be very complicated and inefficient process. C++ provides two methods to generate test cases. These methods are as follows −The generate() methodThe C++ function std::algorithm::generate() assigns the value returned by successive calls to gen to the elements in the range of first to last. It takes three parameters first, last and gen, these are forward iterator to the initial position, backward iterator to the final position and generator function that is called with no argument, ...
Read MoreDifferent ways to declare variable as constant in C and C++
There are multiple ways of declaring constants in C and C++. First of all, we need to understand what constant is. What is a Constant? Constant means which can't be changed. In terms of programming, constants are the fixed values that are assigned to the variables such that they can't be altered by any other variable or component during the execution of a program. Constants can be of any data type. They are used in the programming for defining the non-changing component of a program. There are some data or variables which have fixed value like Pi have ...
Read MoreGeometry using Complex Numbers in C++
In this section, we will see how to make point class using complex class from STL in C++. And apply them on some geometry related problems. The complex number is present inside the complex class from STL (#include )Defining Point ClassTo make complex to point, we will change the name of the complex as point, then change x to real() of complex class and y to imag() of complex class. Thus, we can simulate the point class.# include typedef complex point; # define x real() # define y imag()We have to keep in mind that the x and y ...
Read MoreQueries to add, remove and return the difference of maximum and minimum in C++
In this problem, we are given Q queries. These are of three types, they are −Query 1: Add number N to the list.Query 2: Remove number N to the list.Query 3: Return the difference of minimum and maximum element of the list.Our task is to create a program to solve queries to add, remove, and return the difference of maximum and minimum in C++.Problem DescriptionWe will be given a Q number of queries that we will be performing on the list. There are 3 types of queries to add, remove, and find the difference of maximum and minimum element of ...
Read More