Tuesday, 13 August 2019

SE COMP A.Y 2019-20 GROUP B CINEMAX ASSIGNMENT MODIFIED

//============================================================================
// Name        : cinemax.cpp
// Author      : NitinShivale
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

class cinemax
{
    cinemax *next;
    cinemax *prev;
    cinemax *rows[10];  //data members
    string mname;
    long mobno;
    int flag;
    int seatno;
public:
    cinemax() //constructor..to initialize the data memeber and rows array.
    {
     flag=0;
     mobno=0;
     seatno=0;
     next=prev=NULL;
     for(int i=0;i<10;i++)
     {
       rows[i]=NULL;
     }
    }
    void show();
    void showSeat();        //member Functions
    void createTheater();
}; //end of class

//This show() function only displays the status of rows i:e Array of pointer.
void cinemax::show()
{
 for(int i=0;i<10;i++)
 {
  cout<<"|"<<rows[i]<<"|-> "<<"\n\n";
 }
}

//This showSeat() function displays the memory map of theater after creation of theater...
void cinemax::showSeat()
{
 cinemax *temp;
 for(int i=0;i<10;i++)
 {
  cout<<"|"<<rows[i]<<"|-> ";
  temp=rows[i];
  for(int j=0;j<7;j++)
  {
   cout<<"|"<<temp->prev<<"|"<<temp->seatno<<"|"<<temp->flag<<"|"<<temp->mname<<"|"<<temp->mobno<<"|"<<temp->next<<"|<-->";
   temp=temp->next;
  }
  cout<<"\n\n";
 }
}

//This createTheater() function creates the 10 rows and 7 seats of Theater by using Doubly Circular Linked List.
void cinemax::createTheater()
{
    cinemax *p,*temp,*head,*p1;
    head=p=p1=temp=NULL;
    int i,j;
    //code for to create the ten rows....

    for(i=0;i<10;i++)
    {
     p=new cinemax;
     p->flag=0;
     p->seatno=1;
     p->mname="NULL"; //code belongs to first node of each row
     p->mobno=0;
     p->next=p;
     p->prev=p;
     rows[i]=p;
     temp=p;
     head=temp;
     //code for to create six seats....
     for(j=1;j<7;j++)
     {
      p1=new cinemax;
      p1->flag=0;
      p1->seatno=j+1;
      p1->mname="NULL"; //assuming that flag zero, mob no zero and movie name i:e mname NULL means seat is not booked yet..initial state of seat.
      p1->mobno=0;
      p1->next=temp->next;
      p1->prev=temp;
      temp->next=p1;
      head->prev=p1;
      temp=p1;
     }
    }
}

//The program execution starts from main() function.
int main() {
    cout << "!!!Welcome To Cinemax Theater!!!" << endl;
    cinemax c1; //object c1 creation of cinemax theater to call all the member functions.
    int ch;
    do
    {
        cout<<"1.Show Rows Status Before Creation of Theater\n"; //Menu for user to display and operate accordingly..
        cout<<"2.Show Rows Status After Creation of Theater\n";
        cout<<"3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:\n";
        cout<<"4.Show Seat Vacancy in Theater...\n";
        cout<<"5.Book My Show..\n";
        cout<<"6.Cancel My Show...\n";
        cout<<"\nEnter your Choice...: ";
        cin>>ch;
        switch(ch)
        {
         case 1:cout<<"\n\nBefore Creation of Theater...\n";
                c1.show();
                break;
         case 2:c1.createTheater(); //member function calling
                cout<<"\n\nAfter Theater Creation...\n";
                c1.show();
                break;
         case 3:cout<<"\n After Seat creation of Theater....\n";
                c1.showSeat();
                break;
         case 4:cout<<"/* under process */\n";break;
         case 5:cout<<"/* under process */\n";break;
         case 6:cout<<"/* under process */\n";break;
        }//end of switch case

    }while(ch!=7); //end of do while loop.
    cout<<"\n\n Thank You so much Visit Again....\n";
 return 0;
}//end of main() function


