You are on page 1of 6

Question no 1

#include<iostream>

#include<conio.h>

#include<graphics.h>

#include<stdlib.h>

#include<stdio.h>

#include<math.h>

#include<stdlib.h>

using namespace std;

int x1 , y2 , x[20] , y[20] , n;

void draw_polygon()

int i;

for (

i=0;

i<n-1;

i++

line(x[i] , y[i] , x[i+1] , y[i+1] );

line(x[0] , y[0] , x[n-1] , y[n-1] );

void move(int x1 , int y1)

int a;
for (

a=0;

a<n;

a++

x[a]=x[a]+x1;

y[a]=y[a]+y1;

int main()

int gdriver = DETECT , gmode , errorcode;

initgraph( &gdriver , & gmode , "");

errorcode = graphresult();

cout<<"\n Enter Number of Vertices : ";

cin>>n;

cout<<"\n Enter The Co-ordinates of Vertices :: ";

for (

int i=0;

i<n;

i++

cout<<"\n"<<i+1<<"::";

cin>>x[i]>>y[i];

draw_polygon();

cout<<"\n For Translate please in x-axis , y-axis Translate : ";


cout<<"\n For x-axis::";

cin>>x1;

cout<<"\n For y-axis::";

cin>>y2;

move(x1,y2);

draw_polygon();

getch();

return(0);

cleardevice();

Question 2

#include<iostream>

#include<conio.h>

#include<graphics.h>

#include<stdlib.h>

#include<stdio.h>

#include<math.h>

#include<stdlib.h>

using namespace std;

int x1 , y2 , x[20] , y[20] , n;

float theta;

void draw_poly()

int i;
for (

i=0;

i<n-1;

i++

line(x[i] , y[i] , x[i+1] , y[i+1] );

line(x[0] , y[0] , x[n-1] , y[n-1] );

void rotate(float theta)

int a , b , i , c , d;

a= x[0];

b= y[0];

for (

i=0;

i<n;

i++

c= x[i]*cos(theta)-y[i]*sin(theta);

d= x[i]*sin(theta)+y[i]*cos(theta);

x[i] = c;

y[i] = d;

}
int main()

int gdriver = DETECT , gmode , errorcode;

initgraph( &gdriver , &gmode , "");

errorcode = graphresult();

cout<<"\n Enter Number of Sides : ";

cin>>n;

cout<<"\n Enter The Co-ordinates of Vertices :: ";

for (

int i=0;

i<n;

i++

cout<<"\n"<<i+1<<"::";

cin>>x[i]>>y[i];

draw_poly();

system("CLS");

cout<<"\n Enter The Angle :: ";

cin>>theta;

rotate(theta);

draw_poly();

getch();
cleardevice();

You might also like