The Program for scaling of triangle is above as follows.
And the written program is below here:
Please refer to the above image for understanding the logic behind the program.
You can Also download the Compiled C++ file or the Windows executable from here.
Download Links:
C++ File
Executable File For Windows
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void triangle(int, int, int, int, int, int);
void scale(int, int, int, int, int, int, int, int);
void main(){
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\turboC3\\bgi"); //If this does not work try changing turboC3 to TC
int x1, x2, x3, y1, y2, y3, sx, sy, choice;
cout<<"Enter the coordinates of the triangle";
cin>>x1>>y1>>x2>>y2>>x3>>y3;
triangle(x1, y1, x2, y2, x3, y3);
getch();
clrscr();
cout<<"Enter your choice of scaling\n1. => x\n2. => y\n3. => x and y\n";
cin>>choice;
if(choice == 1)
{cout<<"Enter scaling in x ";cin>>sx; sy=1;}
else if(choice == 2)
{cout<<"Enter scaling in y ";cin>>sy; sx=1;}
else if(choice == 3)
{cout<<"Enter scaling in x and y ";cin>>sx>>sy;}
else
{cout<<"Fatal error";}
scale(x1, y1, x2, y2, x3, y3, sx, sy);
getch();
}
void scale(int x1, int y1, int x2, int y2, int x3, int y3, int sx, int sy) //don't put semicolon here
{
x1*=sx;x2*=sx;x3*=sx;y1*=sy;y2*=sy;y3*=sy;
triangle(x1, y1, x2, y2, x3, y3);
}
void triangle(int x1, int y1, int x2, int y2, int x3, int y3) //don't put semicolon here
{
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
line(x1, y1, x3, y3);
}
As mentioned earlier, please refer to the above provided image for further assistance with
the logic of the program
If you do not understand anything from the above program
Please comment
And Lastly,
Like and Share this.
No comments:
Post a Comment