/** ========  OUTPUT OF CINEMAX THEATER  =======================
 *!!!Welcome To Cinemax Theater!!!
1.Show Rows Status Before Creation of Theater
2.Show Rows Status After Creation of Theater
3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:
4.Show Seat Vacancy in Theater...
5.Book My Show..
6.Cancel My Show...

Enter your Choice...: 1


Before Creation of Theater...
|0|->

|0|->

|0|->

|0|->

|0|->

|0|->

|0|->

|0|->

|0|->

|0|->

1.Show Rows Status Before Creation of Theater
2.Show Rows Status After Creation of Theater
3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:
4.Show Seat Vacancy in Theater...
5.Book My Show..
6.Cancel My Show...

Enter your Choice...:2

After Theater Creation...
|0xd48010|->

|0xd484e0|->

|0xd489b0|->

|0xd48e80|->

|0xd49350|->

|0xd49820|->

|0xd49cf0|->

|0xd4a1c0|->

|0xd4a690|->

|0xd4ab60|->

1.Show Rows Status Before Creation of Theater
2.Show Rows Status After Creation of Theater
3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:
4.Show Seat Vacancy in Theater...
5.Book My Show..
6.Cancel My Show...

Enter your Choice...: 3

Enter your Choice...: 3

 After Seat creation of Theater....
|0xd48010|-> |0xd48430|1|0|NULL|0|0xd480c0|<-->|0xd48010|2|0|NULL|0|0xd48170|<-->|0xd480c0|3|0|NULL|0|0xd48220|<-->|0xd48170|4|0|NULL|0|0xd482d0|<-->|0xd48220|5|0|NULL|0|0xd48380|<-->|0xd482d0|6|0|NULL|0|0xd48430|<-->|0xd48380|7|0|NULL|0|0xd48010|<-->

|0xd484e0|-> |0xd48900|1|0|NULL|0|0xd48590|<-->|0xd484e0|2|0|NULL|0|0xd48640|<-->|0xd48590|3|0|NULL|0|0xd486f0|<-->|0xd48640|4|0|NULL|0|0xd487a0|<-->|0xd486f0|5|0|NULL|0|0xd48850|<-->|0xd487a0|6|0|NULL|0|0xd48900|<-->|0xd48850|7|0|NULL|0|0xd484e0|<-->

|0xd489b0|-> |0xd48dd0|1|0|NULL|0|0xd48a60|<-->|0xd489b0|2|0|NULL|0|0xd48b10|<-->|0xd48a60|3|0|NULL|0|0xd48bc0|<-->|0xd48b10|4|0|NULL|0|0xd48c70|<-->|0xd48bc0|5|0|NULL|0|0xd48d20|<-->|0xd48c70|6|0|NULL|0|0xd48dd0|<-->|0xd48d20|7|0|NULL|0|0xd489b0|<-->

|0xd48e80|-> |0xd492a0|1|0|NULL|0|0xd48f30|<-->|0xd48e80|2|0|NULL|0|0xd48fe0|<-->|0xd48f30|3|0|NULL|0|0xd49090|<-->|0xd48fe0|4|0|NULL|0|0xd49140|<-->|0xd49090|5|0|NULL|0|0xd491f0|<-->|0xd49140|6|0|NULL|0|0xd492a0|<-->|0xd491f0|7|0|NULL|0|0xd48e80|<-->

|0xd49350|-> |0xd49770|1|0|NULL|0|0xd49400|<-->|0xd49350|2|0|NULL|0|0xd494b0|<-->|0xd49400|3|0|NULL|0|0xd49560|<-->|0xd494b0|4|0|NULL|0|0xd49610|<-->|0xd49560|5|0|NULL|0|0xd496c0|<-->|0xd49610|6|0|NULL|0|0xd49770|<-->|0xd496c0|7|0|NULL|0|0xd49350|<-->

|0xd49820|-> |0xd49c40|1|0|NULL|0|0xd498d0|<-->|0xd49820|2|0|NULL|0|0xd49980|<-->|0xd498d0|3|0|NULL|0|0xd49a30|<-->|0xd49980|4|0|NULL|0|0xd49ae0|<-->|0xd49a30|5|0|NULL|0|0xd49b90|<-->|0xd49ae0|6|0|NULL|0|0xd49c40|<-->|0xd49b90|7|0|NULL|0|0xd49820|<-->

|0xd49cf0|-> |0xd4a110|1|0|NULL|0|0xd49da0|<-->|0xd49cf0|2|0|NULL|0|0xd49e50|<-->|0xd49da0|3|0|NULL|0|0xd49f00|<-->|0xd49e50|4|0|NULL|0|0xd49fb0|<-->|0xd49f00|5|0|NULL|0|0xd4a060|<-->|0xd49fb0|6|0|NULL|0|0xd4a110|<-->|0xd4a060|7|0|NULL|0|0xd49cf0|<-->

|0xd4a1c0|-> |0xd4a5e0|1|0|NULL|0|0xd4a270|<-->|0xd4a1c0|2|0|NULL|0|0xd4a320|<-->|0xd4a270|3|0|NULL|0|0xd4a3d0|<-->|0xd4a320|4|0|NULL|0|0xd4a480|<-->|0xd4a3d0|5|0|NULL|0|0xd4a530|<-->|0xd4a480|6|0|NULL|0|0xd4a5e0|<-->|0xd4a530|7|0|NULL|0|0xd4a1c0|<-->

|0xd4a690|-> |0xd4aab0|1|0|NULL|0|0xd4a740|<-->|0xd4a690|2|0|NULL|0|0xd4a7f0|<-->|0xd4a740|3|0|NULL|0|0xd4a8a0|<-->|0xd4a7f0|4|0|NULL|0|0xd4a950|<-->|0xd4a8a0|5|0|NULL|0|0xd4aa00|<-->|0xd4a950|6|0|NULL|0|0xd4aab0|<-->|0xd4aa00|7|0|NULL|0|0xd4a690|<-->

|0xd4ab60|-> |0xd4af80|1|0|NULL|0|0xd4ac10|<-->|0xd4ab60|2|0|NULL|0|0xd4acc0|<-->|0xd4ac10|3|0|NULL|0|0xd4ad70|<-->|0xd4acc0|4|0|NULL|0|0xd4ae20|<-->|0xd4ad70|5|0|NULL|0|0xd4aed0|<-->|0xd4ae20|6|0|NULL|0|0xd4af80|<-->|0xd4aed0|7|0|NULL|0|0xd4ab60|<-->

1.Show Rows Status Before Creation of Theater
2.Show Rows Status After Creation of Theater
3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:
4.Show Seat Vacancy in Theater...
5.Book My Show..
6.Cancel My Show...

Enter your Choice...: 4

Enter your Choice...: 4
*** under process  ****
1.Show Rows Status Before Creation of Theater
2.Show Rows Status After Creation of Theater
3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:
4.Show Seat Vacancy in Theater...
5.Book My Show..
6.Cancel My Show...

Enter your Choice...: 5
*** under process  ****
1.Show Rows Status Before Creation of Theater
2.Show Rows Status After Creation of Theater
3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:
4.Show Seat Vacancy in Theater...
5.Book My Show..
6.Cancel My Show...

Enter your Choice...: 6
*** under process  ****
1.Show Rows Status Before Creation of Theater
2.Show Rows Status After Creation of Theater
3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:
4.Show Seat Vacancy in Theater...
5.Book My Show..
6.Cancel My Show...

Enter your Choice...: 7

Thank You so much Visit Again....

 *************************************************************************************************/

