Server Side Programming Articles - Page 1683 of 2646

set operator= in C++ STL

Sunidhi Bansal
Updated on 28-Jul-2020 10:47:26

297 Views

The function operator= is used in sets to copy one set (or move to another in C++ STL. It behaves as a normal ‘=’ assignment operation for sets. There are there overloaded forms of this function −copy :- set& operator= (const set& s1) −This function copies all the elements in set s1 to another set. The parameter passed is set of the same type.Usage − set s1=s2;move :- set& operator=( set &&s1 ) −This moves the elements of set s1 into the calling set.Initializer list :- set& operator= (initializer_list ilist) −This version copies the values of the initializer list ilist ... Read More

C++ Rule Of Three.

Akansha Kumari
Updated on 15-Jul-2025 17:12:43

1K+ Views

The rule of three in C++ states that, if a class in C++ has any one (or more) of the following, then it should define all three. Destructor Copy Constructor Copy Assignment Constructor These three are special member functions of class and are responsible for managing resources such as dynamic memory, file handles, sockets, etc. And if one of them is defined explicitly, means that class is managing those resources manually (like memory using new/delete), and if we fail to define others then it can lead to ... Read More

round() in C++.

Sunidhi Bansal
Updated on 28-Jul-2020 10:42:58

16K+ Views

The round() function in C++ is used to round off the double, float or long double value passed to it as a parameter to the nearest integral value. The header file used to use the round() function in a c++ program is or .Following are the overloaded versions of round() after C++ 11 standarddouble round( double D )float round( float F )long double round( long double LD )double round ( T var )Note − The value returned is the nearest integer represented as floating point, i.e for 2.3 nearest value returned will be 2.0 and not 2.Following program is ... Read More

Rotation of a point about another point in C++

Sunidhi Bansal
Updated on 28-Jul-2020 10:41:29

1K+ Views

Rotation of a point X about origin is by an angle θ in anti-clockwise direction is done by − X by θ about origin anti-clRotateockwise: X*polar( 1.0, θ ).Here, the function polar for complex numbers is defined under header file and is used to find a complex number using phase angle and magnitude. polar(mag, angle) returns a complex number.Rotation of point X about a point YTo rotate a point about another point, we will use translation in which movement of all coordinates occur in a particular direction.Steps to rotate X about Y.Translate X to Y, so Y becomes the new ... Read More

Relational Operators on STL Array in C++

Sunidhi Bansal
Updated on 28-Jul-2020 10:39:05

376 Views

There are six relational operators for comparison of operands of the same type. These are >,

Read/Write Class Objects from/to File in C++

Sunidhi Bansal
Updated on 05-Oct-2023 01:10:37

39K+ Views

The iostream standard library has two methods cin, to accept input from standard input stream and cout to print output to the standard output stream. In this article we will learn how to read data from files into class objects and how to write data in class objects to files.Reading and writing data to and from files requires another standard library of C++ . The three main data types of fstream are −ifstream − represents input file stream and reads information from files.ofstream − represents output file stream and writes information to files.fstream − represents general file stream and has ... Read More

Count columns to be deleted to make each row sorted in C++

Sunidhi Bansal
Updated on 28-Jul-2020 10:33:43

139 Views

The abnormal behavior of C++ programs often leads to program crash. You may have encountered problems like Segmentation fault, Aborted, Floating point exception etc. Following are sample programs that may help you to understand the reasons for a C++ program crash.ExceptionsExceptions in C++ are responses of a program when it encounters an abnormal condition. The program crashes due to such exceptions if they are not handled properly using try-catch blocks. Following program crashes due to divide by zero exception −Example#include int main(){    int num1=10;    int num2=0;    int quotient=num1/num2;    printf(" Quotient is: %d", quotient);    return ... Read More

Range-based for loop in C++

Sunidhi Bansal
Updated on 28-Jul-2020 10:30:46

4K+ Views

The range based for loop is added in C++ 11 standard and is a more compact form of its traditional equivalent. The range based for loop is used to iterate over elements of a container from beginning to end. The syntax for range-based for loop is as follows −Syntaxfor( range-declaration : range-expression ) loop statementrange-declaration − it is declaration of a variable of type same as the type of elements of range-expression. Often the auto keyword is used to automatically identify the type of elements in range-expression.range-expression − any expression used to represent a sequence of elements. Also Sequence of ... Read More

Maximums from array when the maximum decrements after every access in C++

Ayush Gupta
Updated on 09-Oct-2020 09:33:33

123 Views

In this problem, we are given an array arr[]and an integer M. Our task is to create a program to find Maximums from array when the maximum decrements after every access in C++.Problem DescriptionTo find the maximum, we will find the maximum element from the array and after every retrieval and decrease it by -1, M times.Let’s take an example to understand the problem, Input: arr[] = {3, 6, 8, 9} M = 2Ouput:17Explanation1st iteration, maximum = 9, sum = 9, updated arr = {3, 6, 8, 8}2nd iteration, maximum = 8, sum = 9+8 = 17, updated arr = ... Read More

Maximum value with the choice of either dividing or considering as it is in C++ program

Ayush Gupta
Updated on 09-Oct-2020 09:34:55

251 Views

In this problem, we are given a number N. Our task is to create a program to find to Maximum value with the choice of either dividing or considering as it is in C++.Problem DescriptionTo find the maximum, we can consider any two values, either by take the value as it is or we could get the maximum value by dividing.The value could be extracted as F(N/2) + F(N/3) + F(N/4) + F(N/5).Let’s take an example to understand the problem, Input:N = 8Output:9ExplanationF(8) =F(8/2) + F(8/3) + F(8/4) + F(8/5) = F(4) + F(2) + F(2) + F(1) = 4 ... Read More

Advertisements