C/C++ Program to check whether a string is palindrome or not using string functions [DEVCPP/GCC]

PROGRAM

//Program to check whether a string is palindrome or not using string functions.

#include <iostream>
#include <string.h>              
using namespace std;

int main()
{
char str1[10],str2[10],c;

do
{
cout<<"\nENTER A STRING: ";
cin>>str1;

strcpy(str2,str1);                        //copies the content of str1 to str2

strrev(str1);                                //reverses str1 

if(strcmp(str1,str2)==0)            //compares str1 and str2
cout<<"GIVEN STRING IS PALINDROME";
else
cout<<"GIVEN STRING IS NOT PALINDROME";

cout<<"\n\nDO YOU WISH TO CONTINUE (Y/N)? ";
cin>>c;

  }while(c=='y'||c=='Y');

return 0;
}

OUTPUT

C++ Program to check whether a string is palindrome or not using string functions

C++ Program to print the pattern of alphabet [DEVCPP/GCC]

/*Program to print the pattern of alphabets.

A
BC
DEF
GHIJ
KLMNO

*/

PROGRAM

# include <iostream>

using namespace std;

int main()
{
char c='A';
int i,j,rows;

cout<<"ENTER THE NUMBER OF ROWS:\n";
cin>>rows;
cout<<"\nPATTERN FORMED:\n";

for(i=1;i<=rows;i++)
{
for(j=1;j<=i;j++)
{
                       if(c=='Z')
                       {
                               cout<<c;
                               c='A';
                               continue;
                       }
cout<<c;
c++;
}
cout<<endl;
}

       return 0;
}

OUTPUT

C++ Program to print the pattern of alphabet

C++ Program to illustrate function overloading [DEVCPP/GCC]


FUNCTION OVERLOADING

C++ allows specification of more than one function under the same name in the same scope. These functions must have different signatures and are called overloaded functions. Overloading of functions allow programmer to define different semantics for a function, depending upon number and type of arguments.

For instance, in order to find maximum number, the function max() can be overloaded as:

int max (int num1, int num2);
int max (int num1, int num2, int num3);

Although functions can be distinguished on the basis of return type, they cannot be overloaded on this basis. 

PROGRAM

/* Program to calculate area of square, rectangle and circle using overloaded function area */

#include <iostream>

using namespace std;

float area( int length, int breadth )
{
        return (length * breadth);
}

float area( int side )
{
        return (side * side);
}

float area( float radius )
{
        return (3.14 * radius * radius);
}

int main()
{
        char ch='y';
        int s,c,l,b;
        float r;

        do
        {
              cout<<"\n\n\t***AREA CALCULATOR***";
              cout<<"\n 1. SQUARE";
              cout<<"\n 2. RECTANGLE";
              cout<<"\n 3. CIRCLE";
              cout<<"\n 4. EXIT";
              cout<<"\nENTER YOUR CHOICE(1-4): ";
              cin>>c;

              switch(c)
              {
                      case 1:
                      {
                              cout<<"\nENTER SIDE: ";
                              cin>>s;

                              cout<<"AREA OF SQUARE: "<<area(s);
                              break;
                    }

                    case 2:
                      {
                              cout<<"\nENTER LENGTH: ";
                              cin>>l;
                              cout<<"ENTER BREADTH: ";
                              cin>>b;

                              cout<<"AREA OF RECTANGLE: "<<area(l,b);
                              break;
                      }

                      case 3:
                      {
                               cout<<"\nENTER RADIUS: ";
                               cin>>r;

                               cout<<"AREA OF CIRCLE: "<<area(r);
                               break;
                       }

                       case 4:
                       {
                                exit(0);
                        }

                        default:
                        {
                                 cout<<"YOU ENTERED WRONG CHOICE!";
                        }
             }

             cout<<"\n\nDO YOU WANT TO CONTINUE(Y/N): ";
             cin>>ch;

         }while(ch=='Y' || ch=='y');
}

OUTPUT


C++ Program to illustrate function overloading


C++ Program to illustrate the difference between call by value and call by reference [DEVCPP/GCC]

CALL BY VALUE

In call by value, a copy of actual parameter is passed to the calling function. The passed value to the function is locally stored by the function parameter in stack memory. Here both formal parameters and actual parameters share different address apace. Thus any changes in formal parameters is not reflected back in actual parameters.

