Found 7347 Articles for C++

Reverse a link list using stack in C++

Ajay yadav
Updated on 29-Nov-2019 10:59:50

131 Views

Linked list allocates memory dynamically, is used to implement a stack. This program showcase the reversal of the link list in c++ programming. Here, the aspirant can adopt the following approach to get the expected results. The algorithm is as follows;AlgorithmSTART    Step 1: create an empty stack of type node pointer    Step 2: Traverse the list and push all of its nodes onto a stack    Step 4: Traverse the list from the head node again    Step 5: pop a value from the stack top    step 6: connect them in reverse order    Step 7: PRINT ... Read More

Replacing space with a hyphen in C++

Ajay yadav
Updated on 29-Nov-2019 10:55:18

2K+ Views

In this C++ program, the space in the string will be replaced with the hyphen. Firstly, the length of the string is determined by the length() function of the cstring class, then hyphen is filled into the space of the sentence by traversing the string as follows.Example Live Demo#include #include using namespace std; int main(){    // raw string declaration    string str = "Coding in C++ programming";    cout

Sqrt, sqrtl, and sqrtf in C++ programming

Ajay yadav
Updated on 29-Nov-2019 10:52:02

173 Views

Math ClassThis article demonstrates the usage of math class essentials functions sqrt(), sqrtl(), and sqrtf() to calculate the square root of double, long, and float type variables with precision respectively. The Math class of C++ offers a wide range of functions to calculate mathematical calculations including sin, cos, square root, ceil, floor, etc..It is, therefore, mandatory to import the definition of header class library in the program in order to avail all calculative methods.Sqrt MethodThe double sqrtl () method of the Math class returns the square root of a double variable with precision. The syntax of this function is ... Read More

String at () in C++

Ajay yadav
Updated on 29-Nov-2019 10:46:04

460 Views

AbstractThis short tutorial is an overview of the C++ String class at() functionality in order to access a sequence of characters from the string. In the forthcoming section, an aspiring reader can through string class programming examples to get a thorough understanding of the manipulation of at() functions.String ClassIn programming terms, the strings are typical, a double-quotes representation, contain a collection of characters. The string class is a container class too, to iterate over all its characters using an iterator operator []. Besides, The String class handles all operations related to memory and null termination. Anyone can perform plenty of ... Read More

Swap Upper diagonal with Lower in C++

Ajay yadav
Updated on 29-Nov-2019 10:42:25

185 Views

This tutorial is designed to swap the upper row of a three-diagonal array to its lower one using c++ code. Moreover, if a three-diagonal array is an input, the coveted results must be something like that as;For this, the course of action is briefed in the algorithm as follows;AlgorithmStep-1: Input a diagonal array Step-2: Pass it to Swap() method Step-3: Traverse the outer loop till 3 Step-4: increment j= i+ 1 in the inner loop till 3 Step-5: put the array value in a temp variable Step-6: interchange the value arr[i][j]= arr[j][i] Step-7: put the temp data to arr[j][i] Step-8: ... Read More

Toggle all characters in the string in C++

Ajay yadav
Updated on 29-Nov-2019 10:38:12

739 Views

This program translates the characters of a string into uppercase. However, this task can be easily achieved by using the toUpper() method of the c++ class library. But in this program, we perform this by calculating the ASCII value of characters in uppercase. The Algorithm is as follows;AlgorithmSTART    Step-1: Declare the array of char    Step-2: Check ASCII value of uppercase characters which must grater than A and lesser than Z    Step-3: Check ASCII value of lower characters which must grater than A and lesser than Z ENDThe toggleChar() method gets the array of characters as an input. ... Read More

Write a program for Happy Woman’s Day in c++

Ajay yadav
Updated on 29-Nov-2019 10:35:27

340 Views

The woman day which is celebrated on 7th October worldwide is carved into a c++ programming code as following;Example#include using namespace std; int main(){    // Initializing size of    // design    int n = 5;    // Loop to print Circle    // (Upper part of design)    // Outer loop to    // control height of    // design    for (int i = 0; i

Difference between Go and C++.

Mahesh Parahar
Updated on 28-Nov-2019 10:46:55

279 Views

GoGo is a procedural programming language. Programs are assembled using packages. It supports environment adopting patterns similar to dynamic languages.C++C++ is an object oriented programming language. C++ is quiet fast, reliable and secure. It is most widely used language as well.Following are the important differences between Go and C++.Sr. No.KeyGoC++1TypeGo is a procedural programming language and supports patterns similar to dynamic languages.C++ is an object oriented programming language.2Supports for ClassGo has no support for class with constructors.C++ has support for class with constructors.3Garbage CollectionGo has automatic garbage collection.C++ has not provided automatic garbage collection.4InheritanceGo has no support for inheritance.C++ supports ... Read More

Minimum operations required to set all elements of binary matrix in C++

Narendra Kumar
Updated on 22-Nov-2019 11:58:52

143 Views

Problem statementGiven a binary matrix of N rows and M columns. The operation allowed on the matrix is to choose any index (x, y) and toggle all the elements between the rectangle having top-left as (0, 0) and bottom-right as (x-1, y-1). Toggling the element means changing 1 to 0 and 0 to 1. The task is to find minimum operations required to make set all the elements of the matrix i.e make all elements as 1.ExampleIf input matrix is {0, 0, 0, 1, 1}    {0, 0, 0, 1, 1}    {0, 0, 0, 1, 1}    {1, 1, ... Read More

Minimum operations to make the MEX of the given set equal to x in C++

Narendra Kumar
Updated on 22-Nov-2019 11:57:49

476 Views

Problem statementGiven a set of n integers, perform minimum number of operations (you can insert/delete elements into/from the set) to make the MEX of the set equal to x (that is given).Note − The MEX of a set of integers is the minimum non-negative integer that doesn’t exist in it. For example, the MEX of the set {0, 2, 4} is 1 and the MEX of the set {1, 2, 3} is 0ExampleIf n = 5 and x = 3 and array is {0, 4, 5, 6, 7} then we require minimum 2 operationsAlgorithmThe approach is to see that in ... Read More

Advertisements