Wednesday, 2 August 2017

Postfix expression evaluation like: xy+

Problem Statement:
Postfix expression evaluation like: xy+     (x=100, y=200) i:e 100200+

//Program By : Mr. Nitin M Shivale 9096454130 if any suggestion please!!!!
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<iostream.h>
#include<conio.h>
//declaration of class for postfix expression evaluation.
class stack
{
 int top;           //by default private (data memebers)
 int stk[20];
 char inp[20];
 int x,i;
 public:
 stack()     //constructor to init data members
 {
  top=-1;
  x=i=0;
 }
 void getdata();    //memeber functions..
 void show();
 int isempty();
 int isfull();
 void push(int);
 int pop();
 int posteval();
}; // end of class stack declaration.
/*************************************************
Fun name: posteval()
return type:integer
no of arg:NULL
purpose: To eval postfix expression.
**************************************************/

int stack::posteval()
{
 int t1,t2,t3;
 for(i=0;inp[i]!='\0';i++)
 {
  if(isalpha(inp[i]))  //to check whether operand or operator.
  {
   cout<<"\nEnter the value of "<<inp[i];
   cin>>x;
   push(x);    //if operand push it into stack.
  }
  else
  {
   t1=pop();  //if operator pop 2 operand from stack.
   t2=pop();
   switch(inp[i])  //as per the operator switch into case & perform operation
   {
    case '+':t3=t1+t2;
         push(t3);
         break;
    case '-':t3=t1-t2;
         push(t3);
         break;
    case '*':t3=t1*t2;
         push(t3);
         break;
    case '/':t3=t1/t2;
         push(t3);
         break;
   }//end of switch
  }//end of else
 }//end of for loop
 return pop(); //after evaluation return the final result
}

int stack::pop() //To return the stack value.
{
 int z;
 z=stk[top];
 top--;
 return z;
}

int stack::isempty()  //To check the stack empty case
{
 if(top==-1)
  return 0;
 else
  return 1;
}

void stack::push(int n) //push the value inside the stack.
{
 top++;
 stk[top]=n;
}
void stack::getdata()   //To accept the postfix expression from user.
{
 cout<<"\nEnter the expression:";
 cin>>inp;
}
int stack::isfull() //To check stack full condition.
{
 if(top==20)
  return 1;
 else
  return 0;
}

void stack::show()//To display the postfix expression
{
 cout<<"\n Postfix Expression Evaluation are as follows...";
 while(inp[i]!='\0')
 {
  cout<<inp[i];
  i++;
 }
}
int main()  //Program execution starts from here
{
 int res;
 cout<<"\nPostfix Evaluation....!!!";
 stack s1;      //objecct creation
 s1.getdata();
 s1.show();   //member function calling.
 res=s1.posteval();
 cout<<"\nThe final result of exp is:"<<res;
 getch();
 return 0;
}

Thursday, 22 September 2016

C++ program for simulating job queue.

Group D: (Assignment No:01) (SPPU Syllabus Asignment No:28)

Problem Statement:

Queues are frequently used in computer programming, and a typical example is the creation of a job queue by an operating system. If the operating system does not use priorities, then the jobs are processed in the order they enter the system. Write C++ program for simulating job queue. Write functions to add job and delete job from queue.



Program Code:

//========================================
// Name        : priosimpq.cpp
// Author      : Nitin Shivale
// Version     : 1
// Copyright   : Your copyright notice
// Description : Operating System simple job queue and priority job queue in C++, Ansi-style
//================================================

#include <iostream>
using namespace std;
#define size 5

class spq
{
    int f,r,job,djob;            //data members
    int simpq[size],prioq[size];
public:
    spq() //Default constructor
    {
     f=r=-1; //init front and rear to -1.
     job=djob=0;
     prioq[-1]=0;
    }
    //To check Q is full or not
    int isQfull()
    {
        if(r==size-1)
            return 1;
        else
            return 0;
    }
    //To check Q is empty or not
    int isQempty()
    {
        if((f==-1)||(f>r))
            return 1;
        else
            return 0;
    }
    void simpqadd(); //member functions.
    void showsimpleQ();
    void delsimpleQ();
    void prioqadd();
    void delprioQ();
    void showprioQ();
};

//To insert the job inside the simple queue.
void spq::simpqadd()
{
    cout<<"\nEnter the Job: ";
    cin>>job;
    if(isQfull())
        cout<<"\nSorry !! Queue is full....\n";
    else
    {
        if(f==-1)
        {
            f=r=0;
            simpq[r]=job;
        }
        else
        {
            r=r+1;
            simpq[r]=job;
        }
    }

}

