Sunday, 14 April 2013

C++ program for stack operations using array

/*Program for stack using array
  By sanjay kumar singh,ggsestc*/



#include<iostream.h>
#include<conio.h>
#define size 10

void push();
void pop();
void display();
void peek();
int top=-1,s[size];

void main()

{
        int n;
        do
        {
            cout<<"enter the choice from the following\n";
            cout<<"1...push\n2...pop\n3...display\n4...peek\n";
            cin>>n;
            switch(n)
            {
            case 1:cout<<"...push operation...\n";
                         push();
                         break;
                  case 2:cout<<"...pop operation...\n";
                         pop();
                         break;
                  case 3:cout<<"...display operation...\n";
                         display();
                         break;
                  case 4:cout<<"...peep operation...\n";
                         peek();
                         break;
             }
        }while(n<5);
      getch();
}

void push()
{
      int val;
      cout<<"enter element u want to insert:";
      cin>>val;
      if(top==size-1)
      cout<<"stack is overflow";
      else
      {
          top++;
            s[top]=val;
      }
}

void pop()
{
      int val;
      if(top==-1)
      cout<<"stack underflow";
      else
      {
      val=s[top];
                top--;
                cout<<"\nelement deleted is:"<<val;
      }
}

void display()
{
      if(top==-1)
      cout<<"stack is empty";
      else
      {
          for(int i=top;i>=0;i--)
            cout<<s[i]<<"\t";
      }
}

void peek()
{
      if(top==-1)
      cout<<"stack is empty";
      else
      cout<<s[top];
}

C++ program for linear search in an array list

/*linear search in an array list
  by sanjay kumar singh,ggsestc*/


#include<iostream.h>
#include<conio.h>
#define size 15

void main()
{
        int ar[size],n,i,val,flag=0;
         cout<<"\t\tLinear search in array list\n\n";
         cout<<"Enter the no of elements : ";
         cin>>n;
         cout<<"Enter elements of the array :\n ";
         for(i=0;i<=n-1;i++)
         cin>>ar[i];
         cout<<"Entered elements are : \n";
         for(i=0;i<=n-1;i++)
         cout<<ar[i]<<"\t";
         cout<<"\nEnter the element u want to search : \n";
         cin>>val;
         for(i=0;i<n;i++)
         {
          if(val==ar[i])
            {
            flag=1;
               break;
             }
         }
         if(flag=1)
         cout<<"search successful ad its position is at : "<<i+1;
         else
         cout<<"Search unsuccessful";
         getch();
}

Saturday, 13 April 2013

C++ program for stack using linked list

/*Program for Stack Using Linked-List
     By sanjay kumar singh,ggsestc*/



#include<iostream.h>
#include<conio.h>
#include<malloc.h>

void push();
void pop();
void display();

struct node
{
int data;
      node *next;
};
node *top=NULL;

void main()

{
         int n;
         do
         {
         cout<<"enter the choice from the following \n";
         cout<<"1...push\n2...push\n3...peep\n4...display\n";
         cin>>n;
         switch(n)
         {
          case 1:cout<<"...push operation...\n";
                      push();
                      break;
               case 2:cout<<"...pop operation...\n";
                      pop();
                      break;
               case 4:cout<<"...display operation...\n";
               display();
                      break;
          }
          }while(n<5);
   getch();
}

void push()
{
      int n;
      node *temp;
      cout<<"enter the element u want to insert : ";
      cin>>n;
      temp=(node*)malloc(sizeof(node));
      temp->data=n;
      temp->next=top;
      top=temp;
}
void pop()
{
      int n;
      node *temp;
      if(top==NULL)
      cout<<"stack underflow";
      else
      {
      temp=top;
            top=top->next;
            temp->next=NULL;
            cout<<"deleted element is "<<temp->data;
            free(temp);
      }
}

void display()
{
      node *show;
      if(top==NULL)
      cout<<"stack is empty";
      else
      {
          show=top;
            while(show!=NULL)
            {
              cout<<show->data<<"\t";
                  show=show->next;
             }
       }
}

deletion in an array list

/*C++  Program for deletion of element from an array
   By sanjay kumar singh,ggsestc*/


