1. Translation program:
#include
#include
#include
#include
#include
int x1,y1,x2,y2,x3,y3,mx,my;
void draw();
void tri();
void main()
{
int gd=DETECT,gm;
int c;
initgraph(&gd,&gm,"d:tcbgi ");
printf("Enter the 1st point for the triangle:");
scanf("%d%d",&x1,&y1);
printf("Enter the 2nd point for the triangle:");
scanf("%d%d",&x2,&y2);
printf("Enter the 3rd point for the triangle:");
scanf("%d%d",&x3,&y3);
cleardevice();
draw();
getch();
tri();
getch();
}
void draw()
{
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
}
void tri()
{
int x,y,a1,a2,a3,b1,b2,b3;
printf("Enter the Transaction coordinates");
scanf("%d%d",&x,&y);
cleardevice();
a1=x1+x;
b1=y1+y;
a2=x2+x;
b2=y2+y;
a3=x3+x;
b3=y3+y;
line(a1,b1,a2,b2);
line(a2,b2,a3,b3);
line(a3,b3,a1,b1);
}
getch();
closegraph();
2.
//rotation
#include
#include
#include
#include
#include
#include
float x1,y1,x2,y2,x,y,x3,y3,x4,y4,a;
int ch;
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
clrscr();
initgraph(&gdriver, &gmode, "c:tcbgi");
cout<<"enter coordinates of line1: ";
cin>>x1>>y1>>x2>>y2;
cout<<"enter coordinates for relative line: ";
cin>>x3>>y3;
cout<<"enter the angle of rotation: ";cin>>a;
cleardevice();
line(x1,y1,x2,y2);
moveto(x2,y2);
lineto(x3,y3);
moveto(x3,y3);
lineto(x1,y1);
a=a*(3.14/180);
x1=(x1*cos(a))-(y1*sin(a));
y1=(x1*sin(a))+(y1*cos(a));
x2=(x2*cos(a))-(y2*sin(a));
y2=(x2*sin(a))+(y2*cos(a));
x3=(x3*cos(a))-(y3*sin(a));
y3=(x3*sin(a))+(y3*cos(a));
cout<<"now hit a key to see rotation:";
getch();
moveto(x1,y1);
lineto(x2,y2);
moveto(x2,y2);
lineto(x3,y3);
moveto(x3,y3);
lineto(x1,y1);
getch();
closegraph();
}
3. Reflection
#include
#include
#include
#include
void main()
{
int gd=DETECT,gm;
int x1,y1,x2,y2,x3,y3;
char a;
clrscr();
initgraph(&gd,&gm,"");
printf(" enter the coordinates of triangle");
sacnf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
line(320,0,320,430);
line(0,240,640,240);
printf(" enter the axis of reflection");
scanf("%d",&a);
if(a='x'||a='X')
{
x1=x1;
x2=x2;
x3=x3;
y1=y1+240;
y2=y2+240;
y3=y3+240;
}
else
if(a='y'||a='Y')
{
y1=y1;
y2=y2;
y3=y3;
x1+=320;
x2+=320;
x3+=320;
}
printf(" triangle after reflection");
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
getch();
closegraph();
}
Solution
1. Translation program:
#include
#include
#include
#include
#include
int x1,y1,x2,y2,x3,y3,mx,my;
void draw();
void tri();
void main()
{
int gd=DETECT,gm;
int c;
initgraph(&gd,&gm,"d:tcbgi ");
printf("Enter the 1st point for the triangle:");
scanf("%d%d",&x1,&y1);
printf("Enter the 2nd point for the triangle:");
scanf("%d%d",&x2,&y2);
printf("Enter the 3rd point for the triangle:");
scanf("%d%d",&x3,&y3);
cleardevice();
draw();
getch();
tri();
getch();
}
void draw()
{
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
}
void tri()
{
int x,y,a1,a2,a3,b1,b2,b3;
printf("Enter the Transaction coordinates");
scanf("%d%d",&x,&y);
cleardevice();
a1=x1+x;
b1=y1+y;
a2=x2+x;
b2=y2+y;
a3=x3+x;
b3=y3+y;
line(a1,b1,a2,b2);
line(a2,b2,a3,b3);
line(a3,b3,a1,b1);
}
getch();
closegraph();
2.
//rotation
#include
#include
#include
#include
#include
#include
float x1,y1,x2,y2,x,y,x3,y3,x4,y4,a;
int ch;
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
clrscr();
initgraph(&gdriver, &gmode, "c:tcbgi");
cout<<"enter coordinates of line1: ";
cin>>x1>>y1>>x2>>y2;
cout<<"enter coordinates for relative line: ";
cin>>x3>>y3;
cout<<"enter the angle of rotation: ";cin>>a;
cleardevice();
line(x1,y1,x2,y2);
moveto(x2,y2);
lineto(x3,y3);
moveto(x3,y3);
lineto(x1,y1);
a=a*(3.14/180);
x1=(x1*cos(a))-(y1*sin(a));
y1=(x1*sin(a))+(y1*cos(a));
x2=(x2*cos(a))-(y2*sin(a));
y2=(x2*sin(a))+(y2*cos(a));
x3=(x3*cos(a))-(y3*sin(a));
y3=(x3*sin(a))+(y3*cos(a));
cout<<"now hit a key to see rotation:";
getch();
moveto(x1,y1);
lineto(x2,y2);
moveto(x2,y2);
lineto(x3,y3);
moveto(x3,y3);
lineto(x1,y1);
getch();
closegraph();
}
3. Reflection
#include
#include
#include
#include
void main()
{
int gd=DETECT,gm;
int x1,y1,x2,y2,x3,y3;
char a;
clrscr();
initgraph(&gd,&gm,"");
printf(" enter the coordinates of triangle");
sacnf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
line(320,0,320,430);
line(0,240,640,240);
printf(" enter the axis of reflection");
scanf("%d",&a);
if(a='x'||a='X')
{
x1=x1;
x2=x2;
x3=x3;
y1=y1+240;
y2=y2+240;
y3=y3+240;
}
else
if(a='y'||a='Y')
{
y1=y1;
y2=y2;
y3=y3;
x1+=320;
x2+=320;
x3+=320;
}
printf(" triangle after reflection");
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
getch();
closegraph();
}

