Yahoo!

كتبها ماريا اسلام ، في 13 يونيو 2009 الساعة: 14:53 م

   

/*this program to difer between number ,

variable and operation*/

#include<iostream.h>

#include<string.h>

#include<conio.h>

int state=1,index1=0;

char w[50];

int index2=0,l;

char st[10];

void putt(int);

int digits()

{

if(w[index1]>=’0′ && w[index1]<=’9′)

{

st[index2++]=w[index1++];

return 1;

}

else

return 0;

}

int var()

{

if((w[index1]>=’A’ && w[index1]<=’Z') ||

(w[index1]>=’a’ && w[index1]<=’z'))

{

st[index2++]=w[index1++];

return 1;

}

else

return 0;

}

int sign()

{

if(w[index1]==’-')

{

st[index2++]=w[index1++];

return 1;

}

else

return 0;

 

 

}

int oper()

{

if(w[index1]==’+’ || w[index1]==’-’ ||

w[index1]==’*’ ||w[index1]==’/')

{

st[index2++]=w[index1++];

putt(2);

return 1;

}

else

return 0;

}

void err()

{

if(state==2)

cout<<"error in position :"<<index1<<"it is not

number or variable or not both\n";

else

if(state==4)

cout<<"error in position :"<<index1<<"it is not

operation or did not found number after

operation\n";

index1=l+1;

}

void main()

{

cin>>w;

l=strlen(w);

w[l]=”;

while(index1<=l)

{

switch(state)

{

case 1:

if(digits())

المزيد

أضف الى مفضلتك
  • del.icio.us
  • Digg
  • Facebook
  • Google
  • LinkedIn
  • Live
  • MySpace
  • StumbleUpon
  • Technorati
  • TwitThis
  • YahooMyWeb