Nishtha Thakur has Published 564 Articles

Why is a C++ pure virtual function initialized by 0?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

2K+ Views

It’s just a syntax, nothing more than that for saying that “the function is pure virtual”.A pure virtual function is a virtual function in C++ for which we need not to write any function definition and only we have to declare it. It is declared by assigning 0 in declaration.Here ... Read More

How are virtual functions implemented in C++?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

587 Views

Virtual functions in C++ used to create a list of base class pointers and call methods of any of the derived classes without even knowing kind of derived class object. Virtual functions are resolved late, at runtime.Here is an implementation of virtual function in C++ program −Example#include using namespace ... Read More

Default virtual behavior in C++ vs Java

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

124 Views

In C++ methods are non-virtual by default. They can be made virtual function by using a virtual keyword.Example Code#include using namespace std; class B {    public: void s() //non virtual by default. Use virtual before the function to print “In Derived” {       cout

How do I INSERT INTO from one MySQL table into another table and set the value of one column?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

281 Views

Let us first create a table. Following is the query −mysql> create table insertOneToAnotherTable    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.60 sec)Following is the query to insert some records in the table using insert command −mysql> insert into insertOneToAnotherTable values(100); Query ... Read More

C++ Program to Implement Coppersmith Freivald’s Algorithm

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

383 Views

Freivalds' algorithm determines whether the matrices are equal for a chosen k value with a probability of failure less than 2^-k in O(kn^2).It is used to verify matrix multiplication.AlgorithmBegin    Take matrix1(n*n), matrix2(n*n), matrix3(n*n) as input.    // According to the algorithm we have to verify:    // matrix1 × ... Read More

Template Metaprogramming in C++

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

223 Views

When we write programs to do computation at compile time using a template, that is called Template Metaprogramming.Example Code#include using namespace std; templatestruct power {    enum { value = 4*power::value }; }; templatestruct power {    enum { value = 1 }; }; int main() {    cout

Why use static_cast(x) instead of (int)x in C++?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

2K+ Views

The (int)x is C style typecasting where static_cast(x) is used in C++. This static_cast() gives compile time checking facility, but the C style casting does not support that. This static_cast() can be spotted anywhere inside a C++ code. And using this C++ cast the intensions are conveyed much better.In C ... Read More

C++ Program to implement Slicker Algorithm that avoids Triangulation to find Area of a Polygon

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

83 Views

Here is a C++ program to find the area of polygon using slicker algorithm that avoids Triangulation to find area of a polygon.It assumes the usual mathematical convention that positive y points upwards. In computer systems where positive y is downward, the easiest thing to do is to list the ... Read More

C++ Program to Represent Linear Equations in Matrix Form

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

416 Views

This is a C++ program to represent Linear Equations in matrix form.AlgorithmBegin    1) Take the no of variables n and the coefficients of each variable as input.    2) Declare a matrix[n][n] and constant[n][1].    3) Make for loops i = 0 to n-1 and j = 0 to ... Read More

C++ Program to Check if a Point d lies inside or outside a circle defined by Points a, b, c in a Plane

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

206 Views

We shall consider a C++ Program to check if a point d lies inside or outside a circle defined by points a, b, c in a plane by using equations = (x-xt)^2 + (y-yt)^2 – r*rWhere, For any point t (xt, yt) on the plane, its position with respect to ... Read More

Advertisements