Sunday, 21 October 2018

Going Towards A.I.!!! (VERSION=> 2.0)

===========================================================================
                                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,color=0,COLOR=0;
    float A,B=0,R=0,z=0;
    clrscr();
textbackground(CYAN);
for(i=0;i<=14;i++)
{
for(j=0;j<=80;j++)
{
   gotoxy(j,i);
   cprintf(" ");
}
}
textbackground(GREEN);
for(i=15;i<=25;i++)
{
for(j=0;j<=80;j++)
{
   gotoxy(j,i);
   cprintf(" ");
}
}
textbackground(CYAN);
textcolor(RED);
for(i=1;i<=14;i+=12)
{
for(j=2;j<=79;j++)
{
gotoxy(j,i);
cprintf("Í");
}
}
for(i=2;i<=12;i++)
{
gotoxy(2,i);
cprintf("º");
gotoxy(79,i);
cprintf("º");
}
gotoxy(2,1);
cprintf("É");
gotoxy(79,1);
cprintf("»");
gotoxy(2,13);
cprintf("È");
gotoxy(79,13);
cprintf("¼");
gotoxy(36,2);
textcolor(0);
cprintf("KEYWORDS");
gotoxy(36,3);
cprintf("========");
gotoxy(4,4);
textcolor(0);
cprintf("ADDITION=>");
textcolor(RED);
cprintf(" sum, add, added, Sum, Add, total, altogether, make, together");//, combine, combined, +");
gotoxy(4,5);
textcolor(0);
cprintf("SUBTRACTION=>");
textcolor(RED);
cprintf(" subtract from, subtract, minus, subtraction, remove, removed");//, gave, decrease, decreased, difference, divide, subtracted, less, took, take, left, rest, excess, extra, residue, -");
gotoxy(4,6);
textcolor(0);
cprintf("DIVISION=>");
textcolor(RED);
cprintf(" divide, quotient, by, divided, ratio, per, divisor, /");
gotoxy(4,7);
textcolor(0);
cprintf("MULTIPLICATION=>");
textcolor(RED);
cprintf(" product, multiply, times, multiplied, multiple, twice");//, double, triple, *");
gotoxy(4,8);
textcolor(0);
cprintf("TRIGNOMETRIC FUNCTIONS=>");
textcolor(RED);
cprintf(" tan, sin, cos, cosec, sec, cot");
gotoxy(4,9);
textcolor(0);
cprintf("EXTRA FUNCTIONS=>");
textcolor(RED);
cprintf(" half, twice, thrice, square, square root, cube, cube root");
gotoxy(4,10);
cprintf("reciprocal, absolute, double, triple, root, square, raised to power");
gotoxy(4,11);
cprintf("remainder");
textbackground(GREEN);
textcolor(1);
for(i=14;i<=25;i+=11)
{
for(j=2;j<=79;j++)
{
gotoxy(j,i);
cprintf("Í");
}
}
for(i=15;i<=24;i++)
{
gotoxy(2,i);
cprintf("º");
gotoxy(79,i);
cprintf("º");
}
gotoxy(2,14);
cprintf("É");
gotoxy(79,14);
cprintf("»");
gotoxy(2,25);
cprintf("È");
gotoxy(79,25);
cprintf("¼");
gotoxy(4,15);
textcolor(0);
cprintf("WORD PROBLEM:-");
gotoxy(4,16);
cprintf("============");
gotoxy(4,17);
cprintf("EXAMPLE:");
textcolor(1);
cprintf(" Mohan had");
textcolor(RED);
cprintf(" 3");
textcolor(1);
cprintf(" cows then he Bought");
textcolor(RED);
cprintf(" 8 ");
textcolor(1);
cprintf("more cows.");
gotoxy(13,18);
cprintf("How many ");
textcolor(RED);
cprintf("total ");
textcolor(1);
cprintf("cows does he have?");
gotoxy(4,20);
textcolor(0);
cprintf("ENTER YOUR WORD PROBLEM=> ");

