Friday, January 20, 2012

SIMPLE MACHINE PROGRAM IN C++

#include <iostream>
using namespace std;
 

const int size=10000; 
int top; 
char stack [size]; 

addpush (char item); 
deletepop(); 
Elementdisplay();
 
        addpush(char item) 
        { 
 
            if(top==size)  { 
 
            cout<<endl<<"It WAS already FULL! Please delete Other element\n"; 
                            } 
            else   {
 
            top=top+1; 
 
             stack[top]=item; 
 
             
                    }
        return 0;
        } 
 
 
 
        deletepop()
        { 
 
             if(top==0)  { 
 
                 cout<<"\n\tOPPS!!!Sorry!!!It WAS  Empty!\n"; 

                        } 
 
             else   {
 
                 top=top-1; 
 
               
                    }
       
           return 0;
        }
       
 
        Elementdisplay()
        { 
 
       
            if(top==0){
            cout<<"\n\tSorry!!!It WAS  Empty!\n";
            cout<<endl<<"\tDISPLAY:\n\tELEMENTS in STACK::\n";
                        }
            else{   
            cout<<endl<<"\tDISPLAY:\n\tELEMENTS in STACK::\n";
 
            for(int i=1;i<=top;i++)    {
                cout<<"\t\t"<<stack[i]<<endl;
                                    }
            }
                return 0;

        }
 
void main() 
 

 
    char choices; char item; 
 
    int indicator; 
      cout<<"Prepared by:: \n\t\tANTOLIN C. ABELLANO\n\t\t BSCS 4\n\t\t Data Structure\n\t\tJanuary 20,2012\n\n"; 
 
    do 
 
    {
    cout<<"||--------------------------------------------------------------------------||";
    cout<<"\n   LIST OF CHOICES\n\n";
    cout<<"\tEnter A for ADD ELEMENT\n;
    cout<<"\tEnter B for DELETE ELEMENT\n"; 
    cout<<"\tEnter C for DISPLAY  ELEMENTS\n";   
    cout<<"\tEnter D for EXIT \n"; 
 
        cout <<endl<<"    Enter Your Choice::\t"; 
 
        cin>>choices; 
        choices=toupper(choices);
    cout<<"||--------------------------------------------------------------------------||";
 
        switch (choices) 
 
        { 
 
        case 'A': 
 
            cout <<endl<<"\tENTER ELEMENT TO ADD in STACK::\t"; 
 
            cin>>item; 
 
            addpush (item); 
 
            break; 
 
        case 'B': 
 
            deletepop(); 
 
            break; 
 
        case 'C': 
 
            Elementdisplay();
 
            break;
       
        case 'D':
            cout<<"\n\t";
            exit (0);
            break;
 
        default: 
 
            cout<<endl<<endl<<"\tYour input is Incorrect! \n"; 
 
            break; 
 
        } 
 
      cout<<"\n\tDo you want to continue?\n\t(press 0 to end or press other number to continue!)";
      cin>>indicator;
   
 
    } 
 
    while(indicator!=0);
    cout<<"\t";
 } 
 
   
 
 
 

1 comment:

  1. Hi,When a visitor comes to your website they are making a lot of decisions very quickly for Web Design Cochin. First they are trying to decide whether this website looks legitimate. Secondly, they are looking to see whether you actually do provide the product/ service that they were looking for. How long do they take to decide? Seconds. The appearance of the website is probably going to be the main key to decide whether your target audience hit the back arrow or proceed along the website. Just think of how many times you didn't go into a shop, because of its appearance from the outside.Thanks.......

    ReplyDelete