//To delete job from the simple queue.
void spq::delsimpleQ()
{
    if(isQempty())
        cout<<"\nSorry Q is empty...\n";
    else
    {
        djob=simpq[f];
        f=f+1;
        cout<<"\nDeleted job is: "<<djob;
    }
}

//To show all the jobs from SimpleQueue.
void spq::showsimpleQ()
{
    cout<<"\nThe simple Queue job are as follows....\n";
    int temp;
    for(temp=f;temp<=r;temp++)
    {
        cout<<"\t"<<simpq[temp];
    }
}

//To delete job from the simple queue.
void spq::delprioQ()
{
    if(isQempty())
        cout<<"\nSorry Q is empty...\n";
    else
    {
        djob=prioq[f];
        f=f+1;
        cout<<"\nDeleted job is: "<<djob;
    }
}

//To show all the jobs from PrioQueue.
void spq::showprioQ()
{
    cout<<"\nThe priority Queue job are as follows....\n";
    int temp;
    for(temp=f;temp<=r;temp++)
    {
        cout<<"\t"<<prioq[temp];
    }
}

//To add the jobs as per the priority.
void spq::prioqadd()
{
    int t=0;
    cout<<"\nEnter the job: ";
    cin>>job;
    if(isQfull())
        cout<<"\nSorry!! Priority Queue is full...\n";
    else
    {
        if(f==-1)
        {
            f=r=0; //initially when q is empty insert first job.
            prioq[r]=job;
        }
        else if(job<prioq[r]) //Check the priority(Ascending) of incoming job if it is high
        {
         t=r;
         while(job<prioq[t])//do until priority is high
         {
            prioq[t+1]=prioq[t]; //then shift all the jobs towards right
            t=t-1; //decrement index to check another job.
         }
         t=t+1; //increment index
         prioq[t]=job; //store job at its appropriate location.
         r=r+1; //increment rear index by one
        }
        else
        {
            r=r+1; // as per the priority store in Q.
            prioq[r]=job;
        }
    }
}

int main()
{
    spq s1,s2; //object creation. s1 for simple Q and s2 for priority Q
    int ch;
    do
    {
     cout<< "\n\t!!!Operating System Job Queue!!!" << endl; // prints the msg.
     cout<<"\n1.SimpleQ Add_Job\n2.SimpleQ Del_Job\n3.Show SimpleQ\n4.PrioQ Add_Job\n5.PrioQ Del_Job\n6.Show PrioQ";
     cout<<"\nEnter Your Choice:";
     cin>>ch;
     switch(ch)
     {
      case 1:s1.simpqadd();break;//calling adding element in simple Q without priority.
      case 2:s1.delsimpleQ();break;
      case 3:s1.showsimpleQ();break;
      case 4:s2.prioqadd();break;//calling adding element in priority Q with priority.
      case 5:s2.delprioQ();break;
      case 6:s2.showprioQ();break;
     }
    }while(ch!=7);
    return 0;
}
/************************** OUTPUT ***********************************


    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:1

Enter the Job: 10

    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:1

Enter the Job: 20

    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:1

Enter the Job: 15

    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:1

Enter the Job: 5

    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:1

Enter the Job: 6

    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:1

Enter the Job: 2

Sorry !! Queue is full....

    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:3

The simple Queue job are as follows....
    10    20    15    5    6
    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:4

Enter the job: 10

    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:6

The priority Queue job are as follows....
    10
    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:4

Enter the job: 20

    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:6

The priority Queue job are as follows....
    10    20
    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:4

Enter the job: 15

    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:6

The priority Queue job are as follows....
    10    15    20
    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:4

Enter the job: 5

    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:6

The priority Queue job are as follows....
    5    10    15    20
    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:4

Enter the job: 6

    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:6

The priority Queue job are as follows....
    5    6    10    15    20
    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:5

Deleted job is: 5
    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:6

The priority Queue job are as follows....
    6    10    15    20
    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:5

Deleted job is: 6
    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:6

The priority Queue job are as follows....
    10    15    20
    !!!Operating System Job Queue!!!

1.SimpleQ Add_Job
2.SimpleQ Del_Job
3.Show SimpleQ
4.PrioQ Add_Job
5.PrioQ Del_Job
6.Show PrioQ
Enter Your Choice:
 **************************************************************************/

Monday, 19 September 2016

Pizza parlor accepting maximum M orders.

Group D : (Assignment No: 02) (SPPU Syllabus Assignmnet No: 31)

Problem Statement:
Pizza parlor accepting maximum M orders. Orders are served in first come first served basis. Order once placed cannot be cancelled. Write C++ program to simulate the system using circular queue using array.

Program Code:

//==============================================
// Name        : Pizza_parlor.cpp
// Author      : Nitin Shivale
// Version     : 1.
// Copyright   : Your copyright notice
// Description : ervedPizza parlor accepting maximum M orders.
//==============================================

#include <iostream>
using namespace std;
#define size 5
class pizza
{
    int porder[size];
    int front,rear;
public:
    pizza()
    {
     front=rear=-1;
    }
    int qfull()
    {
     if((front==0)&&(rear==(size-1))||(front==(rear+1)%size))
         return 1;
     else
         return 0;
    }
    int qempty()
    {
        if(front==-1)
            return 1;
        else
            return 0;
    }
    void accept_order(int);
    void make_payment(int);
    void order_in_queue();
};
void pizza::accept_order(int item)
{
    if(qfull())
        cout<<"\nVery Sorry !!!! No more orders....\n";
    else
    {
        if(front==-1)
        {
            front=rear=0;
        }
        else
        {
            rear=(rear+1)%size;
        }
        porder[rear]=item;
    }
}

