C++ Articles

Page 593 of 597

Operations on struct variables in C

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 2K+ Views

Here we will see what type of operations can be performed on struct variables. Here basically one operation can be performed for struct. The operation is assignment operation. Some other operations like equality check or other are not available for stack.Example#include typedef struct { //define a structure for complex objects    int real, imag; }complex; void displayComplex(complex c){    printf("(%d + %di)", c.real, c.imag); } main() {    complex c1 = {5, 2};    complex c2 = {8, 6};    printf("Complex numbers are:");    displayComplex(c1);    displayComplex(c2); }OutputComplex numbers are: (5 + 2i) (8 + 6i)This works fine as ...

Read More

lrint() and llrint() in C++

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 189 Views

In this section we will see the lrint() and llring() in C++. At first let us discuss about the lrint().The lrint() function is used to round the fractional given value in the argument to an integral value using current rounding mode. The current mode is determined by using fesetround().>=This lrint() function takes the double or float or integer value as input parameter, and returns the long int value by rounding the fractional part into an integral part.Example#include #include #include using namespace std; main() {    int x = 40;    long int res;    fesetround(FE_DOWNWARD); // setting ...

Read More

Difference between while(1) and while(0) in C/C++

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 4K+ Views

Here we will see what are the differences between while(1) and while(0) in C or C++. The while is a loop of C or C++. Using this loop we can check one condition, and the statements inside the loop will be executed while the condition is true.The while(1) or while(any non-zero value) is used for infinite loop. There is no condition for while. As 1 or any non-zero value is present, then the condition is always true. So what are present inside the loop that will be executed forever. To come out from this infinite loop, we have to use ...

Read More

Printing 1 to 1000 without loop or conditionals in C/C++

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 641 Views

Here we will see how to print 1 to 1000 without loop or any conditional statements. As the loops cannot be used, so we can try recursions, but here another constraint that, we cannot use the conditions also. So the base case of the recursion will not be used.Here we are solving this problem using static members. At first we are initializing the static member with 1, then in the constructor we are printing the value and increase its value. Now create an array of 1000 objects of that class, so 1000 different objects are created, so the constructor is ...

Read More

What are __FILE__, __LINE__, and __FUNCTION__ in C++

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 7K+ Views

Here we will see what are the __FILE, __LINE__ and __FUNCTION__ in C++.The __FILE__This macro is used to get the path of the current file. This is useful when we want to generate log files. The following code will explain its functionality.Example#include using namespace std; int errorLog (const char* file, const std::string& msg){    cerr

Read More

C++ Program to Check whether Graph is a Bipartite using 2 Color Algorithm

Arjun Thakur
Arjun Thakur
Updated on 30-Jul-2019 335 Views

A bipartite graph is a graph in which if the graph coloring is possible using two colors i.e.; vertices in a set are colored with the same color. This is a C++ program to Check whether a graph bipartite or not using 2 color algorithm.Functions and pseudocodesBegin    1. Develop function isSafe() to check if the current color assignment       is safe for vertex v, i.e. checks whether the edge exists or not.       If it exists, then next check whether the color to be filled in       the new vertex is already used ...

Read More

C++ Program to Implement Gauss Jordan Elimination

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 6K+ Views

This is a C++ Program to Implement Gauss Jordan Elimination. It is used to analyze linear system of simultaneous equations. It is mainly focused on reducing the system of equations to a diagonal matrix form by row operations such that the solution is obtained directly.AlgorithmBegin    n = size of the input matrix    To find the elements of the diagonal matrix:    Make nested for loops j = 0 to n and i = 0 to n       The element in the first row and the first column is made 1       and then the ...

Read More

Why C++ does not have a virtual constructor?

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 4K+ Views

The virtual mechanism works only when we have a base class pointer to a derived class object.In C++, constructor cannot be virtual, because when constructor of a class is executed there is no virtual table in the memory, means no virtual pointer defined yet. So, the constructor should always be non-virtual.But virtual destructor is possible. Here is an exampleExample#include using namespace std; class b {    public:    b()    { cout

Read More

C++ Program to Generate Randomized Sequence of Given Range of Numbers

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 589 Views

At first let us discuss about the rand() function. rand() function is a predefined method of C++. It is declared in header file. rand() is used to generate random number within a range. Here min_n is the minimum range of the random numbers and max_n is the maximum range of the numbers. So rand() will return the random numbers between min_n to (max_n – 1) inclusive of the limit values. Here if we mention lower and upper limits as 1 and 100 respectively, then rand() will return values from 1 to (100 – 1). i.e. from 1 to 99.AlgorithmBegin ...

Read More

C++ Program to Implement Direct Addressing Tables

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 740 Views

This is a C++ program to implement Direct Addressing Tables. Direct Addressing Tables are used when each element has a key drawn from a universal set S = {0, 1, . . . ,n − 1} where n isn’t too large and each key is unique. It facilitates fast insertion, searching and deletion operations.Functions and pseudocodesBegin    insert():       Take the table variables word and key as argument.       T[ x.key ] = x, where x is a value of key.    delete():       Take the table variables word and key as argument.   ...

Read More
Showing 5921–5930 of 5,961 articles
« Prev 1 591 592 593 594 595 597 Next »
Advertisements