CALL BY REFERENCE

In call by reference, reference(address) of the actual parameters is passed to the calling function (See Reference Variables). It results in creation of alias for the actual parameters and both actual parameters and formal parameters refers to the same memory location. Thus any changes in formal parameters is reflected back in actual parameters.

PROGRAM

// Program to illustrate the difference between call by value and call by reference

#include <iostream>

using namespace std;

void callByValue(int n)
{
        n=n*n;
        cout<<"\nNUM IN FUNCTION: "<<n;
}

void callByReference(int &n)
{
        n=n*n;
        cout<<"\nNUM IN FUNCTION: "<<n;
}

int main()
{
        int num;

        cout<<"\nENTER A NUMBER: ";
        cin>>num;

        cout<<"\n\nCALLING BY VALUE!\n";
        callByValue(num);

        cout<<"\nNUM IN MAIN: "<<num;

        cout<<"\n\nCALLING BY REFERENCE!\n";
        callByReference(num);

         cout<<"\nNUM IN MAIN: "<<num;
 return 0;
}

OUTPUT

C++ Program to illustrate the difference between call by value and call by reference with output

C++ Program to generate random number [DEVCPP/GCC]

RAND FUNCTION

It is a pseudo random generator which generates a random number between 0 and RAND_MAX. In order to generate random number in user defined range, this function can be used with modulus operator.

// Generates random number between 0 to 99      
int r1 = rand() % 100;                          

// Generates random number between 1 to 100     

int r2 = rand() % 100 + 1;                      

PROGRAM

/* Program to make user guess a number and comparing it with randomly generated number */

#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
        int count=0,rno,num;

        rno = rand()%10 + 1;

        do
        {

                cout<<"\nENTER A NUMBER BETWEEN 1 TO 10: ";
                cin>>num;

                if(num==rno)
                {
                          cout<<"\nBINGO!";
                }
                else if(num<rno)
                {
                          cout<<"\nRAISE YOUR NUMBER!";
                }
                else
                {
                          cout<<"\nLOW YOUR NUMBER!";
                }

                count++;

         } while(num!=rno);

          cout<<"\nYOUR SCORE IS "<<count;

           return 0;
}

OUTPUT

C++ Program to generate random number with output

C++ Program to display the pattern of diamond [DEVCPP/GCC]

PROGRAM

//Program to display the pattern of diamond!

# include <iostream>
using namespace std;

int main()
{
int rows,uh,lh,i,j,k;

cout<<"ENTER THE NUMBER OF ROWS:";
cin>>rows;

//Calculating the rows to be dedicated for the upper triangular part
uh=(rows/2)+1;  

       //Calculating the rows to be dedicated for the lower triangular part
       lh=(rows-uh);      

for(i=1;i<=uh;i++)          //Printing upper triangle
{
for(j=(uh-i);j>0;j--)
{
cout<<" ";
}
for(k=1;k<(2*i);k++)
{
cout<<"*";
}
cout<<endl;
}

for(i=lh;i>0;i--)               //Printing lower triangle
{
for(j=0;j<=(lh-i);j++)
{
cout<<" ";
}
for(k=1;k<(2*i);k++)
{
cout<<"*";
}
cout<<endl;
}

return 0;
}


OUTPUT

C++ Program to display the pattern of diamond with output

C++ Program to remove duplicate elements from an array [DEVCPP/GCC]

PROGRAM

// Program to remove duplicate elements from an array

#include <iostream>

using namespace std;

int main()
{
        int i,j,k,len=0;

        cout<<"ENTER THE NUMBER OF ELEMENTS: ";
        cin>>len;

        int num[len];

        cout<<"\nENTER ELEMENTS: ";

        for(i=0 ; i<len ; i++)
        {
                   cin>>num[i];
         }

        for(i=0 ; i<len ; i++)
        {
                for(j=i+1 ; j<len ; j++)
                {
                        if(num[i]==num[j])
                        {
                                 for(k=j ; k<len ; k++)
                                 {
                                            num[k]=num[k+1];
                                  }

                                  len--;
                                  j--;
                       }
                }
          }

          cout<<"\nDISTINCT ELEMENTS: ";

          for(i=0 ; i<len ; i++)
          {
                  cout<<num[i]<<" ";
           }

            return 0;
}

