google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.

Wednesday, April 1, 2015

C program in stack data structure for infix and postfix expression

#define max 50
#include<stdio.h>
#include<conio.h>
#include<process.h>
void push(char ch);
char pop();
char stack[max];
int top=-1;
int prec(char chr);
void main()
{
 char a[60],b[60],ch;
 int i,j,p,r,x,y,re;
 clrscr();
 printf("\n Enter Infix Expression:-\n");
 scanf("%s",&a);
 i=0;
 j=0;
 for(i=0;a[i]!='\0';i++)
 {
  switch(a[i])
  {
   case '^':
   case '$':
   case '*':
   case '/':
   case '+':
   case '-': p=prec(a[i]);
    while(top!=-1&&p<=prec(stack[top]))
    {
      b[j]=pop();
      j++;
    }
    push(a[i]);  //push operator into stack
    break;
   case '(': push(a[i]);
    break;

   case ')':
    do
    {
     ch=pop();
     if(ch!='(')
     {
      b[j]=ch;
      j++;
     }
    }while(ch!='(');
     break;
   default : b[j]=a[i];  //output exp
    j++;
  }
 }
 while(top!=-1)
 {
  b[j]=pop();  //last pop the all operators.
  j++;
 }
 b[j]='\0';
 printf("\n Postfix Expression Is:-\n %s",b);
 printf("\n Evaluation of the Postfix expression:-\n");
 i=0;
 while(b[i]!='\0')
 {
  if(b[i]>='0'&&b[i]<='9')
  {
   push(b[i]-48); //convert char into nuumber
  }
  else
  {
   y=pop(); //pop the two poerands and prefrom operation
   x=pop();
   switch(b[i])
   {
      case '+' : r=x+y;
break;
      case '-' : r=x-y;
break;
      case '*' : r=x*y;
break;
      case '/' : r=x/y;
break;
      case '$' :
      case '^' : r=pow(x,y);
break;
   }
   push(r); //push the result into stack
  }
  i++;
 }
 re=pop(); // at the last pop the result and display.
 printf("\n %d",re);
 getch();
}

int prec(char chr)
{
 switch(chr)   // check the priority of the operators.
 {
  case '$' :
  case '^' : return(5);
  case '*' :
  case '/' : return(4);
  case '+' :
  case '-' : return(3);
  case '(' : return(2);
 }
 return(0);
}
void push(char x)
{
  top++;
  stack[top]=x;
}
char pop()
{
 char y;
 y=stack[top];
 top--;
 return(y);
}



RDBMS example for one to many relationship

Q.).
         Customer (cno,cname,city)
         Account (ano,acc_type,balance)

          Relationships between  customer and account  is one-to-many.
 
         Constraints :-primary key,
                                 Balance should be>100

SQL> create table customer2
  2  ( cno number(5)primary key,
  3    cname varchar2(30),
  4    city varchar2(40)
  5  );
Table created.

SQL> insert into customer2
  2  values('&cno','&cname','&city');
Enter value for cno: 101
Enter value for cname: mahendra
Enter value for city: pali
old   2: values('&cno','&cname','&city')
new   2: values('101','mahendra','pali')
1 row created.
SQL> select * from customer2;

  CNO   CNAME   CITY
--------   -----------  ------------------
  101 mahendra       pali
  102 babulal          pune
 103 amit              mumbai

 CNO   CNAME   CITY
--------   -----------  ------------------
 104        raju                 pune
105          akash          Ajmer

SQL> create table account
  2  ( ano number(5)primary key,
  3    acc_type varchar2(20),
  4    balance number(5) check(balance>100),
  5    cno number(5)references customer2(cno)
  6  );
Table created.

SQL> insert into account
2 values('&ano','&acc_type','&balance','&cno');
SQL> select * from account;

       ANO ACC_TYPE                          BALANCE        CNO
---------- ------------------------------ ---------- ----------
      1201 saving                              13000        101
      1202 current                             20000        102
      1203 saving                              14000        103
      1204 saving                              50000        104
      1205 current                             14000        105
      1206 saving                              25000        104
      1207 current                             19000        105


B). wirte a cursor to add interest of 3% to the balance of all account whose balance is greater than 10000.

  1  declare
  2     cursor c1 is select ano from account
  3     where balance>10000;
  4  begin
  5     for x in c1 loop
  6       update account
  7       set balance=balance+balance*3/100
  8       where ano=x.ano;
  9       commit;
 10     end loop;
 11* end;
SQL> /
PL/SQL procedure successfully completed.

SQL> select * from account;

       ANO ACC_TYPE                          BALANCE        CNO
---------- ------------------------------ ---------- ----------
      1201 saving                              13390        101
      1202 current                             20600        102
      1203 saving                              14420        103
      1204 saving                              51500        104
      1205 current                             14420        105
      1206 saving                              25750        104
      1207 current                             19570        105

7 rows selected.


a). create  or replace a PL/ SQL procedure to find total balance of all customers of pune city.
  1  create or replace procedure dis(x in varchar)
  2  is
  3      b number(20);
  4  begin
  5      select sum(a.balance) into b from customer2 c,
  6      account a where c.cno=a.cno and
  7      c.city=x;
  8        dbms_output.put_line('total balance of all customers of pune city:-'||b);
  9* end;
 10  /

Procedure created.

SQL> declare
  2
  3  begin
  4    dis('pune');
  5  end;
  6  /
total balance of all customers of pune city:-97850

PL/SQL procedure successfully completed.




अच्छे विचार करे विचार

  पहचान की नुमाईश, जरा कम करें... जहाँ भी "मैं" लिखा है, उसे "हम" करें... हमारी "इच्छाओं" से ज़्यादा "सुन...