void pizza::make_payment(int n)
{
    int item;
    char ans;
    if(qempty())
        cout<<"\nSorry !!! order is not there...\n";
    else
    {
      cout<<"\nDeliverd orders as follows...\n";
      for(int i=0;i<n;i++)
      {
          item=porder[front];
          if(front==rear)
          {
               front=rear=-1;
          }
          else
          {
              front=(front+1)%size;
          }
          cout<<"\t"<<item;
      }
      cout<<"\nTotal amount to pay : "<<n*100;
      cout<<"\nThank you visit Again....\n";
    }
}

void pizza::order_in_queue()
{
    int temp;
    if(qempty())
    {
        cout<<"\nSorry !! There is no pending order...\n";
    }
    else
    {
        temp=front;
        cout<<"\nPending Order as follows..\n";
        while(temp!=rear)
        {
            cout<<"\t"<<porder[temp];
            temp=(temp+1)%size;
        }
        cout<<"\t"<<porder[temp];
    }
}
int main()
{
    pizza p1;
    int ch,k,n;
    do
    {
     cout<<"\n\t***** Welcome To Pizza Parlor *******\n";
     cout << "\n1.Accept order\n2.Make_payment\n3.Pending Orders\nEnter u r choice: ";
     cin>>ch;
     switch(ch)
     {
      case 1:cout<<"\nWhich Pizza do u like most....\n";
             cout<<"\n1.Veg Soya Pizza\n2.Veg butter Pizza\n3.Egg_Pizza";
             cout<<"\nPlease enter u r order: ";
             cin>>k;
             p1.accept_order(k);
             break;
      case 2:cout<<"\nHow many Pizza ?";
             cin>>n;
             p1.make_payment(n);
             break;
      case 3:cout<<"\n Following orders are in queue to deliver....as follows..\n";
             p1.order_in_queue();
             break;
     }
    }while(ch!=4);

    return 0;
}
/******************* OUTPUT *********************************************************

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 1

Which Pizza do u like most....

1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter u r order: 2

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 1

Which Pizza do u like most....

1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter u r order: 3

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 1

Which Pizza do u like most....

1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter u r order: 2

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 1

Which Pizza do u like most....

1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter u r order: 3

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 3

 Following orders are in queue to deliver....as follows..

Pending Order as follows..
    2    3    2    3
    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 1

Which Pizza do u like most....

1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter u r order: 1

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 3

 Following orders are in queue to deliver....as follows..

Pending Order as follows..
    2    3    2    3    1
    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 1

Which Pizza do u like most....

1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter u r order: 2

Very Sorry !!!! No more orders....

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 2

How many Pizza ?2

Deliverd orders as follows...
    2    3
Total amount to pay : 200
Thank you visit Again....

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 3

 Following orders are in queue to deliver....as follows..

Pending Order as follows..
    2    3    1
    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 2

How many Pizza ?3

Deliverd orders as follows...
    2    3    1
Total amount to pay : 300
Thank you visit Again....

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 3

 Following orders are in queue to deliver....as follows..

Sorry !! There is no pending order...

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 1

Which Pizza do u like most....

1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter u r order: 1

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 1

Which Pizza do u like most....

1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter u r order: 2

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 1

Which Pizza do u like most....

1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter u r order: 3

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 1

Which Pizza do u like most....

1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter u r order: 1

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 1

Which Pizza do u like most....

1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter u r order: 2

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 1

Which Pizza do u like most....

1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter u r order: 3

Very Sorry !!!! No more orders....

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 3

 Following orders are in queue to deliver....as follows..

Pending Order as follows..
    1    2    3    1    2
    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 2

How many Pizza ?2

Deliverd orders as follows...
    1    2
Total amount to pay : 200
Thank you visit Again....

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 3

 Following orders are in queue to deliver....as follows..

Pending Order as follows..
    3    1    2
    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 1

Which Pizza do u like most....

1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter u r order: 1

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 3

 Following orders are in queue to deliver....as follows..

Pending Order as follows..
    3    1    2    1
    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 1

Which Pizza do u like most....

1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter u r order: 2

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 3

 Following orders are in queue to deliver....as follows..

Pending Order as follows..
    3    1    2    1    2
    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice: 1

Which Pizza do u like most....

1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter u r order: 1

Very Sorry !!!! No more orders....

    ***** Welcome To Pizza Parlor *******

1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice:

 *******************************************************/

Sunday, 18 September 2016

Infix to Postfix conversion code in c++

Group C: (Assignment No: 02) (SPPU Syllabus Assignment No: 25)
Problem Statement:
Implement C++ program for expression conversion as infix to postfix and its evaluation using stack based on given conditions
i. Operands and operator, both must be single character.
ii. Input Postfix expression must be in a desired format.
iii. Only '+', '-', '*' and '/ ' operators are expected.

Program Code:

//================================================================================================================================
// Name        : infix_postfix.cpp
// Author      : Nitin Shivale
// Version     : 1
// Copyright   : Your copyright notice
// Description : Conversion of infix expression to postfix expression and evaluation of postfix expression using stack, Ansi-style
//================================================================================================================================