OUTPUT

C++ Program to remove duplicate elements from an array with output


C++ Program to sum elements passed through Command Line Arguments [DEVCPP/GCC]

COMMAND LINE ARGUMENTS

Command Line Arguments are optional string type arguments which can be passed to the program by the Operating System when it is launched.

The full declaration of main is

int main( int argc, char *argv[])

Here, argc refers to Argument Count which contains the number of arguments passed to the main function including a parameter as path of the program. argv is an array of character pointers which contains the arguments. The first argument argv[0] contains the path of program.

To pass Command Line Arguments in DevC++, you need to do the following:

C++ Program to sum elements passed through Command Line Arguments
                         

                           C++ Program to sum elements passed through Command Line Arguments

PROGRAM

//Program to sum elements passed through Command Line Arguments

#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[])
{
        int i,sum=0;

        cout<<"\nARGUMENT COUNT: "<<argc;
        cout<<"\nARGUMENT VALUES: ";

        for(i=0;i<argc;i++)
        {
                cout<<" "<<argv[i];
                if(i!=0)
                {
                           sum=sum+atoi(argv[i]);
                }
        }

        cout<<"\nSUM OF THE ELEMENTS: "<<sum;

        return 0;
}

OUTPUT

C++ Program to sum elements passed through Command Line Arguments with output

C++ Program to check whether given string is palindrome or not [DEVCPP/GCC]


PALINDROME

A palindrome is a word or phrase which is read same from forward as well as from backwards. Spaces or punctuations are usually not taken into consideration for Palindromes.

WORD PALINDROMES
  • Madam
  • Racecar
  • Level
  • Radar
  • Refer
PHRASE PALINDROMES
  • Draw pupil's lip upwards.
  • Rise to vote, Sir!
  • Step on no pets!

PROGRAM

// Program to check whether given string is palindrome or not

#include <iostream>
#include <string>

using namespace std;

int main()
{
int i,len;
string str,strws;
bool flag=true;
cout<<"ENTER A STRING: ";
getline(cin,strws);
len=strws.length();
/*Removing Spaces and Punctuations From String and Converting into Lowercase*/
for(i=0;i<len;i++)
{
if('A'<=strws[i] && strws[i]<='Z')
{
strws[i]=strws[i]+32;
}
if('a'<=strws[i] && strws[i]<='z')
{
str.push_back(strws[i]);
}
}

len=str.length();

for(i=0;i<=(len/2);i++)
{
if(str[i]!=str[len-i-1])
{
flag=false;
break;
}
}
if(flag)
{
cout<<"\nGIVEN STRING IS A PALINDROME!";
}
else
{
cout<<"\nGIVEN STRING IS NOT A PALINDROME!";
}
return 0;
}

OUTPUT

C++ Program to check whether given string is palindrome or not with output

C++ Program to add the distinct elements of an array [DEVCPP/GCC]


PROGRAM

//Program to add the distinct elements of an array

# include <iostream>
using namespace std;

int main()
{
int arr[5],i,j,sum=0;
     bool flag;

cout<<"ENTER THE ELEMENTS OF AN ARRAY:\n";
for(i=0;i<5;i++)     // Input an array
{
cin>>arr[i];
}

for(i=0;i<5;i++)
{
flag=true;
for(j=0;j<i;j++)
{
if(arr[i]==arr[j]) //check for uniqueness
{
flag=false;
break;
}
}
if(flag)
{
sum=sum+arr[i]; //summation of distinct elements
}
}

cout<<"SUM IS:"<<sum;
return 0;
}

OUTPUT

C++ Program to add the distinct elements of an array with output

C++ Program to illustrate reference variable [DEVCPP/GCC]


REFERENCE VARIABLE

C++ allows to create a reference to an existing variable. It provides a new name to an existing variable. Once a reference is created for a variable, either the variable name or reference name can be used to refer the variable.

The reference variable internally works as an constant pointer i.e. Once a reference is created for a variable, then it can't be changed. It is dereferenced internally without the use of dereferencing operator(*).

PROGRAM

// Program to illustrate reference variable

#include <iostream>

using namespace std;

