C++ Templates: Program to Swap Two Numbers Using Function Template

What are Templates in C++? Templates help in defining generic classes and functions and hence allow generic programming. Generic programming is an approach where generic data types are used as parameters and the same piece of code work for various data types. Function templates are used to create family of functions with different argument types. …

C++ Templates: Program to Swap Two Numbers Using Function Template Read More »

C++ Program That Defines a Class String and Overload == Operator to Compare Two Strings [Operator Overloading Concept]

#include<iostream> #include<stdio.h>                             //used for gets() #include<string.h>                           //used for strcmp() using namespace std; class String {         char str[20];         public:         void getdata()                            //function to read the string         {                 gets(str);         }         //operator function to overload comparison operator and compare two strings         int operator ==(String s)         …

C++ Program That Defines a Class String and Overload == Operator to Compare Two Strings [Operator Overloading Concept] Read More »

C++ program for overloading binary operators, addition, subtraction, multiplication, division and comparison

In this program we will first create a class demo that contains two float data members a and b. Values of objects d1 and d2 are entered by user and then arithmetic operations are performed on them by overloading binary operators and result is stored in object d3. The code for the program is given …

C++ program for overloading binary operators, addition, subtraction, multiplication, division and comparison Read More »