line 5: Declaration syntax error
line 59: function containing do are not expanded inline
line 153: function containing while are not expanded inline
line 218: declaration terminated incorrectly`

Recommended Answers

All 4 Replies

Since it happened in the first 5 lines, can we see at least the first 6 lines of code?

commented: #include<iostream.h> #include<stdlib.h> #include<graphics.h> #include<math.h> using namespace std; int xmax,ymax,xmid,ymid; class Line +0

No one here is going to open up some random Word document in MS Word, where there could be random macro viruses in it.

Fortunately for you, I use LibreOffice instead, and the macros are all disabled. So, let me post the code for you as you were requested to do in the first place:

#include<iostream.h>
#include<stdlib.h>
#include<graphics.h>
#include<math.h>
using namespace std;

int xmax,ymax,xmid,ymid;
class Line
{
public:
  int x1,x2,y1,y2,ch;
  void bss(int x1,int y1,int x2,int y2)
  {
    int dx,dy,x,y,s1,s2,ex,e,i,flag=0,temp;

    dx=abs(x2-x1);
    dy=abs(y2-y1);
    x=x1;
    y=y1;
    putpixel(x+xmid,ymid-y,15);

    if(x2>x1)
      {
        s1=1;
      }
    if(x2==x1)
      {
        s1=0;
      }
    if(x2<x1)
      {
        s1=1;
      }
    if(y2>y1)
      {
        s2=1;
      }
    if(y2==y1)
      {
        s2=0;
      }
    if(y2<y1)
      {
        s2=1;
      }
    if(dy>dx)
      {
        temp=dx;
        dx=dy;
        dy = temp;
        ex = 1;
      }
    else
      ex=0;

    e=2*dy-dx;
    i=1;

    do
      {
        while(e>0)
          {
            if(ex==1)
              x=x+s1;
            else
              y=y+s2;
            e=e-2*dx;
          }
        while(e<0)
          {
            if(ex==1)
              y=y+s2;
            else
              x=x+s1;

            e=e+2*dy;
          }

        switch(ch)
          {

          case 1:
            putpixel(x+xmid,ymid-y,15);
            break;

          case 2:
            if(flag==0)
              {
                putpixel(x+xmid,ymid-y,15);
                delay(1000);
                if(i%5==0)
                  {
                    if(flag==1)
                      flag=0;
                    else
                      flag=1;
                  }
                break;

              case 3:
                if(flag==0)
                  {
                    putpixel(x+xmid,ymid-y,15);
                    delay(1000);

                    if(i%5==0)
                      {
                        if(flag==1)
                          flag=0;
                        else
                          flag=1;
                      }
                    if(i%3==0)
                      {
                        putpixel(x+xmid,ymid-y,15);
                        delay(1000);
                      }
                    break;

                  case 4:
                    if(flag==0)
                      delay(1000);
                  }
                else
                  {
                    if(i%3==0)
                      {
                        putpixel(x+xmid,ymid-y,15);
                        dekay(1000);
                      }
                  }
                break;
              case 5:
                putpixel(x+xmid,ymid-y,15);
                break;
              }
            i =i+1;
            delay(50);
          }
        while(i<=dx);
      }
  };

  int main()
  {
    int gd = DETECT,gm;
    int x1,y1,x2,y2,thick,wy,i;
    Line B;
    cout<<"Enter two end pointsof line:\n";
    cin>>x1>>y1;
    cin>>x2,y2;

    while(1)
      {
        cout<<"\nEnter the Style\n";
        cout<<"1.Simple\n";
        cout<<"2.Dash\n";
        . cout<<"3.Dash dot\n";
        cout<<"4.Dot\n";
        cout<<"5.Thick\n";
        cout<<"6.Exit\n";
        cout<<"Enter your style\n";
        cin>>B.ch;
        if(B.ch==5)
          {

            cout<<"Enter the thickness of line:";
            cin>>thick;
          }
        initgraph(&gd,&gm,NULL);
        xmax=getmaxx();
        ymax=getmaxy();
        xmid=xmax/2;
        ymid=ymax/2;

        if(B.ch<=4)
          {
            B.bss(x1,y1,x2,y2);
            delay(300);

          }
        else
          {
            B.bss(x1,y1,x2,y2);
            delay(300);

            if((y2-y1)(x2-x1)<1)
              {
                wy=(thick-1)*sqrt(pow(x2-x1),2)+pow(y2-y1),2))/(2*fabs(x2-x1));
        for(i=0;i<wy;i++)
          {
            B.bss(x1,y1-i,x2,y2-i);
            delay(300);
            B.bss(x1,y1+i,x2,y2+i);
            delay(300);
          }
      }
    else
      wx=(thick-1)*sqrt(pow(x2-x1),2)+pow(y2-y1),2))/(2*fabs(y2-y1));
for(i=0;i<wx;i++)
  {
    B.bss(x1-i,y1,x2-i,y2);
    delay(300);
    B.bss(x1+i,y1,x2+i,y2);
    delay(300);
  }
}

if(B.ch==6)
  {
    cout<<"Exiting....";
    exit(1);
  }
closegraph();
}
return 0;
}
}

This brings us to the error messages:

  • The headers are in the wrong format for modern C++, which leads me to think it was originally written for Turbo C++; however, TC++ didn't support use namespace, which is presumably why you get an error message on line 5.
  • The header <graphics.h> is specific to TC++, and shouldn't be used any more. If you are using it because you are using TC++, stop and throw that ancient piece of garbage away, and start over with a modern C++ compiler.
  • You have the function Line.bss() in the declaration of the class, meaning that it inlined by default. Inline functions, generally speaking, should only be used for very small pieces of code. For some reason, you compiler enforces this by not accepting do or while statements in inlined code.
  • there is an extra trailing close brace at the end of the program.
commented: Thanks for your effort here. It does make me wonder how they put in 200 lines of code and only now figured out it was never going to be in Turbo C. +16
commented: So to remove inline what exactly i should do?? +0

You would move the method out of the class declaration, preferably moving the declaration, implementation, and main() into separate compilation units.

line.h:

int xmax,ymax,xmid,ymid;
class Line
{
public:
  int x1,x2,y1,y2,ch;
};

line.cpp:

#include <cmath>   // in TC++ this would be '<math.h>'
#include "line.h"

void Line::bss(int x1,int y1,int x2,int y2)
{
  int dx,dy,x,y,s1,s2,ex,e,i,flag=0,temp;

  dx=abs(x2-x1);
  dy=abs(y2-y1);
  x=x1;
  y=y1;
  putpixel(x+xmid,ymid-y,15);

  if(x2>x1)
    {
      s1=1;
    }
  if(x2==x1)
    {
      s1=0;
    }
  if(x2<x1)
    {
      s1=1;
    }
  if(y2>y1)
    {
      s2=1;
    }
  if(y2==y1)
    {
      s2=0;
    }
  if(y2<y1)
    {
      s2=1;
    }
  if(dy>dx)
    {
      temp=dx;
      dx=dy;
      dy = temp;
      ex = 1;
    }
  else
    ex=0;

  e=2*dy-dx;
  i=1;

  do
    {
      while(e>0)
        {
          if(ex==1)
            x=x+s1;
          else
            y=y+s2;
          e=e-2*dx;
        }
      while(e<0)
        {
          if(ex==1)
            y=y+s2;
          else
            x=x+s1;

          e=e+2*dy;
        }

      switch(ch)
        {

        case 1:
          putpixel(x+xmid,ymid-y,15);
          break;

        case 2:
          if(flag==0)
            {
              putpixel(x+xmid,ymid-y,15);
              delay(1000);
              if(i%5==0)
                {
                  if(flag==1)
                    flag=0;
                  else
                    flag=1;
                }
              break;

            case 3:
              if(flag==0)
                {
                  putpixel(x+xmid,ymid-y,15);
                  delay(1000);

                  if(i%5==0)
                    {
                      if(flag==1)
                        flag=0;
                      else
                        flag=1;
                    }
                  if(i%3==0)
                    {
                      putpixel(x+xmid,ymid-y,15);
                      delay(1000);
                    }
                  break;

                case 4:
                  if(flag==0)
                    delay(1000);
                }
              else
                {
                  if(i%3==0)
                    {
                      putpixel(x+xmid,ymid-y,15);
                      delay(1000);
                    }
                }
              break;
            case 5:
              putpixel(x+xmid,ymid-y,15);
              break;
            }
          i =i+1;
          delay(50);
        }
      while(i<=dx);
    }
}

main.cpp:

#include <iostream>
#include <cstdlib>
#include <cmath>
#include <graphics.h>
#include "line.h"
using namespace std;



int main()
{
    int gd = DETECT,gm;
    int x1,y1,x2,y2,thick,wy,i;
    Line B;
    cout<<"Enter two end pointsof line:\n";
    cin>>x1>>y1;
    cin>>x2,y2;

    while(1)
    {
        cout<<"\nEnter the Style\n";
        cout<<"1.Simple\n";
        cout<<"2.Dash\n";
        cout<<"3.Dash dot\n";
        cout<<"4.Dot\n";
        cout<<"5.Thick\n";
        cout<<"6.Exit\n";
        cout<<"Enter your style\n";
        cin>>B.ch;
        if(B.ch==5)
        { 
            cout<<"Enter the thickness of line:";
            cin>>thick;
        }
        initgraph(&gd,&gm,NULL);
        xmax=getmaxx();
        ymax=getmaxy();
        xmid=xmax/2;
        ymid=ymax/2;

        if(B.ch<=4)
        {
            B.bss(x1,y1,x2,y2);
            delay(300);
        }
        else
        {
            B.bss(x1,y1,x2,y2);
            delay(300);

            if((y2-y1)(x2-x1)<1)
            {
                wy=(thick-1)*sqrt(pow(x2-x1),2)+pow((y2-y1),2)/(2*fabs(x2-x1));
                for(i=0;i<wy;i++)
                {
                    B.bss(x1,y1-i,x2,y2-i);
                    delay(300);
                    B.bss(x1,y1+i,x2,y2+i);
                    delay(300);
                }
                else
                    wx=(thick-1)*sqrt(pow(x2-x1),2)+pow(y2-y1),2))/(2*fabs(y2-y1));
        for(i=0;i<wx;i++)
        {
            B.bss(x1-i,y1,x2-i,y2);
            delay(300);
            B.bss(x1+i,y1,x2+i,y2);
            delay(300);
        }

        if(B.ch==6)
        {
            cout<<"Exiting....";
            exit(1);
        }
        closegraph();
        return 0;
    }
}

Note that this probably still won't work, as it uses the Turbo C++ specific library <graphics.h>, but this should at least get you on the right track.

And to repeat what I said earlier: DO NOT USE TURBO C++! It is so out of date as to be useless for present-day programming.

If you are in a class where the professor requires it, quit that class and complain to the university administration.

This Functions seems good let me try to run it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.