===========================================================================
CODING
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<process.h>
void main()
{
clrscr();
char a[100],b[50],c[50];
int i,j,k,l,CH,check,p,used=0,ch=0,found,point,mark;
float A,B=0,R=0,z=0;
textbackground(CYAN);
textcolor(RED);
gotoxy(65,2);
cprintf("ÖÄÄÄÄÄÄÄÄÄÄÄÄÄÄ·");
gotoxy(65,3);
cprintf("º KEYWORDS º");
gotoxy(65,4);
cprintf("ÇÄÄÄÄÄÄÄÄÄÄÄÄÄĶ");
gotoxy(65,5);
cprintf("º ADD º");
gotoxy(65,6);
cprintf("º SUM º");
gotoxy(65,7);
cprintf("º SUBTRACT º");
gotoxy(65,8);
cprintf("º MULTPLY º");
gotoxy(65,9);
cprintf("º PRODUCT º");
gotoxy(65,10);
cprintf("º DIVIDE º");
gotoxy(65,11);
cprintf("º ROOT º");
gotoxy(65,12);
cprintf("º SUBTRACT º");
gotoxy(65,13);
cprintf("º ABSOLUTE º");
gotoxy(65,14);
cprintf("º RECIPROCALº");
gotoxy(65,15);
cprintf("º POWER º");
gotoxy(65,16);
cprintf("º REMAINDER º");
gotoxy(65,17);
cprintf("º SIN º");
gotoxy(65,18);
cprintf("º COS º");
gotoxy(65,19);
cprintf("º TAN º");
gotoxy(65,20);
cprintf("º COSEC º");
gotoxy(65,21);
cprintf("º SEC º");
gotoxy(65,22);
cprintf("º COT º");
gotoxy(65,23);
cprintf("ÓÄÄÄÄÄÄÄÄÄÄÄÄÄĽ");
gotoxy(1,1);
textbackground(0);
textcolor(WHITE);
cprintf("Enetr Word Problem: ");
gets(a);
a[-1]=' ';
for(i=0,j=0,found=0;a[i-1]!='\0';i++,j++)
{
if(a[i]!=' ' && a[i]!='\0')
{
b[j]=a[i];
}
else
{
b[j]='\0';
if(found==0)
{
if(strcmpi("divide",b)==0 || strcmpi("quotient",b)==0 || strcmpi("by",b)==0 || strcmpi("divided",b)==0 || strcmpi("ratio",b)==0 || strcmpi("per",b)==0 || strcmpi("divisor",b)==0)
ch=3;
else if(strcmpi("half",b)==0)
{z=2; ch=3;}
else if(strcmpi("product",b)==0 || strcmpi("multiply",b)==0 || strcmpi("times",b)==0 || strcmpi("multiplied",b)==0 || strcmpi("multiple",b)==0 || strcmpi("twice",b)==0 || strcmpi("double",b)==0 || strcmpi("triple",b)==0)
{
ch=2;
if(strcmpi("twice",b)==0 || strcmpi("double",b)==0)
{A=2; used=1;}
else if(strcmpi("triple",b)==0)
{A=3; used=1;}
}
else if(strcmpi("square",b)==0 || strcmpi("cube",b)==0)
{
for(k=i,l=0;a[k-1]!='\0';k++,l++)
{
if(a[k]!=' ' && a[k]!='\0')
c[l]=a[k];
else
{
c[l]='\0';
if(strcmpi("root",c)==0)
{
CH=1;
break;
}
l=-1;
}
}
if(CH==1)
{
if(strcmpi("square",b)==0)
{ch=6; used=1;}
else
{z=0.3333333; ch=7;}
}
else
{
if(strcmpi("square",b)==0)
{z=2; ch=7;}
else
{z=3; ch=7;}
}
}
else if(strcmpi("root",b)==0)
{ch=6; used=1;}
else if(strcmpi("raise",b)==0 || strcmpi("raised",b)==0)
{
for(k=i,l=0;a[k-1]!='\0';k++,l++)
{
if(a[k]!=' ' && a[k]!='\0')
c[l]=a[k];
else
{
c[l]='\0';
if(strcmpi("power",c)==0)
{
CH=1;
break;
}
l=-1;
}
}
if(CH==1)
ch=7;
}
else if(strcmpi("sum",b)==0 || strcmpi("add",b)==0 || strcmpi("added",b)==0 || strcmpi("Sum",b)==0 || strcmpi("Add",b)==0 || strcmpi("total",b)==0 || strcmpi("altogether",b)==0 || strcmpi("",b)==0 || strcmpi("make",b)==0 || strcmpi("together",b)==0 || strcmpi("combine",b)==0 || strcmpi("combined",b)==0)
ch=1;
else if(strcmpi("subtract",b)==0 || strcmpi("minus",b)==0 || strcmpi("subtraction",b)==0 || strcmpi("remove",b)==0 || strcmpi("removed",b)==0 || strcmpi("gave",b)==0 || strcmpi("decrease",b)==0 || strcmpi("decreased",b)==0 || strcmpi("difference",b)==0 || strcmpi("divide",b)==0 || strcmpi("subtracted",b)==0 || strcmpi("less",b)==0 || strcmpi("took",b)==0 || strcmpi("take",b)==0 || strcmpi("left",b)==0 || strcmpi("rest",b)==0 || strcmpi("excess",b)==0 || strcmpi("extra",b)==0 || strcmpi("residue",b)==0)
{
for(k=i,l=0;a[k-1]!='\0';k++,l++)
{
if(a[k]!=' ' && a[k]!='\0')
c[l]=a[k];
else
{
c[l]='\0';
if(strcmpi("from",c)==0)
{
CH=1;
break;
}
/* else if(strcmpi("and",c)==0 || strcmpi("to",c)==0)
{
CH=2;
break;
} */
l=-1;
}
}
if(CH==1)
ch=4;
else
ch=5;
}
else if(strcmpi("reciprocal",b)==0 || strcmpi("inverse",b)==0)
{used=1; ch=8;}
else if(strcmpi("absolute",b)==0)
{used=1; ch=9;}
else if(strcmpi("sin",b)==0 || strcmpi("sine",b)==0)
{used=1; ch=11;}
else if(strcmpi("cos",b)==0 || strcmpi("cosine",b)==0)
{used=1; ch=12;}
else if(strcmpi("tan",b)==0 || strcmpi("tangent",b)==0)
{used=1; ch=13;}
else if(strcmpi("cosec",b)==0 || strcmpi("cosecant",b)==0)
{used=1; ch=14;}
else if(strcmpi("sec",b)==0 || strcmpi("secant",b)==0)
{used=1; ch=15;}
else if(strcmpi("cot",b)==0 || strcmpi("cotangent",b)==0)
{used=1; ch=16;}
else if(strcmpi("remainder",b)==0)
ch=10;
}
/*for(k=0,check=0;b[k]!='\0';k++)
{ if((b[k]<48 || b[k]>57) && (b[k]!='-' || b[k]!='.'))
{
check=1;
break;
}
}
if(check==0 && used==0)
{
for(k=0;b[k]!='\0';k++);
for(p=k-1,k=0,A=0;b[k]!='\0';k++,p--)
A=pow(10,p)*(b[k]-48)+A; */
for(k=0,check=0;b[k]!='\0';k++)
{
if((b[k]!='-' && b[k]!='.'))
if((b[k]<48 || b[k]>57))
{
check=1;
break;
}
}
if(check==0 && used==0)
{
mark=0;
for(k=0,point=0;b[k]!='\0';k++)
{
if(b[k]=='.')
{
point=k;
b[k]=b[k+1];
}
if(point!=0)
b[k]=b[k+1];
}
if(point!=0)
k--;
if(b[0]=='-')
{mark=1; p=k-2;k=1;
if(point!=0)
point--;}
else
{p=k-1;k=0;}
if(point!=0)
point=p+1-point;
for(A=0;b[k]!='\0';k++,p--)
A=pow(10,p)*(b[k]-48)+A;
if(point!=0)
A=A/pow(10,point);
if(mark==1)
A=-A;
used=1;
if(z!=0)
{B=z; used=2;}
}
else if(used==1 && check==0)
{
/*for(k=0;b[k]!='\0';k++);
for(p=k-1,k=0,B=0;b[k]!='\0';k++,p--)
B=pow(10,p)*(b[k]-48)+B; */
mark=0;
for(k=0,point=0;b[k]!='\0';k++)
{
if(b[k]=='.')
{
point=k;
b[k]=b[k+1];
}
if(point!=0)
b[k]=b[k+1];
}
if(point!=0)
k--;
if(b[0]=='-')
{mark=1; p=k-2;k=1;
if(point!=0)
point--;}
else
{p=k-1;k=0;}
if(point!=0)
point=p+1-point;
for(B=0;b[k]!='\0';k++,p--)
B=pow(10,p)*(b[k]-48)+B;
if(point!=0)
B=B/pow(10,point);
if(mark==1)
B=-B;
used=2;
}
if(ch!=0 && used==2)
break;
if(ch!=0)
found=1;
j=-1;
}
}
switch(ch)
{
case 1:
R=A+B;
break;
case 2:
R=A*B;
break;
case 3:
R=A/B;
break;
case 4:
R=B-A;
break;
case 5:
R=A-B;
break;
case 6:
R=sqrt(B);
break;
case 7:
R=pow(A,B);
break;
case 8:
R=1/B;
break;
case 9:
R=fabs(B);
break;
case 10:
R=(int)A%(int)B;
break;
case 11:
R=sin(B*M_PI/180);
break;
case 12:
R=cos(B*M_PI/180);
break;
case 13:
R=tan(B*M_PI/180);
break;
case 14:
R=1/sin(B*M_PI/180);
break;
case 15:
R=1/cos(B*M_PI/180);
break;
case 16:
R=1/tan(B*M_PI/180);
break;
default:
gotoxy(4,5);
cprintf("NOT A WORD PROBLEM!!");
getch();
exit(0);
}
gotoxy(4,5);
cprintf("ANSWER: %.3f",R);
getch();
}
CODING
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<process.h>
void main()
{
clrscr();
char a[100],b[50],c[50];
int i,j,k,l,CH,check,p,used=0,ch=0,found,point,mark;
float A,B=0,R=0,z=0;
textbackground(CYAN);
textcolor(RED);
gotoxy(65,2);
cprintf("ÖÄÄÄÄÄÄÄÄÄÄÄÄÄÄ·");
gotoxy(65,3);
cprintf("º KEYWORDS º");
gotoxy(65,4);
cprintf("ÇÄÄÄÄÄÄÄÄÄÄÄÄÄĶ");
gotoxy(65,5);
cprintf("º ADD º");
gotoxy(65,6);
cprintf("º SUM º");
gotoxy(65,7);
cprintf("º SUBTRACT º");
gotoxy(65,8);
cprintf("º MULTPLY º");
gotoxy(65,9);
cprintf("º PRODUCT º");
gotoxy(65,10);
cprintf("º DIVIDE º");
gotoxy(65,11);
cprintf("º ROOT º");
gotoxy(65,12);
cprintf("º SUBTRACT º");
gotoxy(65,13);
cprintf("º ABSOLUTE º");
gotoxy(65,14);
cprintf("º RECIPROCALº");
gotoxy(65,15);
cprintf("º POWER º");
gotoxy(65,16);
cprintf("º REMAINDER º");
gotoxy(65,17);
cprintf("º SIN º");
gotoxy(65,18);
cprintf("º COS º");
gotoxy(65,19);
cprintf("º TAN º");
gotoxy(65,20);
cprintf("º COSEC º");
gotoxy(65,21);
cprintf("º SEC º");
gotoxy(65,22);
cprintf("º COT º");
gotoxy(65,23);
cprintf("ÓÄÄÄÄÄÄÄÄÄÄÄÄÄĽ");
gotoxy(1,1);
textbackground(0);
textcolor(WHITE);
cprintf("Enetr Word Problem: ");
gets(a);
a[-1]=' ';
for(i=0,j=0,found=0;a[i-1]!='\0';i++,j++)
{
if(a[i]!=' ' && a[i]!='\0')
{
b[j]=a[i];
}
else
{
b[j]='\0';
if(found==0)
{
if(strcmpi("divide",b)==0 || strcmpi("quotient",b)==0 || strcmpi("by",b)==0 || strcmpi("divided",b)==0 || strcmpi("ratio",b)==0 || strcmpi("per",b)==0 || strcmpi("divisor",b)==0)
ch=3;
else if(strcmpi("half",b)==0)
{z=2; ch=3;}
else if(strcmpi("product",b)==0 || strcmpi("multiply",b)==0 || strcmpi("times",b)==0 || strcmpi("multiplied",b)==0 || strcmpi("multiple",b)==0 || strcmpi("twice",b)==0 || strcmpi("double",b)==0 || strcmpi("triple",b)==0)
{
ch=2;
if(strcmpi("twice",b)==0 || strcmpi("double",b)==0)
{A=2; used=1;}
else if(strcmpi("triple",b)==0)
{A=3; used=1;}
}
else if(strcmpi("square",b)==0 || strcmpi("cube",b)==0)
{
for(k=i,l=0;a[k-1]!='\0';k++,l++)
{
if(a[k]!=' ' && a[k]!='\0')
c[l]=a[k];
else
{
c[l]='\0';
if(strcmpi("root",c)==0)
{
CH=1;
break;
}
l=-1;
}
}
if(CH==1)
{
if(strcmpi("square",b)==0)
{ch=6; used=1;}
else
{z=0.3333333; ch=7;}
}
else
{
if(strcmpi("square",b)==0)
{z=2; ch=7;}
else
{z=3; ch=7;}
}
}
else if(strcmpi("root",b)==0)
{ch=6; used=1;}
else if(strcmpi("raise",b)==0 || strcmpi("raised",b)==0)
{
for(k=i,l=0;a[k-1]!='\0';k++,l++)
{
if(a[k]!=' ' && a[k]!='\0')
c[l]=a[k];
else
{
c[l]='\0';
if(strcmpi("power",c)==0)
{
CH=1;
break;
}
l=-1;
}
}
if(CH==1)
ch=7;
}
else if(strcmpi("sum",b)==0 || strcmpi("add",b)==0 || strcmpi("added",b)==0 || strcmpi("Sum",b)==0 || strcmpi("Add",b)==0 || strcmpi("total",b)==0 || strcmpi("altogether",b)==0 || strcmpi("",b)==0 || strcmpi("make",b)==0 || strcmpi("together",b)==0 || strcmpi("combine",b)==0 || strcmpi("combined",b)==0)
ch=1;
else if(strcmpi("subtract",b)==0 || strcmpi("minus",b)==0 || strcmpi("subtraction",b)==0 || strcmpi("remove",b)==0 || strcmpi("removed",b)==0 || strcmpi("gave",b)==0 || strcmpi("decrease",b)==0 || strcmpi("decreased",b)==0 || strcmpi("difference",b)==0 || strcmpi("divide",b)==0 || strcmpi("subtracted",b)==0 || strcmpi("less",b)==0 || strcmpi("took",b)==0 || strcmpi("take",b)==0 || strcmpi("left",b)==0 || strcmpi("rest",b)==0 || strcmpi("excess",b)==0 || strcmpi("extra",b)==0 || strcmpi("residue",b)==0)
{
for(k=i,l=0;a[k-1]!='\0';k++,l++)
{
if(a[k]!=' ' && a[k]!='\0')
c[l]=a[k];
else
{
c[l]='\0';
if(strcmpi("from",c)==0)
{
CH=1;
break;
}
/* else if(strcmpi("and",c)==0 || strcmpi("to",c)==0)
{
CH=2;
break;
} */
l=-1;
}
}
if(CH==1)
ch=4;
else
ch=5;
}
else if(strcmpi("reciprocal",b)==0 || strcmpi("inverse",b)==0)
{used=1; ch=8;}
else if(strcmpi("absolute",b)==0)
{used=1; ch=9;}
else if(strcmpi("sin",b)==0 || strcmpi("sine",b)==0)
{used=1; ch=11;}
else if(strcmpi("cos",b)==0 || strcmpi("cosine",b)==0)
{used=1; ch=12;}
else if(strcmpi("tan",b)==0 || strcmpi("tangent",b)==0)
{used=1; ch=13;}
else if(strcmpi("cosec",b)==0 || strcmpi("cosecant",b)==0)
{used=1; ch=14;}
else if(strcmpi("sec",b)==0 || strcmpi("secant",b)==0)
{used=1; ch=15;}
else if(strcmpi("cot",b)==0 || strcmpi("cotangent",b)==0)
{used=1; ch=16;}
else if(strcmpi("remainder",b)==0)
ch=10;
}
/*for(k=0,check=0;b[k]!='\0';k++)
{ if((b[k]<48 || b[k]>57) && (b[k]!='-' || b[k]!='.'))
{
check=1;
break;
}
}
if(check==0 && used==0)
{
for(k=0;b[k]!='\0';k++);
for(p=k-1,k=0,A=0;b[k]!='\0';k++,p--)
A=pow(10,p)*(b[k]-48)+A; */
for(k=0,check=0;b[k]!='\0';k++)
{
if((b[k]!='-' && b[k]!='.'))
if((b[k]<48 || b[k]>57))
{
check=1;
break;
}
}
if(check==0 && used==0)
{
mark=0;
for(k=0,point=0;b[k]!='\0';k++)
{
if(b[k]=='.')
{
point=k;
b[k]=b[k+1];
}
if(point!=0)
b[k]=b[k+1];
}
if(point!=0)
k--;
if(b[0]=='-')
{mark=1; p=k-2;k=1;
if(point!=0)
point--;}
else
{p=k-1;k=0;}
if(point!=0)
point=p+1-point;
for(A=0;b[k]!='\0';k++,p--)
A=pow(10,p)*(b[k]-48)+A;
if(point!=0)
A=A/pow(10,point);
if(mark==1)
A=-A;
used=1;
if(z!=0)
{B=z; used=2;}
}
else if(used==1 && check==0)
{
/*for(k=0;b[k]!='\0';k++);
for(p=k-1,k=0,B=0;b[k]!='\0';k++,p--)
B=pow(10,p)*(b[k]-48)+B; */
mark=0;
for(k=0,point=0;b[k]!='\0';k++)
{
if(b[k]=='.')
{
point=k;
b[k]=b[k+1];
}
if(point!=0)
b[k]=b[k+1];
}
if(point!=0)
k--;
if(b[0]=='-')
{mark=1; p=k-2;k=1;
if(point!=0)
point--;}
else
{p=k-1;k=0;}
if(point!=0)
point=p+1-point;
for(B=0;b[k]!='\0';k++,p--)
B=pow(10,p)*(b[k]-48)+B;
if(point!=0)
B=B/pow(10,point);
if(mark==1)
B=-B;
used=2;
}
if(ch!=0 && used==2)
break;
if(ch!=0)
found=1;
j=-1;
}
}
switch(ch)
{
case 1:
R=A+B;
break;
case 2:
R=A*B;
break;
case 3:
R=A/B;
break;
case 4:
R=B-A;
break;
case 5:
R=A-B;
break;
case 6:
R=sqrt(B);
break;
case 7:
R=pow(A,B);
break;
case 8:
R=1/B;
break;
case 9:
R=fabs(B);
break;
case 10:
R=(int)A%(int)B;
break;
case 11:
R=sin(B*M_PI/180);
break;
case 12:
R=cos(B*M_PI/180);
break;
case 13:
R=tan(B*M_PI/180);
break;
case 14:
R=1/sin(B*M_PI/180);
break;
case 15:
R=1/cos(B*M_PI/180);
break;
case 16:
R=1/tan(B*M_PI/180);
break;
default:
gotoxy(4,5);
cprintf("NOT A WORD PROBLEM!!");
getch();
exit(0);
}
gotoxy(4,5);
cprintf("ANSWER: %.3f",R);
getch();
}
===========================================================================
No comments:
Post a Comment