textbackground(GREEN);

    gotoxy(30,20);
    textcolor(BLUE);
    gets(a);
    a[-1]=' ';
    textcolor(BLUE);
    gotoxy(30,20);
    for(i=0,j=0,found=0;a[i-1]!='\0';i++,j++,color=0,COLOR=0)
    {
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 || strcmpi("/",b)==0)
    {ch=3;color=1;}
    else if(strcmpi("half",b)==0)
    {z=2; ch=3;color=1;}
    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 || strcmpi("*",b)==0)
    {
    ch=2;
    color=1;
    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;color=1;}
      else
      {z=0.3333333; ch=7;color=1;}
      }
      else
      {
      if(strcmpi("square",b)==0)
      {z=2; ch=7;color=1;}
      else
      {z=3; ch=7;color=1;}
      }
    }
    else if(strcmpi("root",b)==0)
    {ch=6; used=1;color=1;}
    else if(strcmpi("raise",b)==0 || strcmpi("raised",b)==0 || strcmpi("^",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 || strcmpi("by",c)==0)
   {
   CH=1;
   break;
   }
l=-1;
}
      }
      if(strcmpi("^",b)==0)
      {ch=7;color=1;}
      else if(CH==1 && (strcmpi("raised",b)==0 || strcmpi("raise",b)==0))
      {ch=7;color=1;}
    }
    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("make",b)==0 || strcmpi("together",b)==0 || strcmpi("combine",b)==0 || strcmpi("combined",b)==0 || strcmpi("+",b)==0)
    {ch=1;color=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 || strcmpi("-",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;color=1;}
      else
      {ch=5;color=1;}
    }
    else if(strcmpi("reciprocal",b)==0 || strcmpi("inverse",b)==0)
    {used=1; ch=8;color=1;}
    else if(strcmpi("absolute",b)==0)
    {used=1; ch=9;color=1;}
    else if(strcmpi("sin",b)==0 || strcmpi("sine",b)==0)
    {used=1; ch=11;color=1;}
    else if(strcmpi("cos",b)==0 || strcmpi("cosine",b)==0)
    {used=1; ch=12;color=1;}
    else if(strcmpi("tan",b)==0 || strcmpi("tangent",b)==0)
    {used=1; ch=13;color=1;}
    else if(strcmpi("cosec",b)==0 || strcmpi("cosecant",b)==0)
    {used=1; ch=14;color=1;}
    else if(strcmpi("sec",b)==0 || strcmpi("secant",b)==0)
    {used=1; ch=15;color=1;}
    else if(strcmpi("cot",b)==0 || strcmpi("cotangent",b)==0)
    {used=1; ch=16;color=1;}
    else if(strcmpi("remainder",b)==0 || strcmpi("%",b)==0)
    {ch=10;color=1;}
    }
      /*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;
      COLOR=1;
      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;
      COLOR=1;
      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(COLOR==1 || color==1)
    {
      textcolor(RED+BLINK);
      cprintf("%s ",b);
      textcolor(BLUE);
    }
    else
    cprintf("%s ",b);
    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(42,13);
       cprintf("NOT A PROBLEM!!");
       getch();
       exit(0);
    }

    textbackground(RED);
    textcolor(YELLOW);
    textbackground(RED);
    textcolor(YELLOW);
    gotoxy(32,12);
    cprintf("ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»");
    gotoxy(32,13);
    cprintf("º ANSWER:         º");
    gotoxy(32,14);
    cprintf("º ======          º");
    gotoxy(32,15);
    cprintf("ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ");
    for(i=0;;i++)
    {
    textcolor(i);
    gotoxy(42,13);

    cprintf("%.3f",R);
    delay(50);
    if(kbhit())
    break;
    }

    getch();
}




===========================================================================

                                OUTPUT


No comments:

Post a Comment