Search This Blog

GCM - Greatest Common Multiple Program in C++

Program to calculate GCM ( Greatest Commmon Multiple ) in C++ is given below:

// GCM - Greateset Common Multiple program in C++
#include "stdafx.h" //COMMENT THIS LINE IF IT CAUSES ERROR
#include <iostream>

Typecasting in C++

Typecasting in C++ is shown below by typecasting an integer to a character.

//integer to character typecasting
#include <iostream>
using namespace std;

Get System Time and Date in C++

This program gets system time and date in C++.

//How to get system time in C++.
#include <iostream>
#include <ctime>

Mouse Handling in C++

Following is the program for mouse handling in C++ when user left clicks.

#include <iostream>
using namespace std;

Dynamically allocate memory in C++

Dynamically allocate memroy in C++ using following program:


#include <iostream>
using namespace std;

Stack using linked list in C++


Stack using linked list in C++ program is given below:

//Stack using linked list in C++ using templates
#include <iostream>
using namespace std;

Stack using Link List in C++

Program to create a stack using link list in C++.

//Stack using Link List in C++
#include <iostream>
using namespace std;

Stack in C++ | Program to create a stack in C++

Stack in C++ program is given below:

//Stacks in C++
#include <iostream>
using namespace std;

Swap without using variable - C++


Swap two values without using a variable in C++ program is given below:

//Program to swap 2 numbers without using a variable in C++.
#include <iostream>
using namespace std;

Binary Tree in C++


Binary Tree program in C++ is given below:

See First: Binary Tree in C++ (A relatively easier Binary Tree program)

// Binary Tree in C++
// Binary Tree program to insert generically in the binary tree.

#include "stdafx.h" //Comment This line if it creates error.
#include <iostream>
using namespace std;

Printing Linked List Recursively in C++

Printing Linked List Recursively in C++ Program is given below:


// Printing Linked List Recursively in C++
// Linked List is created by inserting at head and then printing recursively.
#include <iostream>
using namespace std;

Operator Overloading: Overload << and >> operator


Overload << and >> operator program is given below:

// operator overloading
// overloading << and >> operator
#include "stdafx.h" //Delete this line if it creates error
#include <iostream>
using namespace std;
const int LEN = 80;           //maximum length of names
////////////////////////////////////////////////////////////////
class employee                        //employee class
{
private:
char name[LEN];                 //employee name
unsigned long number;
public:
friend istream& operator >> (istream& s, employee& e);
friend ostream& operator << (ostream& s, employee& e);
};
//-------------------------------------------------------------
istream& operator >> (istream& s, employee& e){
cout << "Name: "; s.getline(e.name,LEN,'\n');
cout << "Number: "; s >> e.number;
return s;
}
//-------------------------------------------------------------
ostream& operator << (ostream& s, employee& e){
cout << "Name: " << e.name << endl
<< "Number: " << e.number << endl;
return s;
}
///////////////////////////////////////////////////////////////
int main(){
employee oe; // oe => object of class employee.
cin >> oe;
cout << oe;
return 0;
}

Printing Linked List in Reverse Order Recursively in C++


Printing Linked List in Reverse Order Recursively in C++ Program is given below:

// Printing Linked List in Reverse Order Recursively in C++
// Insertion at head is done in the following program
#include <iostream>
using namespace std;

////////////////////////////////////////////////////////////////
struct link                           //one element of list
{
int data;                          //data item
link* next;                        //pointer to next link
};
////////////////////////////////////////////////////////////////
class linklist                        //a list of links
{
private:
link* first;                    //pointer to first link also known as head.
public:
linklist()                      //no-argument constructor
{ first = NULL; }            //no first link
link* getHead(){ return first; }
void additem(int d);            //add data item (one link)
void displayRecursivelyReversed(link* current);                 //display all links in REVERSE ORDER.
};
//-------------------------------------------------------------void
void linklist::additem(int d)         //add data item
{
link *newLink = new link;
newLink->data = d;
//insert at head
newLink->next = first;
first = newLink;
}
//-------------------------------------------------------------void
void linklist::displayRecursivelyReversed(link* current)              //display all links
{
if (current != NULL){
//move to next node.
displayRecursively(current->next);
cout << current->data << endl;
}

}
////////////////////////////////////////////////////////////////
int main()
{
linklist li;       //make linked list
li.additem(25);    //add four items to list
li.additem(36);
li.additem(49);
li.additem(64);
li.displayRecursivelyReversed(li.getHead());      //display entire list
return 0;
}
"Don't let anyone ever make you feel like you don't deserve what you want."