Friendship and Love Calculator Using Mouse

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<graphics.h>
#include<dos.h>

    union REGS i,o;
    initmouse()
    {
    i.x.ax=0;
    int86(0x33,&i,&o);
    return(o.x.ax);
    }

    void showmouseptr()
    {
     i.x.ax=1;
    int86(0x33,&i,&o);
    }

    void restrictmouseptr(int x1,int y1,int x2,int y2)
    {
    i.x.ax=7;
    i.x.cx=x1;
    i.x.dx=x2;
    int86(0x33,&i,&o);
    i.x.ax=8;
    i.x.cx=y1;
    i.x.dx=y2;
    int86(0x33,&i,&o);
    }

    void getmousepos(int *button,int *x,int *y)
    {
    i.x.ax=3;
    int86(0x33,&i,&o);
    *button=o.x.bx;
    *x=o.x.cx;
    *y=o.x.dx;
    }

    struct node
    {
    char ch;
    node *next,*pre;
    };
    struct node1
    {
    int d;
    node1 *next1,*pre1;
    };
    void strt()
    {
    for(int m=0;m<235;m+=5)
     {
        setcolor(m);
        outtextxy(m,200,"Cpptute");
        delay(100);
        cleardevice();
        setbkcolor(LIGHTCYAN);
        settextstyle(4,0,4);
        outtextxy(145,50,"FRIENDSHIP & LOVE");
        outtextxy(205,100,"CALCULATOR");
        outtextxy(190,160,"DEVELOPED BY");
          }
         for(int v=470;v>320;v-=10)
          {
          outtextxy(v,200,"Blog");
        setcolor(v);
        outtextxy(m,200,"Cpptute");
        outtextxy(v,200,"Blog");
        delay(100);
        cleardevice();
        setbkcolor(LIGHTCYAN);
        settextstyle(4,0,4);
        outtextxy(145,50,"FRIENDSHIP & LOVE");
        outtextxy(205,100,"CALCULATOR");
        outtextxy(190,160,"DEVELOPED BY");
          }
         for(int r=0;r<10;r+=3)
          {
        setcolor(r);
        settextstyle(4,0,4);
        outtextxy(145,50,"FRIENDSHIP & LOVE");
        outtextxy(205,100,"CALCULATOR");
        outtextxy(190,160,"DEVELOPED BY");
        outtextxy(m,200,"Cpptute");
        outtextxy(v,200,"Blog");
        delay(100);
          }
          int x;
      setlinestyle(DOTTED_LINE,1,1);
      for(x=210;x<430;x+=20)
        {
            line(210,240,x,240);
        delay(200);
        }
         settextstyle(7,0,1);
         outtextxy(200,400,"Special    Thanks    To");
         outtextxy(220,430,"Cpptute.blogspot.com");
         setlinestyle(DOTTED_LINE,1,1);
         for(x=210;x<435;x+=20)
        {
        line(210,460,x,460);
        delay(200);
        }
            delay(1000);
    }