#include<iostream.h>
#include<conio.h>
#define size 15
void main()
{
         int ar[size],n,i,val,loc;
         cout<<"\t\tDeletion From Array List At Specified location\n\n";
         cout<<"Enter the no of elements : ";
         cin>>n;
         cout<<"Enter elements of the array :\n ";
         for(i=0;i<=n-1;i++)
         cin>>ar[i];
         cout<<"Entered elements are : \n";
         for(i=0;i<=n-1;i++)
         cout<<ar[i]<<"\t";
         cout<<"\nEnter the location in array list for deletion : \n" ;
         cin>>loc;
         for(i=loc-1;i<=n-1;i++)
         ar[i]=ar[i+1];
         cout<<"Updated array is : \n";
         for(i=0;i<n-1;i++)
         cout<<ar[i]<<"\t";
         getch();
}

C++ program for finding the variable position in a string


/*Vowel position in a string
      By sanjay kumar singh,ggsestc*/ 

#include<iostream.h>
#include<conio.h>

void main()
{

    char ch[30];
            cout<<"enter name :";
            cin.get(ch,30);
            strlen(ch);
            for(int i=0;i<strlen(ch);i++)
            {
                    if(ch[i]=='A'||ch[i]=='a'||ch[i]=='e'||ch[i]=='E'||ch[i]=='i'||ch[i]=='I'||ch[i]=='o'||ch[i]=='O'|               
                    |ch[i]=='u'||ch[i]=='U')
                    cout<<"  the vowel   "<<ch[i]<<"   is at "<<(i+1)<<endl;
            }
            getch();
}

Thursday, 11 April 2013

programming for atm machine


/* programming for A.T.M machine
     by sanjay kumar singh , ggsestc*/

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