#include <iostream>
#include<ctype.h>
using namespace std;
//class inpo containing data member and member functions
class inpo
{
    char in[20],po[20],stk[10];//stack for expression conversion.
    int i,j,is,ic,top,top1; //Two top one for stack and one for stack 1.
    int stk1[10]; //Stack 1 for expression evaluation.
public:
    inpo()
    {
     i=j=is=ic=0; //initialization of data members
     top=top1=-1;
    }
    bool IsOperand(char C)
    {
        if(C >= '0' && C <= '9') return true;
        if(C >= 'a' && C <= 'z') return true;
        if(C >= 'A' && C <= 'Z') return true;
        return false;
    }
    void getinfix() //Accept the infix expression
    {
        cout<<"\nEnter valid infix Expression: ";
        cin>>in; //Stored infix exp in in[]char array.
    }
    void showinfix() //Show the infix expression
    {
        cout<<"\t"<<in;
    }
    int isempty() //Stack basic functions.
    {
        if(top==-1)
            return 1;
        else
            return 0;
    }
    int isfull()
    {
        if(top==9)
            return 1;
        else
            return 0;
    }
    void push1(int x1)//for integer stack
    {
        top=top+1;
        stk1[top]=x1;
    }
    int pop1() //for integer stack
    {
       int s1;
       s1=stk1[top];
       top=top-1;
       return s1;
    }
    void push(char x)//for character stack
    {
        top=top+1;
        stk[top]=x;
    }
    char pop()//for character stack
    {
        char s;
        s=stk[top];
        top=top-1;
        return s;
    }
    void showpostfix()
    {
        cout<<"\t"<<po;
    }
    void convert();
    int instackprio();
    int incomingprio(char); //member functions
    void postfixExpEval();
};
void inpo::postfixExpEval() //To evaluate the postfix expression
{
    i=0;
    char ch;
    int op1,op2,res,tot;
        while(po[i]!='\0')//read postfix expression one by one
        {
            ch=po[i];
            if((ch=='+')||(ch=='-')||(ch=='*')||(ch=='/')||(ch=='^')) //isdigit(ch) built in function to check digit.
            {
                switch(ch)//if operator pop and perform operation and push back into the stack.
                {
                case '+':op2=pop1();
                         op1=pop1();
                         res=op1+op2;
                         push1(res);
                         break;
                case '-':op2=pop1();
                         op1=pop1();
                         res=op1-op2;
                         push1(res);
                         break;
                case '*':op2=pop1();
                         op1=pop1();
                         res=op1*op2;
                         push1(res);
                         break;
                case '/':op2=pop1();
                         op1=pop1();
                         res=op1/op2;
                         push1(res);
                         break;
                case '^':op2=pop1();
                         op1=pop1();
                         res=op1;
                         while(op2>1)
                         {
                          res=res*op1;
                          op2--;
                         }
                         push1(res);
                         break;
                }//end of switch

            } //end of if
            else if(IsOperand(ch))//To check operand we use IsOperand function.
            {
                push1(ch-'0'); //if operand push it inside stack
            } //end of else
            i=i+1;
        }//end of while

    tot=pop1(); //final evaluated result at the top of stack.
    cout<<"\nResult is:"<<tot;
}//end of fun

/*******************************************************************
 * Function Name: To convert infix expression to postfix expression.
 * return type: Void
 *******************************************************************/

void inpo::convert()
{
    i=j=0;
    char p,k;
    while(in[i]!='\0')//do until null character not found
    {
     p=in[i];//to read one by one from infix expression
     if((p=='(')||(p=='+')||(p=='-')||(p=='*')||(p=='/')||(p=='^')||(p==')'))
     {
         if(isempty()) //here we are dealing with operator only as per their priority.
         {
             push(p); //if initially stack is empty push
         }
         else if(p==')') //when we encountered with ')' bracket pop from stack until we r not encountered with '(' bracket.
         {
             k=pop();
             while(k!='(') //check the pop element with '(' bracket. if equal stop poping.
             {
                 po[j]=k; //pop and store it inside the postfix expression array po[].
                 j++;     //increment po[] array index by 1.
                 k=pop(); //pop next element
             }
         }
         else
         {
             is=instackprio(); //when we are pushing the operator inside the stack.
             ic=incomingprio(p);// we are always checking their incoming and instack priority.
             if(is>ic)//if instack priority is gretter than incoming priority
             {
              k=pop(); //pop the stack top operator whose priority is bigger than incoming operator from stack.
              po[j]=k;//store it in postfix expression array po[j]
              j++;  //increment j by one.
              push(p);//then push the incoming operator in stack.
             }
             else
             {
                 push(p); //if incoming operator priority is gretter than instack operator priority then
             }            // directly push the incoming operator inside the stack.
         }
     }
     else// if opearnd is their directly store it inside the postfix expression array po[j].
     {
        po[j]=p;
        j++; //increment j by one.
     }
     i=i+1; //read the next character of infix expression for conversion.
    }//end of while loop
    if(in[i]=='\0')//if we encountered with NULL Character of infix expression then
    {
        while(!isempty())//pop the stack containts until stack is not empty and
        {
         k=pop(); //pop from stack
         po[j]=k; //store it inside the postfix expression array po[j].
         j++;  //increment j by one.
        }
    }
 po[j]='\0'; // at the end of the postfix expression store null character to indicate end of the expression.
}

