Click here to Skip to main content
15,878,945 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
 
void reset (int h[][2])
{
    int val[9][2] = {
			{ 50, 50 },{ 75, 50 },{ 75, 75 },{ 100, 75 },
			{ 100, 50 },{ 125, 50 },{ 125, 100 },{ 87, 125 },{ 50, 100 }
		    };
    int i;
    for (i=0; i<9; i++)
    {
	h[i][0] = val[i][0]-50;
	h[i][1] = val[i][1]-50;
    }
}
void draw (int h[][2])
{
    int i;
    setlinestyle (DOTTED_LINE, 0, 1);
    line (320, 0, 320, 480);
    line (0, 240, 640, 240);
    setlinestyle (SOLID_LINE, 0, 1);
    for (i=0; i<8; i++)
	line (320+h[i][0], 240-h[i][1], 320+h[i+1][0], 240-h[i+1][1]);
    line (320+h[0][0], 240-h[0][1], 320+h[8][0], 240-h[8][1]);
}
void rotate (int h[][2], float angle)
{
    int i;
    for (i=0; i<9; i++)
    {
	int xnew, ynew;
	xnew = h[i][0] * cos (angle) - h[i][1] * sin (angle);
	ynew = h[i][0] * sin (angle) + h[i][1] * cos (angle);
	h[i][0] = xnew; h[i][1] = ynew;
    }
}
void scale (int h[][2], int sx, int sy)
{
    int i;
    for (i=0; i<9; i++)
    {
	h[i][0] *= sx;
	h[i][1] *= sy;
    }
}
void translate (int h[][2], int dx, int dy)
{
    int i;
    for (i=0; i<9; i++)
    {
	h[i][0] += dx;
	h[i][1] += dy;
    }
}
void reflect (int h[][2], int m, int c)
{
	int i;
	float angle;
	for (i=0; i<9; i++)
		h[i][1] -= c;
	angle = M_PI/2 - atan (m);
	rotate (h, angle);
	for (i=0; i<9; i++)
		h[i][0] = -h[i][0];
	angle = -angle;
	rotate (h, angle);
	for (i=0; i<9; i++)
		h[i][1] += c;
}
 
void ini()
{
	int gd=DETECT,gm;
	 void initgraph ( int *gd, int *gm, char *bgi);
}
void dini()
{
	getch();
	closegraph();
}
void main();
{ 
	int h[9][2],sx,sy,x,y,m,c,choice;
	do
	{
		clrscr();
		printf("1. Scaling about the origin.\n");
		printf("2. Scaling about an arbitrary point.\n");
		printf("3. Reflection about the line y = mx + c.\n");
		printf("4. Exit\n");
		printf("Enter the choice: ");
		scanf("%d",&choice);
		switch(choice)
		{
			case 1: printf ("Enter the x- and y-scaling factors: ");
				scanf ("%d%d", &sx, &sy);
				ini();
				reset (h);
				draw (h);getch();
				scale (h, sx, sy);
				cleardevice();
				draw (h);
				dini();
				break;
 
			case 2: printf ("Enter the x- and y-scaling factors: ");
				scanf ("%d%d", &sx, &sy);
				printf ("Enter the x- and y-coordinates of the point: ");
				scanf ("%d%d", &x, &y);
				ini();
				reset (h);
				translate (h, x, y);// Go to arbitrary point
				draw(h); getch();//Show its arbitrary position
				cleardevice();
				translate(h,-x,-y);//Take it back to origin
				draw(h);
				getch();
				cleardevice();
				scale (h, sx, sy);//Now Scale it
				draw(h);
				getch();
				translate (h, x, y);//Back to Arbitrary point
				cleardevice();
				draw (h);
				putpixel (320+x, 240-y, WHITE);
				dini();
				break;
 
			case 3: printf ("Enter the values of m and c: ");
				scanf ("%d%d", &m, &c);
				ini();
				reset (h);
				draw (h); getch();
				reflect (h, m, c);
				cleardevice();
				draw (h);
				dini();
				break;
 
			case 4: exit(0);
		}
	}while(choice!=4);
}


What I have tried:

how to resolve this error please tell me?
Posted
Updated 27-Nov-19 0:28am
Comments
Shao Voon Wong 27-Nov-19 5:27am    
Seems like Turbo C++ code. Is the compiler Turbo C++? Visual C++ may not compile this code. And you neglect to mention which line has the error.
Member 14669990 27-Nov-19 5:38am    
error in line 86
Member 14669990 27-Nov-19 5:38am    
erro in line 86

C++
void main();

Please remove that semicolon and see what happens.
 
Share this answer
 
v2
Comments
Member 14669990 27-Nov-19 5:37am    
i removed semi colimn and its nothing work. it also creates a new error
Shao Voon Wong 27-Nov-19 6:05am    
What is the new error? And which line?
Member 14669990 27-Nov-19 6:11am    
expected unqualified-id before ' ' token
in line 86
Shao Voon Wong 27-Nov-19 6:12am    
That was the old error! Just remove the ; from that line.
Member 14669990 27-Nov-19 6:17am    
in which line?
In addition to what you said in your comments:
clrscr() is a function which only seems available in turbo c++; if you are using msvc on visual studio you may have to use:
C++
using <stdlib.h>

// ...

system("CLS"); // will clear the screen and position the cursor
               // to the upper-left corner

But there are probably other issues just waiting to arise; usually it is a bad idea to copy/paste some code from one platform/compiler to another without trying to understand it. Better analyze the foreign code, understand how it works, and code it in the new platform with that information in mind.
 
Share this answer
 
Comments
Member 14669990 27-Nov-19 6:40am    
i am using dev c++

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



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