Found 34494 Articles for Programming

C++ Program to Swap Numbers in Cyclic Order Using Call by Reference

George John
Updated on 25-Jun-2020 09:26:39

946 Views

Three numbers can be swapped in cyclic order by passing them to a function cyclicSwapping() using call by reference. This function swaps the numbers in a cyclic fashion.The program to swap numbers in cyclic order using call by reference is given as follows −Example Live Demo#include using namespace std; void cyclicSwapping(int *x, int *y, int *z) {    int temp;    temp = *y;    *y = *x;    *x = *z;    *z = temp; } int main() {    int x, y, z;    cout > y >> z;    cout

Static Data Members in C++

Ankith Reddy
Updated on 25-Jun-2020 09:29:34

20K+ Views

Static data members are class members that are declared using the static keyword. There is only one copy of the static data member in the class, even if there are many class objects. This is because all the objects share the static data member. The static data member is always initialized to zero when the first class object is created.The syntax of the static data members is given as follows −static data_type data_member_name;In the above syntax, static keyword is used. The data_type is the C++ data type such as int, float etc. The data_member_name is the name provided to the ... Read More

isspace() function in C++

Arjun Thakur
Updated on 25-Jun-2020 09:31:06

3K+ Views

The isspace() function is a predefined function in ctype.h. It specifies whether the argument is a whitespace character or not. Some of the whitespace characters are space, horizontal tab, vertical tab etc.A program that implements isspace() function by counting the number of spaces in a string is given as follows −Example Live Demo#include #include using namespace std; int main() {    char str[] = "Coding is fun";    int i, count = 0;    for(i=0; str[i]!='\0';i++) {       if(isspace(str[i]))       count++;    }    cout

Multiple Inheritance in C++

Chandu yadav
Updated on 25-Jun-2020 09:03:09

5K+ Views

Multiple inheritance occurs when a class inherits from more than one base class. So the class can inherit features from multiple base classes using multiple inheritance. This is an important feature of object oriented programming languages such as C++.A diagram that demonstrates multiple inheritance is given below −A program to implement multiple inheritance in C++ is given as follows −Example Live Demo#include using namespace std; class A {    public:    int a = 5;    A() {       cout

strstr() in C++

George John
Updated on 25-Jun-2020 09:04:00

1K+ Views

The strstr() function is a predefined function in string.h. It is used to find the occurance of a substring in a string. This process of matching stops at ‘\0’ and does not include it.Syntax of strstr() is as follows −char *strstr( const char *str1, const char *str2)In the above syntax, strstr() finds the first occurance of string str2 in the string str1. A program that implements strstr() is as follows −Example Live Demo#include #include using namespace std; int main() {    char str1[] = "Apples are red";    char str2[] = "are";    char *ptr;    ptr = strstr(str1, str2);    if(ptr)    cout

Substring in C++

Ankith Reddy
Updated on 07-Oct-2023 01:44:35

23K+ Views

A substring is a part of a string. A function to obtain a substring in C++ is substr(). This function contains two parameters: pos and len. The pos parameter specifies the start position of the substring and len denotes the number of characters in a substring.A program that obtains the substring in C++ is given as follows −Example Live Demo#include #include using namespace std; int main() {    string str1 = "Apples are red";    string str2 = str1.substr(11, 3);    string str3 = str1.substr(0, 6);    cout

C++ Program to Perform Addition Operation Using Bitwise Operators

Arjun Thakur
Updated on 25-Jun-2020 09:05:32

1K+ Views

Bitwise operators are used to perform bitwise operations. That implies the manipulation of bits. Some of the bitwise operators are bitwise AND, bitwise OR, bitwise XOR etc.A program to perform addition operation using bitwise operators is given below −Example Live Demo#include using namespace std; int main() {    int num1, num2, carry;    cout

C++ Program to Use rand and srand Functions

Chandu yadav
Updated on 25-Jun-2020 09:06:34

406 Views

Random numbers can be generated in C++ using the rand() function. The srand() function seeds the random number generator that is used by rand().A program that uses rand() and srand() is given as follows −Example Live Demo#include #include #include using namespace std; int main() {    srand(1);    for(int i=0; i

C++ Program to Sort Elements in Lexicographical Order (Dictionary Order)

Arjun Thakur
Updated on 25-Jun-2020 09:08:19

1K+ Views

Lexicographical order denotes the way the words are ordered in a list, based on alphabetical order according to their alphabets. For example −List of words: Harry Adam Sam Lexicographical order of words: Adam Harry SamA program to sort elements in lexicographical order is as follows −Example Live Demo#include using namespace std; int main() {    int i,j;    string s[5], temp;    cout

C++ Program to Add Complex Numbers by Passing Structure to a Function

Chandu yadav
Updated on 25-Jun-2020 09:09:47

602 Views

Complex numbers are numbers that are expressed as a+bi where i is an imaginary number and a and b are real numbers. Some examples on complex numbers are −2+5i 3-9i 8+2iA program to add complex numbers by passing structure to a function is given as follows −Example Live Demo#include using namespace std; typedef struct complexNumber {    float real;    float imag; }; complexNumber addCN(complexNumber num1, complexNumber num2) {    complexNumber temp;    temp.real = num1.real + num2.real;    temp.imag = num1.imag + num2.imag;    return(temp); } int main() {    complexNumber num1, num2, sum;    cout num1.real; ... Read More

Advertisements