/* * Function to check the instack priority of operator * */
int inpo::instackprio()
{
    char b;
    b=stk[top];
    switch(b)
    {
     case '(':return 0; break;
     case '+':return 2; break;
     case '-':return 2; break;
     case '*':return 4; break;
     case '/':return 4; break;
     case '^':return 5; break;
    }
}
/* * Function to check the priority of incoming operator * */
int inpo::incomingprio(char ch)
{
    switch(ch)
    {
     case '(':return 9; break;
     case '+':return 1; break;
     case '-':return 1; break;
     case '*':return 3; break;
     case '/':return 3; break;
     case '^':return 6; break;
    }
}

int main()
{
    inpo p1;
    p1.getinfix();
    p1.showinfix();
    cout<<"\nAfter conversion from infix to postfix...\n";
    p1.convert();
    p1.showpostfix();
    cout << "\n\n!!!POSTFIX EXPRESSION EVALUATION ARE AS FOLLOWS..!!!" << endl;
    p1.postfixExpEval();
    return 0;
}

/************** OUTPUT***********************************************************
 *
 Enter valid infix Expression: 2^4
    2^4
After conversion from infix to postfix...
    24^

!!!POSTFIX EXPRESSION EVALUATION ARE AS FOLLOWS..!!!

Result is:16

Enter valid infix Expression: (9-1)/(4-2)^2
    (9-1)/(4-2)^2
After conversion from infix to postfix...
    91-42-2^/

!!!POSTFIX EXPRESSION EVALUATION ARE AS FOLLOWS..!!!

Result is:2

[student@localhost SE_Comp_A]$ g++ conv_in_po_eval.cpp
[student@localhost SE_Comp_A]$ ./a.out

Enter valid infix Expression: (8*6)/(4-2)^3
    (8*6)/(4-2)^3
After conversion from infix to postfix...
    86*42-3^/

!!!POSTFIX EXPRESSION EVALUATION ARE AS FOLLOWS..!!!

Result is:6

 ***********************************************************************************/

Linked list program to store negative and positive number

Group B: (Assignment No:04)(SPPU Syllabus assignment No :18)
Problem Statement: Write C++ program to store set of negative and positive numbers using linked list. Write functions to 
a) Insert numbers
b) Delete nodes with negative numbers
c) Create two more linked lists using this list, one containing all positive numbers and other containing negative numbers
d) For two lists that are sorted; Merge these two lists into third resultant list that is sorted.

Program Code:
//Author: Prof.Anjali Almale
#include<iostream>
using namespace std;
struct node   //node defined to allocate memory
{
    int num; //To store data
    node *next; //To store address of next node.
};

class numbers  //class name is number
{
 public:

    node *head,*head1,*head2; //data memebers

    numbers() //default constructor
    {
        head=NULL;
        head1=NULL;
        head2=NULL;
    }
    void create();       //member function declaration.
    void display(node *);
    void insert();
    void sort(node *);
    void display2();
    void remove();
    void seperate();
    void merge();
}; //end of class

void numbers::create()
{

  node *current,*new_node;
    char c;
 cout<<"\n------------CREATION OF NUMBERS LIST-------------\n\n ";
    do
    {

    new_node=new node; //dynamic memory allocation
    cout<<"\n Enter the no: \n ";
    cin>>new_node->num; //To store data

    new_node->next=NULL; //make node next null(init)
    if(head==NULL) //check header if null
    {
        head=new_node;
        current=new_node;
    }
    else
    {
        current->next=new_node;
        current=new_node;

    }
    cout<<"\nDo you want to add new member";
    cin>>c;
       }while(c!='n');
}
void numbers::seperate()//To separate the positive numbers and negative numbers.
{
    node *temp,*current1,*current2,*n1,*n2;
    temp=head;

    while(temp!=NULL)
    {
        if((temp->num)<0)
        {
            n1=new node;
            n1->num=temp->num;
            n1->next=NULL;

            if(head1==NULL)
            {
                current1=n1;
                head1=n1;
            }
            else
            {
            current1->next=n1;
            current1=n1;
            }

        }
        else if((temp->num)>=0)
        {
            n2=new node;
            n2->num=temp->num;
            n2->next=NULL;
            if(head2==NULL)

            {
                current2=n2;
                head2=n2;
            }
            else
            {
              current2->next=n2;
              n2->next=NULL;
              current2=n2;
            }
        }
          temp=temp->next;
     }
}

void numbers::display(node *head)//To display the list
{
    node *p;
    p=head;
    if(p==NULL)
    {
        cout<<"\nThe list is Empty";
    }
    else
    {
        while(p!=NULL)
        {
            cout<<p->num<<"\t";
             p=p->next;
        }
    }
}

void numbers::sort(node *head_d) //Before merge u hv to sort them
{
    node *temp1,*temp2,*temp3;
    temp1 = head_d;

 for( ;temp1->next!=NULL;temp1=temp1->next)
 {
     for(temp2=temp1->next;temp2!=NULL;temp2=temp2->next)
     {
         if(temp1->num>temp2->num)
         {
             int temp= temp1->num;
             temp1->num = temp2->num;
             temp2->num = temp;
         }
     }
 }
 temp3 = head_d;

while (temp3!=NULL)
{
cout<<"\t"<< temp3->num;
temp3 =temp3->next;
}
}

void numbers::merge()//To merge both the list
{
    node *temp;
    temp=head1;

    while(temp->next!=NULL)
    {
        temp=temp->next;
    }
    temp->next=head2;
}
void numbers::insert()
{
    node *p,*temp;
        p=new node;
        cout<<"\n\n Enter New Number to be insert  :  ";
        cin>>p->num;
        p->next=NULL;
        temp=head;
        while(temp->next!=NULL)
        {
    temp=temp->next;
        }
    temp->next=p;
}