int main()
{
       int num;

       cout<<"\nENTER A NUMBER: ";
       cin>>num;

int &RefToNum = num;

// RefToNum is a reference variable referring to num

       cout<<"\nVALUE OF NUM: "<<num;
       cout<<"\nVALUE OF REFERENCE TO NUM: "<<RefToNum;

       cout<<"\n\nSQUARING NUM...";

       num = num*num;

       cout<<"\n\nVALUE OF NUM: "<<num;
       cout<<"\nVALUE OF REFERENCE TO NUM: "<<RefToNum;

/* Both variable results in the same value as
they are operating on the same memory location */

       return 0;
}

OUTPUT

C++ Program to illustrate reference variable with output

C++ Program to illustrate reference variable


C++ Program to perform addition of two numbers using pointers [DEVCPP/GCC]

PROGRAM

//Program to perform addition of two numbers using pointers

#include <iostream>

using namespace std;

int main()
{
int x,y,sum;

cout<<"ENTER FIRST NUMBER: ";
cin>>x;
cout<<"ENTER SECOND NUMBER: ";
cin>>y;

int *p1=&x;
int *p2=&y;

sum= (*p1)+(*p2);

cout<<"SUM OF "<<x<<" AND "<<y<<" IS "<<sum;
return 0;
}

OUTPUT

C++ Program to perform addition of two numbers using pointers with output


C++ Program to perform addition of two numbers using pointers with output

C++ Introduction to Pointers


VARIABLES

A variable is an abstraction of a memory cell. These are named memory locations used to store a value. The address of a variable can be easily obtained by Address-of Operator(&).

 int num;                                                     
 cout<< &num;

POINTERS

Pointer is a powerful mechanism in C++ programming. Pointers are special variables that contains the address of another variable.

A pointer is declared as following:

 int *int_ptr;                                 
 char *char_ptr;                                                float *float_ptr;                                                        

After declaration, we can assign address of variables to a pointer.

 int num=10;                                                 
 int_ptr = &num;                                                               
 char ch='a';                                               
 char_ptr = &ch;                                                      
 float val=3.25;                                           
 float_ptr = &val;                                                        

A fundemental operation on pointers in Dereferencing i.e. referring to the object pointed by that pointer.

 cout<< *int_ptr;    //10                                     
 cout<< *char_ptr;   //a                                      
 cout<< *float_ptr;  //3.5  


C++ Introduction to Pointers


C++ Program to obtain Fibonacci series using recursion [DEVCPP/GCC]


PROGRAM

//Program to get the Fibonacci series using recursion 

# include <iostream>

using namespace std;

int fib(int n)
{
if(n==1||n==2)     //base condition
{
return 1;
}
else
        {
return fib(n-1)+fib(n-2);
         }
}

int main()
{
int i,num;
cout<<"ENTER THE NUMBER UPTO WHICH YOU WANT THE FIBBONACI SERIES TO          BE PRINTED:\n";
cin>>num;
cout<<"OUTPUT:\n";

for(i=1;i<=num;i++)
{
cout<<fib(i)<<" ";
}

return 0;
}

OUTPUT

C++ Program to obtain Fibonacci series using recursion with output

C++ Program to perform system shutdown and restart (Windows) [DEVCPP/GCC]

SYSTEM

This function invokes the command processor to execute a command.

PROGRAM

//Program to perform system shutdown and restart in Windows OS

#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
        int n;
        char ch;

        cout<<"\n****MENU****\n";

        cout<<"\n1. SHUTDOWN";
        cout<<"\n2. RESTART";
        cout<<"\n3. EXIT";
     
        cout<<"\n\nENTER YOUR CHOICE: ";
        cin>>n;

        switch(n)
        {
                case 1:
                {
                        system("C:\\Windows\\System32\\Shutdown /s /t 60");
                        cout<<"\nSYSTEM WILL SHUT DOWN IN 1 MINUTE!";

                        cout<<"\n\nDO YOU WANT TO ABORT SHUTDOWN(Y/N)?";
                        cin>>ch;

                        if(ch=='y' || ch=='Y')
                        {
                                system("C:\\Windows\\System32\\Shutdown /a");
                                cout<<"\nSYSTEM SHUT DOWN IS ABORTED!";
                        }

                        break;
                }

                case 2:
                {
                        cout<<"\nSYSTEM WILL RESTART IN 1 MINUTE!";
                        system("C:\\Windows\\System32\\Shutdown /r /t 60");

                        cout<<"\n\nDO YOU WANT TO ABORT RESTART(Y/N)?";
                        cin>>ch;

                        if(ch=='y' || ch=='Y')
                        {
                                system("C:\\Windows\\System32\\Shutdown /a");
                                cout<<"\nSYSTEM RESTART IS ABORTED!";
                        }

                        break;
               }

                case 3:
                {
                       exit(0);
                }

                default:
                {
                        cout<<"\nWRONG CHOICE!";
                        break;
                }
        }

        return 0;
}

