Class

C++ Program to Print Numbers From 1 to n Without Using Loops, Recursion or Goto Statement

You may have made program to print numbers from 1 to n using loops, recursion or goto statement. But have you ever thought about doing this without help of loops, recursion or goto? It can be done without using such things as explained in below program.Also Read: C program to find factorial of any number using …

C++ Program to Print Numbers From 1 to n Without Using Loops, Recursion or Goto Statement 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 »

C++ program to swap two numbers using class

#include<iostream.h> #include<conio.h> class swap { int a,b; public: void getdata(); void swapv(); void display(); }; void swap::getdata() { cout<<“Enter two numbers:”; cin>>a>>b; } void swap::swapv() { a=a+b; b=a-b; a=a-b; } void swap::display() { cout<<“a=”<<a<<“tb=”<<b; } main() { clrscr(); swap s; s.getdata(); cout<<“nBefore swap:n”; s.display(); s.swapv(); cout<<“nnAfter swap:n”; s.display(); getch(); return 0; }