Found 7347 Articles for C++

C++ Program to Find the Number of Permutations of a Given String

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

1K+ Views

We can arrange the characters of a string in different order. Here we will see how we can count the number of permutations can be formed from a given string.We know that if one string is ‘abc’. It has three characters; we can arrange them into 3! = 6 different ways. So a string with n characters, we can arrange them into n! different ways. But now if there are same characters are present for multiple times, like aab, then there will not be 6 permutations.abaaabbaabaaaababaHere the (1, 6), (2, 5), (3, 4) are same. So here the number of ... Read More

Listing modified, old and newly created files on Linux using C++

George John
Updated on 30-Jul-2019 22:30:26

205 Views

Here we will see how to list the modified files and old and newly created files on Linux platform using C++ program.The task is very simple. We can use the Linux shell command to get the files in desired order. The ls –l command is used to get all of the files in long listing format. Here we will add more options to sort them based on time. (Ascending and Descending). The –t command is used to sort based on time, and –r can be added to reverse the sequence.The command will be like below:ls –lt ls –ltrWe will use ... Read More

C++ Program to Check Whether a Directed Graph Contains a Eulerian Path

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

380 Views

The Euler path is a path; by which we can visit every edge exactly once. We can use the same vertices for multiple times. One graph which contains Euler Circuit is also considered in this case, as it also has the Euler path.To check whether a directed graph has Euler path or not, we have to check these conditions -There must be one single vertex an where (in-degree + 1 = out_degree)There must be one single vertex bn where (in-degree = out_degree + 1)Rest all vertices have (in-degree = out_degree) if any of these cases fails, the graph has no ... Read More

C++ Program to Check Whether an Undirected Graph Contains a Eulerian Path

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

918 Views

The Euler path is a path; by which we can visit every node exactly once. We can use the same edges for multiple times. The Euler Circuit is a special type of Euler path. When the starting vertex of the Euler path is also connected with the ending vertex of that path.To detect the Euler Path, we have to follow these conditionsThe graph must be connected.Now when no vertices of an undirected graph have odd degree, then it is a Euler Circuit, which is also one Euler path.When exactly two vertices have odd degree, it is a Euler Path.InputOutputBoth of ... Read More

C++ Program to Check Whether an Undirected Graph Contains a Eulerian Cycle

George John
Updated on 30-Jul-2019 22:30:26

339 Views

To know about Euler Circuit, we have the idea about Euler Path. The Euler path is a path; by which we can visit every node exactly once. We can use the same edges for multiple times. The Euler Circuit is a special type of Euler path. When the starting vertex of the Euler path is also connected with the ending vertex of that path.To detect the circuit, we have to follow these conditions:The graph must be connected.Now when no vertices of an undirected graph have odd degree, then it is a Euler Circuit.InputOutputThe graph has Euler Circuit.Algorithmtraverse(u, visited)Input The start ... Read More

C++ Program to Perform Sorting Using B-Tree

Chandu yadav
Updated on 30-Jul-2019 22:30:26

351 Views

Here we will see how to get the sorted sequence using B-Tree. The B-tree is n-ary tree. To get the sorted sequences, we can create a B-tree, then add the numbers into it. Here the B-tree can hold maximum 5 nodes. If number of nodes increases, split the node and form new level. As the nodes are holding few number of elements like 5 (at most), we are using Bubble sorting techniques to sort them. as the number of elements is very low, then it will not affect too much on its performance.After traversing the tree, we will get all ... Read More

Fesetround() and fegetround() in C++

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

76 Views

Here we will see the fesetround() and fegetround() method in C++. These methods can be found in the cfenv library.The fesetround() method is used to set the specified floating point rounding direction to the current rounding direction. This is used with rint(), nearbyint() and some other rounding functions in C++.The syntax is like below −int fesetround(int round);The round can be among these FE_TONEAREST, FE_DOWNWARD, FE_UPWARD etc. This function returns 0 when rounding direction is successfully applied to the required manner.Example#include #include #include using namespace std; main() {    double x = 4.7, ans;    fesetround(FE_TONEAREST); //round to ... Read More

Hiding of all overloaded methods in base class in C++

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

427 Views

In C++, we can use the function overloading techniques. But if some base class has one method in overloaded form (different function signature with the same name), and the derived class redefines one of the function which is present inside the base, then all of the overloaded version of that function will be hidden from the derived class.Let us see one example to get the clear idea.Example#include using namespace std; class MyBaseClass {    public:       void my_function() {          cout

Inheritance and friendship in C++

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

2K+ Views

In C++, the friendship is not inherited. It means that, if one parent class has some friend functions, then the child class will not get them as friend.In this example it will generate an error because the display() function is friend of MyBaseClass but not the friend of MyDerivedClass. The display() can access the private member of MyBaseClass.Example#include using namespace std; class MyBaseClass {    protected:       int x;    public:       MyBaseClass() {          x = 20;       }       friend void display(); }; class MyDerivedClass : public MyBaseClass {    private:       int y;    public:       MyDerivedClass() {          x = 40;       } }; void display() {    MyDerivedClass derived;    cout

Extending namespace and Unnamed namespace

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

192 Views

Here we will see how we can extend some namespace, and how the unnamed or anonymous name space can be used.Sometimes we can define one namespace. Then we can write the namespace again with the same definition. If the first one has some member, and second one has some other members, then the namespace is extended. We can use all of the members from that namespace.Example#include using namespace std; namespace my_namespace {    int my_var = 10; } namespace my_namespace { //extending namespace    int my_new_var = 40; } main() {    cout

Advertisements