Found 7401 Articles for C++

C++ Program to Implement the String Search Algorithm for Short Text Sizes

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

310 Views

In this C++ program, as input, a text and a pattern are given. As output, the pattern is searched in the text and all instances of the pattern are given.AlgorithmBegin    Take the string and pattern as input.    Declare the original and duplicate array with their size.    Put the lengths of original and duplicate in len_ori and len_dupli.    Make a loop for find out the position of the searched pattern.    If pattern is not found, print not found otherwise print the no of instances of the searched pattern. EndExample Code Live Demo#include #include using namespace std; ... Read More

C++ Program to Implement Bitap Algorithm for String Matching

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

309 Views

This is a C++ Program to Implement Bitap Algorithm for String Matching. The algorithm tells whether a given text contains a substring which is “approximately equal” to a given pattern, where approximate equality is defined in terms of Levenshtein distance — if the substring and pattern are within a given distance k of each other, then according to the algorithm they are equal. It begins by precomputing a set of bitmasks containing one bit for each element of the pattern. So we are able to do most of the work with bitwise operations, which are extremely fast.AlgorithmBegin    Take the ... Read More

Can a C++ virtual functions have default parameters?

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

675 Views

Yes, C++ virtual functions can have default parameters.Example Code Live Demo#include using namespace std; class B {    public:       virtual void s(int a = 0) {          cout

SQL using C/C++ and SQLite

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

2K+ Views

In this section, you will learn how to use SQLite in C/C++ programs.InstallationBefore you start using SQLite in our C/C++ programs, you need to make sure that you have SQLite library set up on the machine. You can check SQLite Installation chapter to understand the installation process.C/C++ Interface APIsFollowing are important C/C++ SQLite interface routines, which can suffice your requirement to work with SQLite database from your C/C++ program. If you are looking for a more sophisticated application, then you can look into SQLite official documentation.Serial NoAPI & Description1sqlite3_open(const char *filename, sqlite3 **ppDb)This routine opens a connection to an SQLite ... Read More

Calling virtual functions inside constructors in C++

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

176 Views

Virtual functions calling from a constructor or destructor is dangerous and should be avoided whenever possible as the virtual function we call is called from the Base class and not from the derived class.The reason is that in C++ Super-classes are constructed before derived classes. So, in the following example, as B must be instantiated, before D is instantiated. When B's constructor is called, it's not D yet, so the virtual function table still has the entry for B's copy of s().Example Code Live Demo#include using namespace std; class B {    public: B() {       s();    } ... Read More

Database Connectivity using C/C++

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

3K+ Views

In this section, you will learn how to use SQLite in C/C++ programs.InstallationBefore you start using SQLite in our C/C++ programs, you need to make sure that you have SQLite library set up on the machine. You can check the SQLite Installation chapter to understand the installation process.C/C++ Interface APIsFollowing are important C/C++ SQLite interface routines, which can suffice your requirement to work with SQLite database from your C/C++ program. If you are looking for a more sophisticated application, then you can look into SQLite official documentation.Serial NoAPI & Description1sqlite3_open(const char *filename, sqlite3 **ppDb)This routine opens a connection to an ... Read More

Difference between a virtual function and a pure virtual function in C++

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

5K+ Views

Following table shows the difference between Virtual and Pure Virtual Function:Virtual FunctionPure Virtual FunctionVirtual function has their definition in the class.Pure virtual function has no definition.Declaration: virtual funct_name(parameter_list) {. . . . .};Declaration: virtual funct_name(parameter_list)=0;It has no concept of derived class.If a class contains at least one pure virtual function, then it is declared abstract.If required, the base class can override a virtual function.In case of pure virtual function derived class has to definitely override the pure virtual function.virtual functionExample Code Live Demo#include using namespace std; class B {    public:       virtual void s() //virtual function { ... Read More

Pure virtual destructor in C++

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

438 Views

The pure virtual destructor is possible in C++. If a class contains pure virtual destructor it is must to provide a function body for the pure virtual destructor.Example Code Live Demo#include using namespace std; class B {    public:    virtual ~B()=0; // Pure virtual destructor }; B::~B() {    std::cout

Inline virtual function in C++

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

1K+ Views

Virtual functions in C++ use 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 the runtime.The main use of the virtual function is to achieve Runtime Polymorphism. The inline functions are used to increase the efficiency of the code. The code of inline function gets substituted at the point of an inline function call at compile time, whenever the inline function is called.Whenever a virtual function is called using base class reference or pointer it cannot be inlined, ... Read More

Assertions in C/C++

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

278 Views

Here we will see what is assertions in C/C++. The C library macro void assert(int expression) allows diagnostic information to be written to the standard error file. In other words, it can be used to add diagnostics in your C program.Following is the declaration for assert() Macro.void assert(int expression);The parameter of this assert() is expression − This can be a variable or any C expression. If expression evaluates to TRUE, assert() does nothing. If expression evaluates to FALSE, assert() displays an error message on stderr (standard error stream to display error messages and diagnostics) and aborts program execution.Example Code#include ... Read More

Advertisements