Click here to Skip to main content
15,395,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

What I have tried:

  1  #include<iostream.h>
  2  #include<stdlib.h>
  3  #include<graphics.h>
  4  #include<math.h>
  5  using namespace std;
  6  
  7  int xmax,ymax,xmid,ymid;
  8  class Line
  9  {
 10  public:
 11  int x1,x2,y1,y2,ch;
 12  void bss(int x1,int y1,int x2,int y2)
 13  {
 14  int dx,dy,x,y,s1,s2,ex,e,i,flag=0,temp;
 15  
 16  dx=abs(x2-x1);
 17  dy=abs(y2-y1);
 18  x=x1;
 19  y=y1;
 20  putpixel(x+xmid,ymid-y,15);
 21  
 22  if(x2>x1)
 23  {
 24  s1=1;
 25  }
 26  if(x2==x1)
 27  {
 28  s1=0;
 29  }
 30  if(x2<x1)
 31  {
 32  s1=1;
 33  }
 34  if(y2>y1)
 35  {
 36  s2=1;
 37  }
 38  if(y2==y1)
 39  {
 40  s2=0;
 41  }
 42  if(y2<y1)
 43  {
 44  s2=1;
 45  }
 46  if(dy>dx)
 47  {
 48  temp=dx;
 49  dx=dy;
 50  dy = temp;
 51  ex = 1;
 52  }
 53  else
 54  ex=0;
 55  
 56  e=2*dy-dx;
 57  i=1;
 58  
 59  do
 60  {
 61  while(e>0)
 62  {
 63  if(ex==1)
 64  x=x+s1;
 65  else
 66  y=y+s2;
 67  
 68  e=e-2*dx;
 69  }
 70  while(e<0)
 71  {
 72  if(ex==1)
 73  y=y+s2;
 74  else
 75  x=x+s1;
 76  
 77  e=e+2*dy;
 78  }
 79  
 80  switch(ch)
 81  {
 82  
 83  case 1:
 84   putpixel(x+xmid,ymid-y,15);
 85   break;
 86  
 87  case 2:
 88   if(flag==0)
 89   {
 90    putpixel(x+xmid,ymid-y,15);
 91    delay(1000);
 92   if(i%5==0)
 93   {
 94    if(flag==1)
 95     flag=0;
 96    else
 97     flag=1;
 98    }
 99   break;
100  
101  case 3:
102   if(flag==0)
103   {
104   putpixel(x+xmid,ymid-y,15);
105   delay(1000);
106  
107   if(i%5==0)
108   {
109    if(flag==1)
110     flag=0;
111    else
112     flag=1;
113    }
114    if(i%3==0)
115    {
116    putpixel(x+xmid,ymid-y,15);
117    delay(1000);
118   }
119   break;
120  
121  case 4:
122   if(flag==0)
123    delay(1000);
124    }
125   else
126   {
127    if(i%3==0)
128    {
129    putpixel(x+xmid,ymid-y,15);
130    dekay(1000);
131    }
132   }
133   break;
134  case 5:
135   putpixel(x+xmid,ymid-y,15);
136   break;
137  }
138  i =i+1;
139  delay(50);
140  }
141  while(i<=dx);
142  }
143  };
144  int main()
145  {
146  int gd = DETECT,gm;
147  int x1,y1,x2,y2,thick,wy,i;
148  Line B;
149  cout<<"Enter two end pointsof line:\n";
150  cin>>x1>>y1;
151  cin>>x2,y2;
152  
153  while(1)
154  {
155  cout<<"\nEnter the Style\n";
156  cout<<"1.Simple\n";
157  cout<<"2.Dash\n";
158  cout<<"3.Dash dot\n";
159  cout<<"4.Dot\n";
160  cout<<"5.Thick\n";
161  cout<<"6.Exit\n";
162  cout<<"Enter your style\n";
163  cin>>B.ch;
164  if(B.ch==5)
165  {
166  
167  cout<<"Enter the thickness of line:";
168  cin>>thick;
169  }
170  initgraph(&gd,&gm,NULL);
171  xmax=getmaxx();
172  ymax=getmaxy();
173  xmid=xmax/2;
174  ymid=ymax/2;
175  
176  if(B.ch<=4)
177  {
178  B.bss(x1,y1,x2,y2);
179  delay(300);
180  
181  }
182  else
183  {
184  B.bss(x1,y1,x2,y2);
185  delay(300);
186  
187  if((y2-y1)(x2-x1)<1)
188  {
189   wy=(thick-1)*sqrt(pow(x2-x1),2)+pow(y2-y1),2))/(2*fabs(x2-x1));
190   for(i=0;i<wy;i++)
191    {
192     B.bss(x1,y1-i,x2,y2-i);
193     delay(300);
194     B.bss(x1,y1+i,x2,y2+i);
195     delay(300);
196    }
197   }
198   else
199    wx=(thick-1)*sqrt(pow(x2-x1),2)+pow(y2-y1),2))/(2*fabs(y2-y1));
200     for(i=0;i<wx;i++)
201    {
202     B.bss(x1-i,y1,x2-i,y2);
203     delay(300);
204     B.bss(x1+i,y1,x2+i,y2);
205     delay(300);
206    }
207   }
208  
209   if(B.ch==6)
210   {
211   cout<<"Exiting....";
212   exit(1);
213   }
214   closegraph();
215   }
216   return 0;
217  }
218  }
Posted
Updated 2-Jan-22 5:03am
v2
Comments
k5054 2-Jan-22 10:33am
   