int main()
{
    numbers n;
    n.create();
    cout<<"\n \nTHE LIST OF +VE AND -VE NUMBERS IS: \n";
    n.display(n.head);
    n.insert();
    cout<<"\n \nTHE LIST AFTER INSERTION IS: \n";
    n.display(n.head);
    n.seperate();
    cout<<"\n\n THE LIST OF ONLY -VE NUMBERS IS: \n";
    n.display(n.head1);
    cout<<"\n\n THE LIST OF ONLY +VE NUMBERS IS: \n";
    n.display(n.head2);
    cout<<"\n\n THE LIST OF ONLY SORTED -VE NUMBERS IS : \n";
    n.sort(n.head1);
    cout<<"\n\n THE LIST OF ONLY SORTED +VE NUMBERS IS : \n";
    n.sort(n.head2);
    n.merge();
    cout<<"\n AFTER MERGE .....THE LIST IS AS FOLLOWS: \n";
    n.display(n.head1);
    cout<<"\n\n THE LIST OF SORTED +VE AND -VE NUMBERS IS : \n";
    n.display(n.head1);
    return 0;
}

/*   OUTPUT *************************************************************


------------CREATION OF NUMBERS LIST-------------


 Enter the no:
 1

Do you want to add new membery

 Enter the no:
 -5

Do you want to add new membery

 Enter the no:
 6

Do you want to add new membery

 Enter the no:
 -7

Do you want to add new membery

 Enter the no:
 -3

Do you want to add new membery

 Enter the no:
 -4

Do you want to add new membery

 Enter the no:
 7

Do you want to add new membern


THE LIST OF +VE AND -VE NUMBERS IS:
1    -5    6    -7    -3    -4    7

 Enter New Number to be insert  :  10


THE LIST AFTER INSERTION IS:
1    -5    6    -7    -3    -4    7    10

 THE LIST OF ONLY -VE NUMBERS IS:
-5    -7    -3    -4

 THE LIST OF ONLY +VE NUMBERS IS:
1    6    7    10

 THE LIST OF ONLY SORTED -VE NUMBERS IS :
    -7    -5    -4    -3

 THE LIST OF ONLY SORTED +VE NUMBERS IS :
    1    6    7    10
 AFTER MERGE .....THE LIST IS AS FOLLOWS:
-7    -5    -4    -3    1    6    7    10

 THE LIST OF SORTED +VE AND -VE NUMBERS IS :
-7    -5    -4    -3    1    6    7    10

********************************************************************************************/

Tuesday, 6 September 2016

C++ program using stack to check whether given expression is well parenthesized or not.

Group C: Assignment No: 01 (SPPU Syllabus Assignment No:24)

Problem Statement:
In any language program mostly syntax error occurs due to unbalancing delimiter such as (),{},[]. Write C++ program using stack to check whether given expression is well parenthesized or not.


Program Code:

//============================================================================
// Name        : wellformness.cpp
// Author      : Nitin Shivale
// Version     : 1
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
#define size 10

class stackexp
{
    int top;
    char stk[size];
public:
    stackexp()
    {
     top=-1;
    }
    void push(char);
    char pop();
    int isfull();
    int isempty();
};

void stackexp::push(char x)
{
    top=top+1;
    stk[top]=x;
}

char stackexp::pop()
{
    char s;
    s=stk[top];
    top=top-1;
    return s;
}

int stackexp::isfull()
{
    if(top==size)
        return 1;
    else
        return 0;
}

int stackexp::isempty()
{
    if(top==-1)
        return 1;
    else
        return 0;
}

int main()
{
    stackexp s1;
    char exp[20],ch;
    int i=0;
    cout << "\n\t!!Well Formness of Parenthesis..!!!!" << endl; // prints !!!Hello World!!!
    cout<<"\nEnter the expression to check whether it is in well form or not :  ";
    cin>>exp;
    if((exp[0]==')')||(exp[0]==']')||(exp[0]=='}'))
    {
        cout<<"\n Invalid Expression.....\n";
        return 0;
    }
    else
    {
        while(exp[i]!='\0')
        {
            ch=exp[i];
            switch(ch)
            {
            case '(':s1.push(ch);break;
            case '[':s1.push(ch);break;
            case '{':s1.push(ch);break;
            case ')':s1.pop();break;
            case ']':s1.pop();break;
            case '}':s1.pop();break;
            }
            i=i+1;
        }
    }
    if(s1.isempty())
    {
        cout<<"\nExpression is well parenthesis...\n";
    }
    else
    {
        cout<<"\nSorry !!! Invalid Expression or not in well parenthesized....\n";
    }
    return 0;
}

/******************* output   *****************************************************

  !!Well Formness of Parenthesis..!!!!

Enter the expression to check whether it is in well form or not :  (m<(n[8]+0))

Expression is well parenthesis...


!!Well Formness of Parenthesis..!!!!

Enter the expression to check whether it is in well form or not :  )(m+n)*(a-b)

 Invalid Expression.....



     !!Well Formness of Parenthesis..!!!!

Enter the expression to check whether it is in well form or not :  (m+b(n[8)/2+3)

Sorry !!! Invalid Expression or not in well parenthesized....


*********************************************************************************/