OUTPUT

C++ Program to perform system shutdown and restart with outputC++ Program to perform system shutdown and restart with output



C++ Program to illustrate memory allocation with malloc, calloc and realloc [DEVCPP/GCC]

MALLOC

It requests a block of memory from the heap. If the request is granted, a block of required size is allocated and a pointer to the beginning of block is returned. The content of allocated block is not initialized with any default value i.e. It contains garbage value upon allocation.
ptr=(type*)malloc(size) 
CALLOC

It allocates contiguous blocks of requested size for an array and initializes all of its bits to 0. The effective result of calloc is the allocation of (No of Blocks * Size of each Block) bytes.
ptr=(type*)calloc(n,size)
REALLOC

It changes the size of previously allocated memory object pointed by given pointer and reallocates it with given size. The contents of memory object remains unchanged upto the minimum of old and new sizes. If the current memory object cannot be enlarged to satisfy the request, the function may move the memory block to a new location. The old memory object is then freed. If no memory object can be acquired to accommodate the request, the object remains unchanged.
ptr=realloc(ptr,newsize)
FREE

A block of memory previously allocated by a call to malloc, calloc or realloc is deallocated making it available again for further allocations.
free(ptr)
PROGRAM

//Program to illustrate memory allocation with malloc, calloc and realloc with their initialization and   deallocation

#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
       int i,n,r,*cal,*mal;

       cout<<"\nENTER NUMBER OF VALUES REQUIRED: ";
       cin>>n;

       mal=(int*)malloc(n*sizeof(int));

       cout<<"\nMALLOC INITIAL ADDRESS:"<<mal;
   
       cout<<"\n\nMALLOC INITIAL MEMORY CONTENTS\n";
       for(i=0;i<n;i++)
       {
            cout<<"M["<<i<<"]: "<<mal[i]<<endl;
       }

       free(mal);

       cal=(int*)calloc(n,sizeof(int));

        cout<<"\nCALLOC INITIAL ADDRESS:"<<cal;
        cout<<"\n\nCALLOC INITIAL MEMORY CONTENTS\n";

        for(i=0;i<n;i++)
        {
              cout<<"C["<<i<<"]: "<<cal[i]<<endl;
        }

  cout<<"\nALTER NUMBER OF VALUES REQUIRED: ";
  cin>>r;

  realloc(cal,r*sizeof(int));

  cout<<"\n\nCALLOC MEMORY CONTENTS AFTER REALLOCATION\n";
  for(i=0;i<r;i++)
        {
              cout<<"C["<<i<<"]: "<<cal[i]<<endl;
        }
     
        free(cal);
        return 0;
}

OUTPUT

C++ Program to illustrate memory allocation with malloc, calloc and realloc with output


C++ Program to find factorial of a number using recursion [DEVCPP/GCC]

RECURSION

Recursion is an approach in which the function definition refers to itself. Each time the function calls itself with the slightly simpler version of the original problem.

PROGRAM

//Program to find factorial of a number using recursion.

# include <iostream>
using namespace std;

int fact(int n)
{
if(n==0)   //Base condition 
return 1;
else
return n * fact(n-1) ;
}

int main()
{
int num;

       cout<<"Enter a number:";
cin>>num;

       cout<<"Factorial:"<<fact(num);
return 0;
}

OUTPUT


C++ Program to find factorial of a number using recursion with output

C++ Program to implement insertion sort [DEVCPP/GCC]

INSERTION SORT

Insertion sort is another sorting algorithm which sorts the list by shifting elements. It is simple to implement and works efficienty for smaller set of data. It "inserts" the key element in its correct position in the sorted subarray at each iteration.

EXAMPLE