What compiler are you using? using namespace std; is absolutely correct for any implementation that supports C++-98 or later. Unless you're stuck on a DOS box, for some reason, then you should be using a new compiler. Visual studio is available as a free download (community edition), so you should consider that. There's also options for other compilers that could be used with eclipse or code-blocs or other free IDE's for windows.
vaishnavi ganeshkar 2-Jan-22 11:48am
   
turbo c
k5054 2-Jan-22 13:07pm
   
Why? Assuming that you're using the free Turbo C++ 3.0, that goes back to 1992. There's better options available, unless you're stuck with a 1990's era computer and/or OS.
0x01AA 2-Jan-22 11:42am
   
I guess the problems are on
a.) Line 189
b.) Line 199 like @k5054 mentioned it
Especally have a look to ...pow(x2-x1),2).... The power function has two arguments double pow (double base, double exponent);

Therefore:
Wrong: wy=(thick-1)*sqrt(pow(x2-x1),2)+pow(y2-y1),2))/(2*fabs(x2-x1));
Right: wy=(thick-1)*sqrt(pow(x2-x1,2)+pow(y2-y1,2))/(2*fabs(x2-x1));

Wrong: wx=(thick-1)*sqrt(pow(x2-x1),2)+pow(y2-y1),2))/(2*fabs(y2-y1));
Right: wx=(thick-1)*sqrt(pow(x2-x1,2)+pow(y2-y1,2))/(2*fabs(y2-y1));

... and be prepared for divisions by zero because of /(2*fabs(x2-x1)
Rick York 2-Jan-22 14:44pm
   
If you are concerned with performance then you should never use the pow function to square a value. Internally it use a logarithm and exponential operation so it is very, very inefficient for this purpose. If have to you draw lots of lines it will become noticeable. Instead, use something like this template function :
template< typename T >
inline T Square( T a ) { return a * a; }
Rick York 2-Jan-22 14:46pm
   
That could make your logic look like this :
wx = ( thick - 1 ) * sqrt( Square(x2-x1) + Square(y2-y1) ) / ( 2*fabs(y2-y1) );

To add to what k5054 says, do yourself a favour and properly indent your code: not only does it make an app a lot easier to read, it makes missing curly brackets a lot more obvious.
Most good editors can reformat code to your prefered indentation style, and help you indent it as you edit.
Take your main function for example:
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;
 }
Is a lot harder to work with than this:
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;
}
   
v2
In addition to my questions about your compiler:
C++
wx=(thick-1)*sqrt(pow(x2-x1),2)+pow(y2-y1),2))/(2*fabs(y2-y1));

There are more closing brackets here ) than opening brackets (, so you're missed something here, and there aren't enough closing braces } for your class Line.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900