void main()
{
          char ch;
          long int  amount,total=100000;
          int n=85321,s,pass,cpass,npass,vpass,paswrd[10],password,len;
          around:
          {
              gotoxy(30,5);
              textmode(C4350);
              cout<<" BANK   OF   INDIA ";
              gotoxy(34,10);
              cout<<" 24 HOURS ";
              gotoxy(32,12);
              cout<<" ATM  FACILITY ";
              gotoxy(25,22);
              cout<<" DO U WANT TO USE ATM ";
              gotoxy(53,21);
              cout<<" YES...y \n";
              gotoxy(53,23);
              cout<<" NO....n ";
              gotoxy(53,25);
              cout<<"Enter Your Choice:";
              cin>>ch;
          }
          clrscr();
          gotoxy(20,15);
          cout<<" THANK U ";
          gotoxy(18,17);
           cout<<" VISIT AGAIN ";
            if(ch=='y'||ch=='Y')
         {
                clrscr();
          gotoxy(15,12);
          cout<<" Please Enter Your Card ... ";
                          getch();
          clrscr();
                 gotoxy(15,12);
          cout<<" Enter PIN Code...";
          cin>>n;
          if(n==85321)
              {
    clrscr();
    gotoxy(25,15);
    cout<<" WELCOME TO BANK OF INDIA ";
    gotoxy(35,20);
    cout<<" ATM ";
                                    getch();
                }
                                menu:
                 {
                      clrscr();
                       gotoxy(26,5);
                       cout<<" ENTER YOUR CHOICE ";
                         gotoxy(25,10);
                                         cout<<" 1...CASH WITHDRAW   ";
                                          gotoxy(25,12);
                         cout<<" 2...BALANCE CHECK   ";
                      gotoxy(25,14);
                                     cout<<" 3...CHANGE PIN CODE ";
                        gotoxy(25,16);
                                    cout<<" 4...EXIT            ";
                                    cin>>s;
             }
                                 if(s==1)
        {
clrscr();
gotoxy(25,5);
 cout<<" WITHDRAW ";
                                                             circle:
    gotoxy(18,12);
       cout<<" ENTER AMOUNT...";
      cin>>amount;
                                                                  if(amount%100==0)
                                                                   {
                                                                          gotoxy(18,15);
                                                                          cout<<" U RECIEVE UR MONEY";
                                                                          total-=amount;
           gotoxy(18,17);
          cout<<" CURRENT BALANCE IS "<<total;
                                                                          gotoxy(18,22);
          cout<<" DO U WANT RECIEPT FOR BALANCE 
                                                                           ENQUIRY ";
                   gotoxy(63,23);
          cout<<" YES...y ";
             gotoxy(63,24);
                                                                          cout<<" NO...n  ";
                                                                          cin>>ch;
         clrscr();
          if(ch=='y'||ch=='Y'||ch=='n'||ch=='N')                                        
                   {

                                                                                    clrscr();
             gotoxy(20,11);
          cout<<" DO U WANT TO CONTINUE FOR 
                                                                                    MORE TRANSACTION ";
            gotoxy(62,12);
                                                                                    cout<<" YES ";
            gotoxy(62,14);
       cout<<" NO ";
     cin>>ch;
      if(ch=='y'||ch=='Y')
          {
clrscr();                                                                                  
  goto circle;
           }
                else
             {
 gotoxy(40,20);                                                      
                                                                                         cout<<" DO U WANT TO 
                                                                                              CONTINUE... ";
                                                                                       gotoxy(40,25);
                                                              
cout<<" YES...y ";                                                               
                                                                                              gotoxy(40,27);
                                                                                          cout<<" NO...n ";
cin>>ch;                                                                         
if(ch=='y'||ch=='Y')                                                               
{                                                                   
clrscr();                                                                  
                                                                                                 goto menu;
}                                                                    
else                                                              
                                                                                                       {
          clrscr();                                                               
           gotoxy(20,10);
            cout<<" THANK U ";                                                               
            gotoxy(20,12);                                                             
           cout<<" VISIT AGAIN ";                                                                                                                            
                                                                                                         }
               }
}
                                                  
                                                                             else
                                                                          {
                                                                             cout<<" SORRY...PLEASE ENTER IN THE 
                                                                             MULTIPLE OF (100,500,1000...) ";
 }
 else if(s==2)
 {
                   clrscr();
                   gotoxy(15,7);
                   cout<<" BALANCE ENQUIRY ";
                   if(total==0)
                   {
                        gotoxy(15,10);
                        cout<<" YOUR ACCOUNT HAVE NO BALANCE TO QUERY ";
                   }
                   else
                   {
gotoxy(12,11);
cout<<" ACCOUNT BALANCE IS "<<total;
gotoxy(12,16);
cout<<" DO U WANT TO CONTINUE ";
gotoxy(35,17);
cout<<" YES ";
gotoxy(35,18);
cout<<" NO ";
cin>>ch;
if(ch=='y'||ch=='Y')
{
clrscr();
goto menu;
}
else
{
clrscr();
gotoxy(15,7);
cout<<" THANK U ";
gotoxy(15,10);
cout<<" VISIT AGAIN ";
}
                   }
              }
else if(s==3)
{
clrscr();
gotoxy(15,6);
cout<<" CHANGE PIN CODE ";
loop:
gotoxy(13,10);
cout<<" ENTER OLD PIN CODE ...";
cin>>cpass;
if(cpass==pass)
{
clrscr();
sph:
gotoxy(15,8);
cout<<" ENTER NEW PIN CODE... ";
cin>>npass;
clrscr();
gotoxy(15,10);
cout<<" AGAIN ENTER PIN CODE FOR 
                                                                                 VERIFICATION... ";
cin>>vpass;
if(npass==vpass)
{
clrscr();
gotoxy(15,10);
cout<<" PIN CODE CHANGES 
                                                                                                  SUCCESSFULLY... ";
gotoxy(15,13);
cout<<" DO U WANT TO CONTINUE... ;
gotoxy(15,15);
cout<<" YES...y ";
gotoxy(15,17);
cout<<" NO...n  ";
cin>>ch;
if(ch=='y'||ch=='Y')
    {
  clrscr();
  goto menu;
    }
else
    {
       clrscr();
       gotoxy(15,12);
    cout<<"     THANK U      ";
       gotoxy(15,14);
       cout<<"     VISIT   AGAIN        ";
    }
}
else
     {
   clrscr();
   gotoxy(20,5);
   cout<<" SORRY PIN CODE NOT 
                                                                                                    MATCH ";
   goto sph;
   gotoxy(15,12);
   cout<<"  PLEASE TRY AGAIN ";
     }
   }
   else
              {
             clrscr();
             gotoxy(20,5);
             cout<<" PLAESE VERIFY YOUR PIN CODE ";
             goto loop;
              }
             }
 else
 {
clrscr();
gotoxy(15,14);
cout<<"  DO U WANT TO CONTINUE... ";
                  gotoxy(37,15);
                  cout<<" YES ";
                  gotoxy(37,16);
                  cout<<" NO ";
cin>>ch;
if(ch=='y'||ch=='Y')
{
 goto menu;
}
else
{
clrscr();
gotoxy(15,18);
cout<<"  THANK U ";
gotoxy(15,20);
cout<<" VISIT AGAIN ";
}
}
 }

getch();
}