1. Translation program#includestdio.h#includeconio.h#incl.pdf

  • 1.
    1. Translation program: #include #include #include #include #include intx1,y1,x2,y2,x3,y3,mx,my; void draw(); void tri(); void main() { int gd=DETECT,gm; int c; initgraph(&gd,&gm,"d:tcbgi "); printf("Enter the 1st point for the triangle:"); scanf("%d%d",&x1,&y1); printf("Enter the 2nd point for the triangle:"); scanf("%d%d",&x2,&y2); printf("Enter the 3rd point for the triangle:"); scanf("%d%d",&x3,&y3); cleardevice(); draw(); getch(); tri(); getch(); } void draw() { line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); }
  • 2.
    void tri() { int x,y,a1,a2,a3,b1,b2,b3; printf("Enterthe Transaction coordinates"); scanf("%d%d",&x,&y); cleardevice(); a1=x1+x; b1=y1+y; a2=x2+x; b2=y2+y; a3=x3+x; b3=y3+y; line(a1,b1,a2,b2); line(a2,b2,a3,b3); line(a3,b3,a1,b1); } getch(); closegraph(); 2. //rotation #include #include #include #include #include #include float x1,y1,x2,y2,x,y,x3,y3,x4,y4,a; int ch; int main(void) { int gdriver = DETECT, gmode, errorcode; clrscr(); initgraph(&gdriver, &gmode, "c:tcbgi"); cout<<"enter coordinates of line1: "; cin>>x1>>y1>>x2>>y2;
  • 3.
    cout<<"enter coordinates forrelative line: "; cin>>x3>>y3; cout<<"enter the angle of rotation: ";cin>>a; cleardevice(); line(x1,y1,x2,y2); moveto(x2,y2); lineto(x3,y3); moveto(x3,y3); lineto(x1,y1); a=a*(3.14/180); x1=(x1*cos(a))-(y1*sin(a)); y1=(x1*sin(a))+(y1*cos(a)); x2=(x2*cos(a))-(y2*sin(a)); y2=(x2*sin(a))+(y2*cos(a)); x3=(x3*cos(a))-(y3*sin(a)); y3=(x3*sin(a))+(y3*cos(a)); cout<<"now hit a key to see rotation:"; getch(); moveto(x1,y1); lineto(x2,y2); moveto(x2,y2); lineto(x3,y3); moveto(x3,y3); lineto(x1,y1); getch(); closegraph(); } 3. Reflection #include #include #include #include void main() { int gd=DETECT,gm; int x1,y1,x2,y2,x3,y3;
  • 4.
    char a; clrscr(); initgraph(&gd,&gm,""); printf(" enterthe coordinates of triangle"); sacnf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3); line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); line(320,0,320,430); line(0,240,640,240); printf(" enter the axis of reflection"); scanf("%d",&a); if(a='x'||a='X') { x1=x1; x2=x2; x3=x3; y1=y1+240; y2=y2+240; y3=y3+240; } else if(a='y'||a='Y') { y1=y1; y2=y2; y3=y3; x1+=320; x2+=320; x3+=320; } printf(" triangle after reflection"); line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); getch();
  • 5.
    closegraph(); } Solution 1. Translation program: #include #include #include #include #include intx1,y1,x2,y2,x3,y3,mx,my; void draw(); void tri(); void main() { int gd=DETECT,gm; int c; initgraph(&gd,&gm,"d:tcbgi "); printf("Enter the 1st point for the triangle:"); scanf("%d%d",&x1,&y1); printf("Enter the 2nd point for the triangle:"); scanf("%d%d",&x2,&y2); printf("Enter the 3rd point for the triangle:"); scanf("%d%d",&x3,&y3); cleardevice(); draw(); getch(); tri(); getch(); } void draw() {
  • 6.
    line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); } void tri() { int x,y,a1,a2,a3,b1,b2,b3; printf("Enterthe Transaction coordinates"); scanf("%d%d",&x,&y); cleardevice(); a1=x1+x; b1=y1+y; a2=x2+x; b2=y2+y; a3=x3+x; b3=y3+y; line(a1,b1,a2,b2); line(a2,b2,a3,b3); line(a3,b3,a1,b1); } getch(); closegraph(); 2. //rotation #include #include #include #include #include #include float x1,y1,x2,y2,x,y,x3,y3,x4,y4,a; int ch; int main(void) { int gdriver = DETECT, gmode, errorcode;
  • 7.
    clrscr(); initgraph(&gdriver, &gmode, "c:tcbgi"); cout<<"entercoordinates of line1: "; cin>>x1>>y1>>x2>>y2; cout<<"enter coordinates for relative line: "; cin>>x3>>y3; cout<<"enter the angle of rotation: ";cin>>a; cleardevice(); line(x1,y1,x2,y2); moveto(x2,y2); lineto(x3,y3); moveto(x3,y3); lineto(x1,y1); a=a*(3.14/180); x1=(x1*cos(a))-(y1*sin(a)); y1=(x1*sin(a))+(y1*cos(a)); x2=(x2*cos(a))-(y2*sin(a)); y2=(x2*sin(a))+(y2*cos(a)); x3=(x3*cos(a))-(y3*sin(a)); y3=(x3*sin(a))+(y3*cos(a)); cout<<"now hit a key to see rotation:"; getch(); moveto(x1,y1); lineto(x2,y2); moveto(x2,y2); lineto(x3,y3); moveto(x3,y3); lineto(x1,y1); getch(); closegraph(); } 3. Reflection #include #include #include #include
  • 8.
    void main() { int gd=DETECT,gm; intx1,y1,x2,y2,x3,y3; char a; clrscr(); initgraph(&gd,&gm,""); printf(" enter the coordinates of triangle"); sacnf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3); line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); line(320,0,320,430); line(0,240,640,240); printf(" enter the axis of reflection"); scanf("%d",&a); if(a='x'||a='X') { x1=x1; x2=x2; x3=x3; y1=y1+240; y2=y2+240; y3=y3+240; } else if(a='y'||a='Y') { y1=y1; y2=y2; y3=y3; x1+=320; x2+=320; x3+=320; } printf(" triangle after reflection");
  • 9.