Let us consider a list containing 5 elements i.e. 50,40,30,20,10 to be sorted in ascending order by insertion sort. Since a single element is considered sorted, thus it begins with the second index.At each iteration, a key element is selected such that the elements before key element are sorted.

In the first iteration, the element at index 0 is considered as sorted and element at index 1 is selected as key element (Here 40). The key element is stored in a temporary variable and then the shifting of elements is performed. Since 50>40, 50 shifts towards the key element's index making space for the key element. Since minimum index is reached and we are left with no more comparisons, we place the key element at this index.

C++ Program to implement insertion sort with output

In the second iteration, element at index 2 is selected as the key element (Here 30). Notice that the elements before 30 are already in sorted order, thus we only need to determine the correct position in that sorted subarray for our key element. Since 50 and 40 both are greater than 30, thus both are shifted towards key element's index and the key element(30) is placed in the correct position in that subarray.

C++ Program to implement insertion sort with output

In the third iteration, element at index 3 is selected as the key element (Here 20). 20 is again compared with its previous sorted elements for its correct position. 20 being smallest of all its previous elements obtains starting position in the sorted subarray

C++ Program to implement insertion sort with output

In the last iteration, the sorted subarray consists of n-1 elements of the list and the remaining element is selected as key element. This element is compared with its preceeding elements one by one and acquires its correct position in the array, thus all the elements in the array are sorted.

C++ Program to implement insertion sort with output

PROGRAM

// Program to implement insertion sort

#include <iostream>
#define MAX 5

using namespace std;

void insertion_sort(int a[],int size)
{
        int i,j,key;

        for(i=1;i<size;i++)
        {
                key=a[i];
                j=i-1;

                while((key<a[j]) && (j>=0))
                {
                        a[j+1]=a[j];
                        j--;
                }

                a[j+1]=key;
        }

        cout<<"\n\nSORTED ARRAY\n";

        for(i=0;i<size;i++)
        {
                cout<<a[i]<<" ";
        }
}


int main()
{
        int i,list[MAX];

        cout<<"ENTER ELEMENTS TO BE SORTED\n";
        for(i=0;i<MAX;i++)
        {
                cin>>list[i];
        }

        insertion_sort(list,MAX);

        return 0;
}

OUTPUT

C++ Program to implement insertion sort with output

C++ Program to implement queue through classes and objects [DEVCPP/GCC]

QUEUE

Queue is a linear data structure in which insertion take place at one end called rear end and deletion can take place from other end called front end. Queue implements First In First Out (FIFO) technique i.e. the oldest element is extracted first.

PROGRAM

// Program to implement queue through classes and objects

#include <iostream>
#define MAX 10

using namespace std;

class Queue
{
      int front,rear;
      int queue[MAX];

      public:

      Queue()
      {
              front=rear=-1;
      }

       void qinsert(int item)
       {
              if(rear==MAX-1)
             {
                      cout<<"\nQUEUE OVERFLOW";
             }
             else if(front==-1 && rear==-1)
             {
                      front=rear=0;
                      queue[rear]=item;
                      cout<<"\nITEM INSERTED: "<<item;
             }
             else
             {
                      rear++;
                      queue[rear]=item;
                      cout<<"\nITEM INSERTED: "<<item;
             }
       }

       void qdelete()
       {
              int item;

              if(rear==-1)
             {
                       cout<<"\nQUEUE UNDERFLOW";
             }
             else if(front==0 && rear==0)
             {
                       item=queue[front];
                       front=rear=-1;
                       cout<<"\n\nITEM DELETED: "<<item;
             }
             else
             {
                      item=queue[front];
                      front++;
                      cout<<"\n\nITEM DELETED: "<<item;
             }
       }

       void qtraverse()
       {
              if(front==-1)
              {
                      cout<<"\n\nQUEUE IS EMPTY\n";
              }
              else
              {
                      cout<<"\n\nQUEUE ITEMS\n";
                      for(int i=front;i<=rear;i++)
                      {
                               cout<<queue[i]<<" ";
                      }
                      cout<<endl;
              }
        }
};

int main()
{
      Queue q;

      q.qtraverse();
      q.qinsert(10);
      q.qinsert(20);

      q.qtraverse();

      q.qdelete();
      q.qinsert(30);

      q.qtraverse();
      return 0;
}

OUTPUT

C++ Program to implement queue through classes and objects with output


FIND US ON FACEBOOK!