void main()
    {
    int gdriver = DETECT, gmode, errorcode,gm,maxx,maxy,x,y,button,prevx,prevy;
    initgraph(&gdriver, &gmode, "../bgi");
    maxx=getmaxx();
    maxy=getmaxy();
    setviewport(1,0,maxx-1,maxy-1,1);
    restrictmouseptr(1,0,maxx-1,maxy-1);
    showmouseptr();

  strt();
        cleardevice();
            setbkcolor(LIGHTCYAN);
    int nl1,nl2,op,nc=0,j,k=0,l=0,f=0,k1=0,c,tn=0,a=0;
    char n1[30],n2[30];
    char op1[]={'l','o','v','e','s','/0'};
    char op2[]={'f','r','i','e','n','d','s','/0'};
    node *head,*tail,*temp,*temp1,*temp2,*ptr;
    head=NULL;tail=NULL;
    node1 *head1[10],*tail1[10],*tem1,*t1,*t2;
    head1[0]=NULL;tail1[0]=NULL;
    //part1
          settextstyle(4,0,2);
    outtextxy(60,100,"Enter  first name");
     line(55,147,210,147);
     outtextxy(370,100,"Enter  Second name");
     line(360,147,550,147);
          settextstyle(6,0,2);
     outtextxy(200,445,"Made By Admin");
          settextstyle(4,0,2);
    gotoxy(15,9);
    gets(n1);
    gotoxy(55,9);
    gets(n2);
    nl1=strlen(n1);
    nl2=strlen(n2);
    setlinestyle(SOLID_LINE,1,1);
    rectangle(190,252,260,285);
    rectangle(310,252,421,285);
    outtextxy(197,255,"LOVE");
    outtextxy(317,255,"FRIENDS");
       while(!kbhit())
           {
        getmousepos(&button,&x,&y);
            if((button &1)==1&&x>=190&&x<=250&&y>=250&&y<=280)
            {
             op=1;
             break;
              }
             if((button &1)==1&&x>=310&&x<=410&&y>=250&&y<=280)
            {
             op=2;
             break;
             }
       }
    if(op==1)
    {
    nc=nl1+nl2+5;
    }
    if(op==2)
    {
    nc=nl1+nl2+7;
    }
    //part2
    for(int i=1;i<=nc;i++)
  {
        node *p=new node;
                if(k<nl1)
                    {
                    p->ch=n1[k];
                k++;
                }
                else
                {
                    if(op==1)
                    {
                        if(l<5)
                        {
                        p->ch=op1[l];
                        l++;
                        if(l==5)
                        goto loop;
                        }

                    }
                    if(op==2)
                    {
                        if(f<7)
                        {
                        p->ch=op2[f];
                        f++;
                        if(f==7)
                        goto loop;
                        }
                    }
                 }

                 if((l==5||f==7)&&k1<nl2)
                 {
                  p->ch=n2[k1];
                  k1++;
                 }
       loop:
    p->next=NULL;
    p->pre=NULL;
    if(head==NULL)
    {
    head=p;
    tail=p;
    }
    else
    {
    tail->next=p;
    p->pre=tail;
    tail=p;
    }
  }
//part3
    temp1=head;
    while(temp1!=NULL)
    {    c=1;
    temp2=temp1->next;
        while(temp2!=NULL)
        {

            if(temp1->ch==temp2->ch)
            {
            ptr=temp2;
            c++;
            temp2=temp2->pre;
            temp2->next=ptr->next;
            ptr->next->pre=temp2;
            delete(ptr);
            }
        temp2=temp2->next;
        }

    node1 *q=new node1;
    q->d=c;
    q->next1=NULL;
    q->pre1=NULL;
    if(head1[0]==NULL)
    {
    head1[0]=q;
    tail1[0]=q;
    }
    else
    {
    tail1[0]->next1=q;
    q->pre1=tail1[0];
    tail1[0]=q;
    }
    tn++;
    temp1=temp1->next;
    }
    //part4
    int tn1=tn;
    while(tn1!=2)
    {
    if(tn1%2==0)
    {
     tn1=(tn1/2);
     }
     else
     {
     tn1=(tn1/2)+1;
     }
     a++;
     }


 //part5
    int z,h;
     for(int g=1;g<=a;g++)
    {    z=1;
     head1[g]=NULL;tail1[g]=NULL;
     if(tn%2==0)
     {
     tn=(tn/2);
     }
     else
     {
     tn=(tn/2)+1;
     }
      t1=head1[g-1];
      t2=tail1[g-1];

     while(z<=tn)
     {
      if(t1==t2)
      {
      h=t1->d;
      }
      else
      {
          h=t1->d+t2->d;
      }
      node1 *w=new node1;

      w->d=h;
      w->next1=NULL;
      w->pre1=NULL;
      if(head1[g]==NULL)
        {
        head1[g]=w;
        tail1[g]=w;
        }
        else
        {
        tail1[g]->next1=w;
        w->pre1=tail1[g];
        tail1[g]=w;
        }
        t1=t1->next1;
        t2=t2->pre1;
        z++;
    }
    }

       //part6
       int per=0;
   per=(head1[a]->d*10)+(tail1[a]->d);
     gotoxy(35,20);
     printf("%d %",per);
     setlinestyle(SOLID_LINE,1,1);
     for(x=260;x<320;x+=10)
    {
    line(260,320,x,320);
    delay(200);
    }
       for(int p=0;p<16;p++)
      {
    cleardevice();
    setcolor(p+34);
    settextstyle(4,0,4);
    outtextxy(200,90,"Thank You");
    outtextxy(180,150,"God bless us all");
    outtextxy(100,200,"Inspiration is the key to success");
    delay(100);
      }
      getch();
}